cc_9313
cc_9313

Reputation: 269

how to detect unique ibeacon advertisements react-native on ios device?

I have IoT devices (emergency watch) which sends iBeacon advertisements when button on device is triggered and i am detecting these signals on my react-native application.

The problem i am facing is differentiating which signal belongs to which IoT device.

I am currently using kontakio react-native library. On iOS the library does not fetch the MAC address of the beacon. On the android it fetches the MAC address of the beacon devices.

The idea is to render these on list and when user selects one it will be stored in the phones memory and only look at the emergency call from that particular mac address.

Here is the code logic so far:

    if (isAndroid) {
  DeviceEventEmitter.addListener(
    'beaconsDidUpdate',
    async ({beacons, region}) => {
      const pairedBeacon = await getDataFromStorage();
      beacons.map(b => {
        if (
          b.proximity == 'IMMEDIATE' ||
          b.proximity == 'NEAR' 
        ) {
          setList(beacons);
        }
        if (b.address == pairedBeacon) {
          emergencyCall();
        }
      });
    },
  );

} else {
  kontaktEmitter.addListener(
    'didRangeBeacons',
    async ({beacons, region}) => {
      beacons.map(b => {
        if (
          b.proximity == 'immediate' ||
          b.proximity == 'near'
        ) {
          setList(beacons);
        }
      });
    },
  );

Any idea on how i can solve this on the iOS side? Help is greatly appreciated.

Upvotes: 1

Views: 1154

Answers (1)

davidgyoung
davidgyoung

Reputation: 64995

The best solution is to configure the IoT device to send out a unique beacon identifier for each device, so that you can rely on the beacon identifier rather than the MAC address. This is true regardless of whether you use Eddystone or iBeacon advertisements because:

  1. iOS provides no access to identifiers for iBeacon advertisements besides the beacon UUID/major/minor. It does not provide access to the MAC.
  2. iOS provides no access to the MAC for Eddystone advertisements -- it only gives access to the beacon namespace and instance ID, plus a "peripheral id" which is a 32-bit UUID mapped internally by iOS to the Bluetooth MAC address. There is no way to determine the actual MAC from the peripheral id.

The above restrictions are true regardless of whether you are using React Native or the library from Kontakt.io. It is an operating system restriction.

If you cannot change the beacon identifiers on your IoT device for some reason, then you might be able to establish a bluetooth connection to the device and query it for its MAC address or other unique identifier. The Eddystone advertisement will allow you to get access to the "peripheral id" needed to establish the connection to do this. However, for this to work, the IoT device must support connections (beacons are typically not connectable, but may support connections in some modes) and must expose access to the MAC or other unique identifier in a readable characteristic. It is conceivable that the IoT hardware supports this, but it is far from certain. You need to check the hardware documentation to see what you can do, or you need to control the IoT device firmware to make it do what you need.

Upvotes: 3

Related Questions