ds18b20-raspi
Get temperature readings from a DS18B20 1-Wire sensor connected to a Raspberry Pi.
Noteworthy Features
- Includes
readSimpleC
(degC) andreadSimpleF
(degF) functions to make it simple to read temperatures if only a single 1-Wire sensor is present. No need to supply the 1-Wire deviceId as a parameter. - Both asynchronous and synchronous versions provided. Invoke the synchronous version of a given function by simply not providing a callback function.
- Built-in CLI (see documentation at the end of this page) for easy reading of temperatures from the command-line with an extensive set of options.
Install
$ npm install --save ds18b20-raspi
Usage/API
const sensor = ;
readSimpleC([decimals], [callback(error, reading)])
Get temperature (degC) of sensor (only works if there is exactly one DS18B20 1-Wire sensor present)
const tempC = sensor;console; // round temperature reading to 1 digitconst tempC = sensor;console; // async versionsensor; // round temperature reading to 1 digitsensor;
readSimpleF([decimals], [callback(error, reading)])
Get temperature (degF) of sensor (only works if there is exactly one DS18B20 1-Wire sensor present)
const tempF = sensor;console;
See other readSimpleC
examples above and change readSimpleC
to readSimpleF
.
readAllC([decimals], [callback(error, readings)])
Get readings (degC) of all temperature sensors found
const temps = sensor;console; // round temperature readings to 2 digitsconst temps = sensor;console; // async versionsensor; // round temperature readings to 2 digitssensor;
readAllF([decimals], [callback(error, readings)])
Get readings (degF) of all temperature sensors found
const temps = sensor;console;
See other readAllC
examples above and change readAllC
to readAllF
.
readC(deviceId, [decimals], [callback(error, readings)])
Get temperature reading (degC) for a specific 1-Wire device id
const deviceId = '28-051724b238ff';const temp = sensor;console; // round temperature readings to 2 digitsconst deviceId = '28-051724b238ff';const temp = sensor;console; // async versionconst deviceId = '28-051724b238ff';sensor; // round temperature readings to 2 digitsconst deviceId = '28-051724b238ff';sensor;
readF(deviceId, [decimals], [callback(error, readings)])
Get temperature reading (degF) for a specific 1-Wire device id
const deviceId = '28-051724b238ff';const temp = sensor;console;
See other readC
examples above and change readC
to readF
.
list([callback(error, deviceIds)])
List device ids of all 1-Wire sensors found
const list = sensor;console; // async versionsensor;
CLI
Install
$ npm install -g ds18b20-raspi
Usage
$ ds18b20 [deviceId] [options]
Options
--all, -a Get readings of all temperature sensors found
--list, -l List device ids of all 1-Wire sensors found
--degf, -f Get temperature in degF instead of degC
--decimals, -d Number of decimal digits to display
--help, -h Show help
--version, -v Display version information
Examples
Get temperature of sensor (only works if there is exactly one DS18B20 1-Wire sensor present)
$ ds18b20
Get temperature readings of all 1-Wire sensors found
$ ds18b20 -a
Get temperature of a specific 1-Wire device id
$ ds18b20 28-051724b238ff
Get temperature of a specific 1-Wire device id in degF with 2 decimals
$ ds18b20 28-051724b238ff -f -d 2
List device ids of all 1-Wire sensors found
$ ds18b20 --list
License
MIT © Dave Johnson (thisDaveJ)