• Hello, I'm building an android app and I was wondering how I can advertise my puck's data only when ibeacon devices are detected from puck.. Could you please give me some info about that and probably part of code? thanks in advance!

  • You can use NRF.findDevices to check for the beacons advertising around you can can then do things based on that: http://www.espruino.com/Reference#l_NRF_¬≠findDevices

    Eg.

    function checkPresence() {
      NRF.findDevices(function(devices) {
        var found = false;
        for (var dev in devices) {
          if (dev.name == "whatever") found = true;
        }
        if (found) start advertising
        else stop advertising;
      }, 1000); // scan for 1 second
    }
    setInterval(checkPresence, 5*60000); // check once every 5 minutes
    

    However actually checking for surrounding beacons takes a lot of power, so you don't want to do it often, or for long. The example above does 1 second every 5 minutes, which is still quite a lot. If you were doing this to save power you're probably best off not bothering and just advertising regardless.

  • Thanks for your responce, but this is

    Uncaught Error: Field or method "name" does not already exist, and can't create it on Number
     at line 5 col 14
          if (dev.name == "DiamondBeacon") found = true;
    

    and when I use the simple example no name is displayed.. I want to scan with id(Mac address).

    NRF.findDevices(print)
    
  • Ahh, try:

        devices.forEach(function(dev) {
          if (dev.name == "whatever") found = true;
        });
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Puck advertise data when ibeacons with specific uuid detected

Posted by Avatar for Pzr0 @Pzr0

Actions