Step 3: Turn advertisements into beacons

Step 3: Turn advertisements into beacons

animation
bluetooth
ble

Step 3: Turn advertisements into beacons

Inspect Figure 1 before filling the beacon API so every byte has an explicit identity or calibration purpose. Unlike the connected GATT example, receivers must interpret this advertisement without negotiating a service contract.

iBeacon payload layout with Apple company ID 0x004C, type 0x02, length 0x15, 16-byte UUID, Major, Minor, and calibrated TX Power byte.
Figure 1: iBeacon advertisement fields for namespace, location, and calibrated transmit power

Read Figure 1 from Apple’s company identifier and the iBeacon type and length bytes into the 16-byte UUID, then Major and Minor, and finally the calibrated TX Power byte. UUID identifies the deployment namespace, Major and Minor subdivide it, and TX Power supports a rough RSSI-based distance estimate. This layout connects the connected sensor build to a connectionless pattern: the phone can classify nearby beacons, but payload meaning, calibration, privacy, and authenticity must be designed in advance.

#include <BLEDevice.h>
#include <BLEBeacon.h>

#define BEACON_UUID  "FDA50693-A4E2-4FB1-AFCF-C6EB07647825"
#define BEACON_MAJOR 1     // Store/building number
#define BEACON_MINOR 101   // Specific beacon ID

void setup() {
  Serial.begin(115200);
  BLEDevice::init("iBeacon");
  BLEDevice::createServer();

  BLEBeacon beacon;
  beacon.setManufacturerId(0x4C00);  // Apple's company ID
  beacon.setProximityUUID(BLEUUID(BEACON_UUID));
  beacon.setMajor(BEACON_MAJOR);
  beacon.setMinor(BEACON_MINOR);
  beacon.setSignalPower(-59);  // Calibrated RSSI at 1 m

  BLEAdvertisementData advData;
  advData.setFlags(0x04);  // BR_EDR_NOT_SUPPORTED
  advData.setManufacturerData(beacon.getData());

  BLEAdvertising* pAdv = BLEDevice::getAdvertising();
  pAdv->setAdvertisementData(advData);
  pAdv->start();
}

void loop() { delay(1000); }

The manufacturer ID 0x4C00 marks Apple’s company ID. The UUID identifies the beacon group, major can represent a store or building, and minor can represent a specific beacon. setSignalPower(-59) stores the calibrated RSSI at 1 meter, which receivers use as the reference point for distance estimation.

Back to the chapter