-
• #2
Hi,
So, just to be clear - you'd like to scan for iBeacons, and then have the Puck itself advertise the ID of any beacon that was found?
Scanning itself uses quite a lot of power (12mA compared to 0.02mA normally), but the good news is you don't have to do it for long (maybe 2 seconds).
NRF.findDevices
automatically scans for a certain length of time and aggregates all the beacons that are found - unless you're somewhere that's got 100s of beacons within range then this is the one you want.NRF.setScan
scans continuously and calls a function every time an advertising packet is received.
Let me know if I'm right about the kind of thing you want above and I'll post up some code.
-
• #3
I have 3 iBeacons(4m distance from each other) and the Puck. I want the beacon id to be advertised whenever is found. So, I want continuous scanning.
I also have a name for every beacon(kitchen, bedroom, etc..) Can I advertise that too? -
• #4
It's unlikely there will be space in the advertising packet for a name and the UUID - you could do one or the other though.
I want continuous scanning.
You said originally you wanted to scan only every 5 minutes? I'm going to do that as an example, because if you scan continuously your battery will only last 10-15 hours.
-
• #5
Okay,
Every 5 minutes then. Thanks Gordon! -
• #6
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
-
• #7
I wanted to say Mac Address of the beacon instead of UUID. Sorry for that.
So, how to check and advertise the mac address? thanks --this is my final question by the way :) -
• #8
dev.id
contains the mac address as a string, so just change:var uuid = new Uint8Array(dev.manufacturerData,2,16);
to
var uuid = dev.id .substr(0,17).split(":").map(x=>parseInt(x,16))
-
• #9
Can I get the major of the iBeacon as well?
-
• #10
Yes, but I think you could probably figure out how to do that yourself. It'll be in
dev.manufacturerData
like the UUID was. -
• #11
I would be very thankful if you could you give me the line with iBeacon major value.
Hello there,
I want my Puck to scan for beacons every 5 minutes(for example). I want to know about NRF.findDevices and NRF.setScan(what's the difference). Also I want to advertise the id of the beacon when is found. Can I scan continuously or the battery will be dead soon? Thanks in advance! (Code would be much appreciated).