You are reading a single comment by @ChristianW and its replies. Click here to read the full conversation.
  • OK. Another update.
    Some more investigation and some coding later I have a working solution now:

    const ttl = 30;
    var idlog = {};
    
    function i2h(i) {
      return ('0'+i.toString(16)).slice(-2);
    }
    
    function a2h(a, i, l) {
      var res = '';
      for(var j=i; j<i+l; j++) {
        res += i2h(a[j]);
      }
      return res;
    }
    
    function dec32(a, i) {
      var res = Uint32Array(1);
      res[0] = (a[i+3] << 24) | (a[i+2] << 16) | (a[i+1] << 8) | a[i];
      return res[0];
    }
    
    function decodeData(device) {
      var d = device.manufacturerData;
      var id = a2h(d, 0, 6);
      var data = {
        battery: d[14],
        flat: d[15],
        temp: dec32(d, 10) / 100,
        pressure: dec32(d, 6) / 100000
      };
    
      var t = getTime();
      if( idlog[id] == undefined || idlog[id].last + ttl < t) {
        idlog[id] = {
          last: t,
          data: data
        };
        console.log(id, data);
      }
    }
    
    function onInit() {
      NRF.setScan(function(device){
        decodeData(device);
      }, {
        filters:[{
          services: ['fbb0']
        }]
      });
    }
    

    This is the output from a few sensors (*ba52 sits on a "real" tire, the others are just blown into to wake them up):

    82eaca30bc95 { "battery": 85, "flat": 0, "temp": 23.11, "pressure": 0.07926 }
    82eaca30bc95 { "battery": 85, "flat": 1, "temp": 23.55, "pressure": 0 }
    80eaca10ba52 { "battery": 85, "flat": 0, "temp": 18.67, "pressure": 8.36479 }
    80eaca10ba52 { "battery": 85, "flat": 0, "temp": 18.67, "pressure": 8.36479 }
    80eaca10ba52 { "battery": 85, "flat": 0, "temp": 18.67, "pressure": 8.36479 }
    82eaca30bc95 { "battery": 85, "flat": 0, "temp": 23.7, "pressure": 0.07018 }
    81eaca207bdd { "battery": 75, "flat": 0, "temp": 23.73, "pressure": 0.053 }
    80eaca10ba52 { "battery": 85, "flat": 0, "temp": 18.67, "pressure": 8.36479 }
    82eaca30bc95 { "battery": 85, "flat": 1, "temp": 24.85, "pressure": 0 }
    81eaca207bdd { "battery": 75, "flat": 1, "temp": 24.15, "pressure": 0 }
    

    Now everything needs to be wrapped up, put into a working solution including low pressure / battery indication (sound, LED), missing signal detection, pairing etc...

About

Avatar for ChristianW @ChristianW started