• Not sure about the HID stuff - wasn't running EspruinoHub at the time.

    Have moved over to setAdvertising and got it working well. Took a bit of time to find a succinct example of noble code that showed how to get the data, but once I found it, it was trivial enough. Code below emits changes to any advertised data from my puck. Right now it assumes a single byte payload in the data - sufficient for my needs, but easily extended to do things properly.

    var noble = require('noble');
    
    noble.on('stateChange', function(state) {
        if (state === 'poweredOn') {
            // pass true so duplicate events are emitted
            noble.startScanning([],true);
        } else {
            noble.stopScanning();
        }
    });
    
    var lastData = {};
    noble.on('discover', function(peripheral) {
        if (peripheral.id !== 'f14142b40d3b') return;
        var data = peripheral.advertisement.serviceData;
        for (var i=0;i<data.length;i++) {
            var d = data[i];
            if (lastData[d.uuid] !== d.data[0]) {
                lastData[d.uuid] = d.data[0];
                console.log(d.uuid,d.data[0]);
            }
        }
    });
    
About

Avatar for knolleary @knolleary started