You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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.

    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
    
About

Avatar for Gordon @Gordon started