13

iBeacon Scanning

Would it be possible to have a new action for scanning bluetooth iBeacons and returning information in variables such as mac address etc.

Also the possibility of an action to scan for a specific ibeacons mac address with variable results stating whether it was found or not.

A trigger would be good too. Maybe an 'if near ibeacon' with the ability to set the required ibeacon mac address. Also separate settings for scan times which would be set separately to the 'BT scan seconds' and the 'Display off monitoring' settings so that it could check at a more granular interval even with the screen off.

4 replies

IG

I can addendum this with code that actually puts BT Near to shame (for unpaired devices). Glad I spotted this post as it falls right under a FR I was going to ask for; Better BT Near scanning.

You can in the meantime do this yourself...

Run this code often, for example the new Ticker event.

    BLE Scan (288)

     A1: Java Function [ Return:adapter Class Or Object:BluetoothAdapter Function:getDefaultAdapter

    {BluetoothAdapter} () Param: Param: Param: Param: Param: Param: Param: ] 

     A2: Java Function [ Return: Class Or Object:adapter Function:startDiscovery

    {boolean} () Param: Param: Param: Param: Param: Param: Param: ] 

And create and Intent Received event;

    android.bluetooth.device.action.FOUND

And you'll have the following variables for found devices..

     A1: Variable Set [ Name:%signal To:%android_bluetooth_device_extra_rssi Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:Off ] 

     A2: Variable Set [ Name:%name To:%android_bluetooth_device_extra_name Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:Off ] 

     A3: Variable Set [ Name:%mac To:%android_bluetooth_device_extra_device Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:Off ] 

     A4: Variable Set [ Name:%class To:%android_bluetooth_device_extra_class Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 Structure Output:Off ] 

    

How you use this data, you choose.

Is that different from the Bluetooth Info > Scan Devices action? I think it's the same thing :)

IG

Hah, I never spotted that before. Does appear to do exactly the same thing, with the ease of just an action.

Yep! :) Can you confirm this works for iBeacons?

C

Yes, it "sorta" works for iBeacons, as it returns most important iBeacon information most of the time, and as by returning only those few variables it drains less battery.

BUT it's not reliable enough to use; it misses some iBeacon advertisements at random, and so "gone->exit" either flickers or fails. Also, it invokes some Android code that's very different on different phones (and changes significantly with versions of Android). So it may work reasonably for some people while others using the exact same code have significant problems. 

C

Yes, it's different. Bluetooth Info>Scan Devices will _not_report any device that isn't broadcasting _at_the_end of the scan. Devices that wink on during a scan, but then wink back off before the end of the scan, are not reported by Bluetooth Info>Scan Devices. 

What's needed to see these devices is a BTScan that either a] is very very short (significantly less than 10 seconds), or b] ignores callbacks of type CALLBACK_TYPE_MATCH_LOST.

C

Yes, this hack is significantly different from Bluetooth Info > Scan Devices.

This hack starts out the same. But it returns only MAC, optional name, and RSSI, which are available from _only_receiving_ (no transmitting). Bluetooth Info > Scan Devices on the other hand spends _considerable_ additional battery, CPU, and time getting alias, battery level, class, class_name, connected, encrypted, major_class, major_class_name, paired, and type for each device it lists. 

(And there are two other possible differences I suspect but don't have firm evidence for at this time: First, if _all_ the additional information can't be gathered, the beacon may not be reported at all by Bluetooth Info > Scan Devices ...but this hack would report it. Second, if Android reports the device "gone" (which it does differently in different versions and on different brands of hardware), that beacon also may not be reported at all by Bluetooth Info > Scan Devices ...but this hack would report it.)