Git Product home page Git Product logo

ds18b20's Introduction

ds18b20

badge

Get temperature from ds18b20 sensor connected to a Raspberry PI (GPIO w1 pin).

Usage

Install

npm install ds18b20 --save

Drivers

1-Wire drivers need to be loaded in order to create the connection between the physical sensor and the rPI. You can load them from the terminal (or from the bin/modules.sh script).

sudo modprobe wire
sudo modprobe w1-gpio
sudo modprobe w1-therm

Code

var ds18b20 = require('ds18b20');
ds18b20.sensors(function(err, ids) {
  // got sensor IDs ...
});

// ... async call
ds18b20.temperature('10-00080283a977', function(err, value) {
  console.log('Current temperature is', value);
});

// ... or sync call
console.log('Current temperature is' + ds18b20.temperatureSync('10-00080283a977'));

// default parser is the decimal one. You can use the hex one by setting an option
ds18b20.temperature('10-00080283a977', {parser: 'hex'}, function(err, value) {
  console.log('Current temperature is', value);
});

console.log('Current temperature is' + ds18b20.temperatureSync('10-00080283a977', {parser: 'hex'}));

Develop

Install dev dependencies

npm install

And check gulpfile...

License

(The MIT License)

Copyright (c) 2013 - 2015 Christophe Hamerling <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ds18b20's People

Contributors

chamerling avatar kkoehler avatar mlinc avatar sinanju avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ds18b20's Issues

Multiple 1-wire-buses

Hi,
I would like to use two 1-wire-buses. That means, that sensors are stored in the file /sys/bus/w1/devices/w1_bus_master**1**/w1_master_slaves and /sys/bus/w1/devices/w1_bus_master**2**/w1_master_slaves

I tried to change the /home/pi/.node-red/node_modules/ds18b20/lib/ds18b20.js file but it won't work. This are my first steps with node-js... Can anybody help me?

var W1_FILE = '/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves';
var W2_FILE = '/sys/bus/w1/devices/w1_bus_master2/w1_master_slaves';
var sensorsW1;
var sensorsW2;
var sensorsAll;

[...........]

// Get all connected sensor IDs as array
// @param callback(err, array)
function sensors(callback) {
  sensorsW1 =  fs.readFileSync(W1_FILE, 'utf8', function(err, data) {
    if (err) {
      return callback(err);
    }

    var parts = data.split('\n');
    parts.pop();
    return parts;
  });

  sensorsW2 =  fs.readFileSync(W2_FILE, 'utf8', function(err, data) {
    if (err) {
      return callback(err);
    }

    var parts = data.split('\n');
    parts.pop();
    return parts;
  });
return callback(null, sensorsW1);
}
module.exports.sensors = sensors;

Tanks,
Leo

try-catch too broad

The try-catch block in function temperature() covers its callback. This way the library catches all exceptions thrown in the callback, even unrelated ones from applications using the library, and causes it to fail.

return callback(new Error('Can not read temperature for sensor ' + sensor));

Example:

ds18b20.temperature(id, (error, value) => {
    throw new Error("Custom error unrelated to ds18b20");
}

Output:
ERROR: Can not read temperature for sensor XY

The try-catch block should only catch exceptions from parseData() instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.