You are reading a single comment by @Gordon and its replies.
Click here to read the full conversation.
-
Hi @Gordon, I uploaded this code to Pixl.js (2v08)
var deviceInfo = {}; function parseDevice(device) { var d = new DataView(device.serviceData["fe95"]); var frame = d.getUint16(0, true); var offset = 5; console.log("FRAME: " + frame); if (frame&16) offset+=6; // mac address if (frame&32) offset+=1; // capabilitities if (frame&64) { // event var l = d.getUint8(offset+2); var code = d.getUint16(offset,true); if (!deviceInfo[device.id]) deviceInfo[device.id]={id:device.id}; event = deviceInfo[device.id]; switch (code) { case 0x1004: event.temperature = d.getInt16(offset+3,true)/10; break; case 0x1006: event.humidity = d.getInt16(offset+3)/10; break; case 0x100D: event.temperature = d.getInt16(offset+3,true)/10; event.humidity = d.getInt16(offset+5)/10; break; case 0x1008: event.moisture = d.getUint8(offset+3); break; case 0x1009: event.fertility = d.getUint16(offset+3,true)/10; break; // case 0x1007: break; // 3 bytes? got 84,0,0 or 68,0,0 default: event.code = code; event.raw = new Uint8Array(d.buffer, offset+3, l); break; } print(event); } }; setInterval(function () { NRF.setScan(parseDevice, { filters: [{serviceData:{"fe95":{}}}], timeout: 2000 }); }, 5000);
It always prints FRAME, and when the temperature or humidity changes it prints the event:
FRAME: 22616 { "id": "a5:c2:83:xx:xx:xx public", "code": 50578, "raw": new Uint8Array([208, 117, 0, 0, 58, 221, 132, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) } FRAME: 22616 { "id": "a5:c2:83:xx:xx:xx public", "code": 15670, "raw": new Uint8Array([121, 182, 117, 0, 0, 185, 254, 166, 227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
I have no idea how to extract the temperature and humidity :-)
Can I get some useful info from this Python code (0x80, 0x7F)?
THANK YOU
Which device are you wanting to run this on?
There's actually a Bangle.js app for this already at: https://github.com/espruino/BangleApps/blob/master/apps/miplant/app.js
So to run on another device you could just copy
var deviceInfo = {};
,parseDevice
and theNRF.setScan
command, then check indeviceInfo
after a few seconds and see if you get any data.The code posted above (using
findDevices
) isn't ideal as it doesn't catch every advertising packet. To get all the information you need you have to have it scanning for advertising packets for a while