temper-usb

0.1.0 • Public • Published

Temper

NPM version Build Status Coverage Status Dependency Status

TEMPer USB reader for NodeJS

Use connect to an interact with a temper USB compatible sensor. This project has been tested to work on a raspberry pi and should be easy to integrate into any NodeJS project. There is also a basic CLI which outputs JSONL optionally.

Usage

There is both a CLI and a library:

CLI

Get the current temp:

$ sudo temper
Found 1 devices
2017/02/27 23:52:20.793
  Device on bus 1
    S0: 32
    S1: 24.83984375
 

Get the current temp every 1s, in F, and and output as one JSON entry per line

$ sudo temper -f -p 1000 -j
Found 1 devices
[{"date":"2017-02-27T23:53:27.221Z","busNumber":1,"data":{"0":89.6,"1":76.71171875}}]

Library

import {getTemperDevices} from 'temper-usb'; // const getTemperDevices = require('temper-usb').getTemperDevices;
getTemperDevices().forEach((td) => td.getTemperature().then(console.log).catch(console.err));
// {"0": 89.6, "1": 76.71171875}

Often you want to test without have a USB pluggined in. For this, MockTemperDevice, which was used for testing has been exported.

import {mock, TemperDevice} from 'temper-usb';
const td = new mock.MockTemperDevice();
console.log(td instanceof TemperDevice); // True
td.getTemperature().then(console.log).catch(console.err); // in C
// { '0': 32.5, '1': 48 } 

Installation

Install temper as a dependency:

npm install --save temper-usb

If you want to install scripts globally, use -g. If you have install issues, checkout usb for more info on installing the correct usb libraries.

Permissions

As noted here and included in this project for reference. If you don't want to run this as sudo, copy etc/99-tempsensor.rules into /etc/udev/rules.d/. You will do something like:

sudo cp /path/to/my/project/node_modules/temper-usb/etc/99-tempsensor.rules /etc/udev/rules.d/

To test restart or reinsert the usb then you should see the following:

pi@raspberrypi:~ $ lsusb | grep "0c45:7401"
Bus 001 Device 013: ID 0c45:7401 Microdia 
pi@raspberrypi:~ $ sudo ls -l /dev/usb*
total 0
crw-rw-rw- 1 root root 180, 96 Mar  4 15:29 hiddev0

Debugging

We use debug. In node set env variable DEBUG=temper-usb:* or in a browser localStorage.debug='temper-usb:*' to see debugging output.

Notes and a Thank You

This project borrows heavily from temper-python and is a vague reimplementation in another language. They have documented many error cases in that project. It is also much more well tested and complete than this.

License

Apache-2.0 License

Package Sidebar

Install

npm i temper-usb

Weekly Downloads

1

Version

0.1.0

License

Apache-2.0

Last publish

Collaborators

  • mlucool