Skip to content

Instantly share code, notes, and snippets.

@kenkit
Forked from ihewitt/aidex.js
Created March 12, 2025 03:04
Show Gist options
  • Save kenkit/38965fd4c3556bd571ff013208d83b25 to your computer and use it in GitHub Desktop.
Save kenkit/38965fd4c3556bd571ff013208d83b25 to your computer and use it in GitHub Desktop.
var serial = "xxxxxx"; //<-- Put serial number to pair here
var device = "";
var neopixel = require("neopixel");
var handle=0 ;
var WIFI_NAME = "xx";
var WIFI_OPTIONS = { password : "xx" };
var has_cleared=false;
var wifi = require("Wifi");
wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
if (err) {
console.log("Connection error: "+err);
return;
}
console.log("Connected!");
});
function scanForDevices() {
NRF.findDevices(function(devs) {
devs.forEach(function(dev) {
dt = dev.manufacturerData;
v = new DataView(new Uint8Array(dt,0,12).buffer);
epoch=946684800+(3*60*60); //off by 8hrs
timestamp = new Date((v.getUint32(2,true)+epoch)*1000); //Date [2-5]
age = parseInt(dt[1] /6); //Sample age [1]
console.log("SAMPLE AGE:"+dt[1]);
sens_no = dt[8]; //Sensor count
phase = dt[9]; //State?
// Running
life = 300 * (v.getUint16(6,true)); //Age of sensor
span = 14 - life / (60 * 60 * 24);
unk = dt[11]; //unknown?
glu = dt[10]/10; //gluc mmol
mg = glu*18;
if (phase == 4) { // countdown phase
time = dt[10];
console.log("Warming " + (59 - time) + " mins");
}
if (phase == 0xc) { // Stabilising
run = "stabilizing";
}
if(glu>=10){//grb
/*
if(handle!=0){
clearInterval(handle);
handle=0;
}
handle = setInterval("var l;neopixel.write(48, [0, l=!l?255:0, l?255:0]);",500);*/
}else if(glu<=3.5){
/*if(handle!=0){
clearInterval(handle);
handle=0;
}
handle = setInterval("var l;neopixel.write(48, [0, l=!l?255:0, 0]);",500);*/
}else{
neopixel.write(48, [0, 0, 0]);
}
console.log(dt);
console.log("Date: " + timestamp.toISOString() +
" Days: " + parseInt(span) +
" Gluc: " + glu +
" Age: " + age);
});
}, {timeout: 2000, //Check for a couple of seconds
filters: [{id: device}]});
}
NRF.setScan(function(d) {
//require("neopixel").write(D14, [50,0,0,0]);
if (d.id=="xx:xx:xx:xx:xx:xx public") //Is it a transmitter
{
var sens = new Uint8Array(d.manufacturerData, 0, 6);
if (1 ) // Find serial
{
device=d.id;
console.log("Device is: "+ device+" ser:"+sens);
scanForDevices();
}
}
}, { active: true } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment