It scans every 5 minutes for 2 seconds, then sets its own manufacturer data to Espruino's ID (0x590) with the found device's UUID - otherwise it advertises normally.
function advertiseBeacon(dev) {
var uuid = new Uint8Array(dev.manufacturerData,2,16);
NRF.setAdvertising({},{
manufacturer:0x590, // espruino's manufacturer
manufacturerData:uuid
});
}
function doScan() {
NRF.findDevices(function(devs) {
var found = undefined;
devs.forEach(function(dev) {
if (dev.manufacturer==76)
found = dev;
});
if (found) advertiseBeacon(found); // advertise one we found
else NRF.setAdvertising({},{}); // don't advertise any data
}, 2000); // scan for 2 seconds
};
setInterval(doScan, 5*60000); // 5 minutes
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Here you go.
It scans every 5 minutes for 2 seconds, then sets its own manufacturer data to Espruino's ID (0x590) with the found device's UUID - otherwise it advertises normally.