This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 change device name and ibeacon

Problem

I got some problem in change device name.

I found that the function of ble.gap.setDeviceName(deviceName) is useless.

So I've searching for another function. And I found at this website.

And it works.

But the point is when I try to broadcast iBeacon (using the method of this website)

The device name became unchangeable.

I wondering if there is a solution allows me to mix them together.

Because I hope that it can not only broadcast iBeacon, but also have a device name in order to connect through an APP to change the data like uuid or other detail of iBeacon broadcasting data.


Code

#include "mbed.h"
#include "BLEDevice.h"
#include "iBeaconService.h"

BLEDevice ble;

const static char     DEVICE_NAME[]        = "TestDeviceName";

const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
                        0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61
                       };
uint16_t majorNumber = 1122;
uint16_t minorNumber = 3344;
uint16_t txPower = 0xC8;

const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05};

int main(void)
{
    
    ble.init();

    //If I add the line below device name become unchangeable
    iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower);

    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);

    ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));

    //This line is used to change device name
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));

    ble.setAdvertisingInterval(1000);
    ble.startAdvertising();

    for (;;) {
        ble.waitForEvent();
    }
}

Thanks for answering.

Parents
  • Hi David,

    By using iBeaconService you already add 30 bytes to the advertising packet. And you have no space left to add the device name in ( the maximum payload for the advertising packet is 31). If you check the return code from the accumulateAdvertisingPayload() call, you will find an error code.

    But why don't you detect your device using the UUID in the advertising packet, instead of using name ?

  • Usually, you will handle connection in your app, not in the Bluetooth Setting window. And in your app, you can filter using UUID when scanning, or you can scan without filter, but can check the advertising packet data to find the UUID of your beacon(s).

    By spec, iBeacon should not be connectable. If you want it to be connectable, you should set it as configuration mode, and you only enter configuration mode on certain condition (such as on a button press). You can refer to our nRF Smart Beacon kit.

    AFAIK, They are almost the same. BLE is the new name, BLEDevice is the old one, they keep BLEDevice to make it backward compatible.

Reply
  • Usually, you will handle connection in your app, not in the Bluetooth Setting window. And in your app, you can filter using UUID when scanning, or you can scan without filter, but can check the advertising packet data to find the UUID of your beacon(s).

    By spec, iBeacon should not be connectable. If you want it to be connectable, you should set it as configuration mode, and you only enter configuration mode on certain condition (such as on a button press). You can refer to our nRF Smart Beacon kit.

    AFAIK, They are almost the same. BLE is the new name, BLEDevice is the old one, they keep BLEDevice to make it backward compatible.

Children
No Data
Related