Created
March 5, 2019 14:11
-
-
Save kkm/6c8cfdd619ec5c610d84d579d4a9fb11 to your computer and use it in GitHub Desktop.
Raspberry GrovePi+ with Co2 in nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const struct = require('python-struct'); | |
var serialport = require('serialport'); | |
var SerialPort = serialport; | |
var port = new SerialPort('/dev/ttyAMA0', { | |
baudRate: 9600 | |
}); | |
port.on('open', function () { | |
console.log('Port geöffnet /dev/ttyAMA0 @ 9600 bds'); | |
}); | |
setInterval(function () { | |
port.write(hex()); | |
}, 1000); | |
port.on('data', function (byte) { | |
var high_level = byte[2]; | |
var low_level = byte[3]; | |
var temp = byte[4] - 40; //falsch??? ewig 27C??? | |
var conc = high_level * 256 + low_level; | |
if (!isNaN(temp)) { | |
console.log("Temp :", temp); | |
console.log("Co2 :", conc); | |
} | |
}); | |
//https://stackoverflow.com/questions/37545844/send-byte-0xff-with-node-js-through-serialport | |
//Python: "\xff\x01\x86\x00\x00\x00\x00\x00\x79"; | |
function hex() { | |
var arr = []; | |
arr.push(255); | |
arr.push(1); | |
arr.push(134); | |
arr.push(0); | |
arr.push(0); | |
arr.push(0); | |
arr.push(0); | |
arr.push(0); | |
arr.push(121); | |
return new Buffer(arr); | |
} | |
function pack(bytes) { | |
var chars = []; | |
for (var i = 0, n = bytes.length; i < n;) { | |
chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); | |
} | |
return String.fromCharCode.apply(null, chars); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zeile 20: vielleicht ist Taupunkt-Temperatur gemeint, also nicht Lufttemperatur, sondern Temperatur, wo es Wasser in der Luft hat? Oder so etwas? Muss die Spec lesen, gibst du mir Link?