heimcontrol.js icon indicating copy to clipboard operation
heimcontrol.js copied to clipboard

OneWire sensors

Open maverik23 opened this issue 10 years ago • 2 comments

someone connect a sensor OneWire

maverik23 avatar Jun 01 '14 02:06 maverik23

Say please... I can't give you the exact answer because it requires time and you need to know how to handle the sensors output result. ...but, please find below an example implementation for a node.js 1-wire sensor. A ds18b20 temperature sensor to be exact.

function readTemp(callback){ fs.readFile('/sys/bus/w1/devices/28-00000400a88a/w1_slave', function(err, buffer) { if (err){ console.error(err); process.exit(1); }

  // Read data from file (using fast node ASCII encoding).
  var data = buffer.toString('ascii').split(" "); // Split by space

  // Extract temperature from string and divide by 1000 to give celsius
  var temp  = parseFloat(data[data.length-1].split("=")[1])/1000.0;

  // Round to one decimal place
  temp = Math.round(temp * 10) / 10;

  // Add date/time to temperature
var data = {
        temperature_record:[{
        unix_time: Date.now(),
        celsius: temp
        }]};

  // Execute call back with data
  callback(data);

}); };

Hope this helps you on your way. All you need to do is modify the code above and write the socket.io adapters and views. If you're lucky you might find your 1-wire sensors already implemented through the npm. ...also you must run 'sudo mod-probe w1-gpio' and 'sudo mod-probe w1-therm' to enable 1-wire drivers. Sorry I couldn't be of more help.

Opulence avatar Jun 06 '14 15:06 Opulence

Respect for @Opulence ! Because how maverik23 asks his question is just plain rude, i wouldn't have answered him :) !

NicoJuicy avatar Dec 14 '14 20:12 NicoJuicy