npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ds18b20-raspi

v0.3.6

Published

Get temperature readings from a DS18B20 1-Wire sensor connected to a Raspberry Pi

Downloads

335

Readme

ds18b20-raspi

Get temperature readings from a DS18B20 1-Wire sensor connected to a Raspberry Pi.

Noteworthy Features

  • Includes readSimpleC (degC) and readSimpleF (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 = require('ds18b20-raspi');

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.readSimpleC();
console.log(`${tempC} degC`);

// round temperature reading to 1 digit
const tempC = sensor.readSimpleC(1);
console.log(`${tempC} degC`);


// async version
sensor.readSimpleC((err, temp) => {
	if (err) {
		console.log(err);
	} else {
	console.log(`${temp} degC`);
	}
});

// round temperature reading to 1 digit
sensor.readSimpleC(1, (err, temp) => {
	if (err) {
		console.log(err);
	} else {
	console.log(`${temp} degC`);
	}
});

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.readSimpleF();
console.log(`${tempF} degF`);

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.readAllC();
console.log(temps);

// round temperature readings to 2 digits
const temps = sensor.readAllC(2);
console.log(temps);

// async version
sensor.readAllC((err, temps) => {
	if (err) {
		console.log(err);
	} else {
		console.log(temps);
	}
});

// round temperature readings to 2 digits
sensor.readAllC(2, (err, temps) => {
	if (err) {
		console.log(err);
	} else {
		console.log(temps);
	}
});

readAllF([decimals], [callback(error, readings)])

Get readings (degF) of all temperature sensors found

const temps = sensor.readAllF();
console.log(temps);

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.readC(deviceId);
console.log(temp);

// round temperature readings to 2 digits
const deviceId = '28-051724b238ff';
const temp = sensor.readC(deviceId, 2);
console.log(temp);


// async version
const deviceId = '28-051724b238ff';
sensor.readC(deviceId, (err, temp) => {
	if (err) {
		console.log(err);
	} else {
		console.log(temp);
	}
});

// round temperature readings to 2 digits
const deviceId = '28-051724b238ff';
sensor.readC(deviceId, 2, (err, temp) => {
	if (err) {
		console.log(err);
	} else {
		console.log(temp);
	}
});

readF(deviceId, [decimals], [callback(error, readings)])

Get temperature reading (degF) for a specific 1-Wire device id

const deviceId = '28-051724b238ff';
const temp = sensor.readF(deviceId);
console.log(temp);

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.list();
console.log(list);

// async version
sensor.list((err, deviceIds) => {
	if (err) {
		console.log(err);
	} else {
		console.log(deviceIds);
	}
});

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)