0

I'm using Xamarin.iOS to wrote a BLE scanner. I'm interrested in getting the GUID of the device the 2 word associated with it and finally the signal strength to compute the distance between the phone and the BLE beacon. The beacons are using the iBeacon protocol.

Here is the pseudocode I have so far:

if (scanner == null)
{
    scanner = new CBCentralManager();
}

if (scanner != null)
{
    // FIXME Should I pass null to the first parameter of ScanForPeripherals?
    scanner.DiscoveredPeripheral += Scanner_DiscoveredPeripheral;
    scanner.ScanForPeripherals(null, new PeripheralScanningOptions { AllowDuplicatesKey = true });
}

private void Scanner_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
{
    lock (this.visibleBeacons)
    {
        // FIXME : How do I get the 2 word values and the signal strength?
        BeaconInfo discoveredPeripheral = new BeaconInfo(e.Peripheral.Identifier.ToString(), word1, word2, signalStrength);
        ...
    }
}

We never open a session with a beacon to receive data. We only rely on the advertising characteristics (send every 250ms) for our business needs. The 2 16-bit fields are used to told what we need to do when walking near a beacon.

The beacon is programmed with the manufacturer software.

1 Answers1

0

Unfortunately you cannot use Apple's CBCentralManager framework to scan for iBeacon. Apple actively blocks that API from detecting any iBeacon packet. See my blog post about that here.

As an alternative you need to use the Apple CoreLocation APIs. I am not a Xamarin expert, but you might want to take a look at this code sample to see how this is done.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • as a quick addendum, it seems that only the received signal strength is avilable? I need the sent signal strength as well... –  Mar 20 '23 at 13:34
  • The iBeacon packet contains a one byte field called "measured power" or "tx power" which tells you the strength of the transmitter. It represents the expected received signal strength at one meter on a reference iPhone. Unfortunately, iOS blocks reading this field directly from any API (although Android and other platforms do not). Apple provides a derived `accuracy` field on `CLBeacon` that tells you the calculated distance estimate based on rssi and the measured power field... but you cannot easily calculate the original measured power from this. – davidgyoung Mar 20 '23 at 14:46