Skip to content

Instantly share code, notes, and snippets.

@industrialinternet
Last active August 29, 2015 14:02
Show Gist options
  • Save industrialinternet/2405128f8bc488e0e04f to your computer and use it in GitHub Desktop.
Save industrialinternet/2405128f8bc488e0e04f to your computer and use it in GitHub Desktop.
Node-red EnOcean in Node
// v0.1 added else for testing
// expects binary lines like 55000A0701EBA500005B080088E4C20001FFFFFFFF4F0034
if (msg.payload.length > 20) {
var m = msg.payload;
console.log("ping",m.length,m.toString('hex'));
if (m.charCodeAt(0) == 85) {
var l = m.charCodeAt(2) + m.charCodeAt(1)*256;
console.log("Len =",l);
var type = m.charCodeAt(4);
console.log("Type=",type);
var tel = m.charCodeAt(6); // would be better as hex
console.log("Tel =",tel);
var rssi = m.charCodeAt(l+11);
var i = m.substr(l+1,4);
var id = "";
for (a = 0; a < i.length; a++) {
id += i.charCodeAt(a).toString(16);
}
console.log("ID =",id);
if (tel == "165") { // It's a temp sensor (0xA5)
var t = m.charCodeAt(9);
msg.payload = parseInt(400 - (t*400/256))/10;
}
else { // It's a switch (only other option for now)
msg.payload = m.charCodeAt(7);
}
msg.type = type;
msg.tel = tel;
msg.topic = id;
console.log(msg);
return msg
}
} else {
msg.payload = "telegram not reconised";
msg.topic = "enon debug";
return msg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment