Decoding iBeacon Advertising Using Javascript

iBeacon advertising consists of a UUID, major, minor and measured power. To decode the advertising using Javascript:

function decodeIBeacon(packet) {
  var uuid = packet.substring(4, 40);
  var major = parseInt(packet.substring(40, 44), 16);
  var minor = parseInt(packet.substring(44, 48), 16);
  var power = parseInt(packet.substring(48, 50), 16) - 256;

  var beacon = {
    uuid: uuid,
    major: major,
    minor: minor,
    power: power
  };

  return beacon;
}

This function takes a hexadecimal string representation of an iBeacon advertisement packet as input and decodes it into an object that contains the UUID, major and minor values and the measured power (measured in dBm) of the beacon.

To use this function, you need to extract the iBeacon advertisement packet from the Bluetooth Low Energy advertisement data received by the BLE scanning device. The iBeacon advertisement packet typically starts with a pattern similar to the following: 02 01 06 1a ff 4c 00 02 15. You can extract the iBeacon part by searching for these bytes in the advertisement data and then take the next 20 bytes as the packet.

View iBeacons

Advertise Eddystone Using node.js

We recently came across node-eddystone-beacon that advertises Eddystone using node.js (Javascript). It works across MacOS, Linux (including Raspberry Pi) and Windows but obviously requires the device to have a Bluetooth adapter.

The open source code advertises Eddystone-URL, Eddystone-UID and Eddystone-TLM. Examples are provided.

Our previous post mentioned node-beacon-scanner that provides for node.js Bluetooth scanning.

Cordova Bluetooth LE Plugin Updated

Cordova, previously called PhoneGap, is a mobile cross platform development tool that uses web pages and Javascript.

Don Coleman of Chariot Solutions maintains the open source cordova-plugin-ble-central custom plugin (blue area in above diagram) that provides a Bluetooth API for scanning, connecting to service characteristics, reading and writing values and characteristic change notification. Examples are provided.

The recent updates provide support for new permissions and API changes in Android 10+. It’s great to see the plugin updated because the problem with many tools and libraries is that they rarely keep up to date with changes in the underlying iOS and Android APIs.