Difference between setLocalName() and setDeviceName()??

I have been reading up on Bluetooth. I came across the functions setLocalName() and setDeviceName() in the currieBLE library.

The syntax is identical according to https://www.arduino.cc/en/Reference/BLEPeripheralSetDeviceName, and https://www.arduino.cc/en/Reference/BLEPeripheralSetLocalName.

Syntax for setLocalName() is...

yourBlePeripheralName.setLocalName(const char* deviceName)

and for setDeviceName() is...

yourBlePeripheralName.setLocalName(const char* localName)

It appears the example code is the exact same for both. Why do both use the setLocalName() function?

I have the very same question… any insight into this conundrum. :confused:

I note that the examples given in the documentation are exactly the same which does not help… We need an example for setDeviceName().

Anyhow, quickly looking at the BLEPeripheral.h file I get some more clues as to the differences but still I don’t fully understand the context just yet.

setLocalName(): Set the local name that the BLE Peripheral Device advertises

setDeviceName(): Set the device name for the BLE Peripheral Device. If device name is not set, a default name will be used instead. User-defined name string for this device will be truncated if more than maximum allowed string length (20 bytes).

So all I can see is that there is more commentary on setDeviceName. No mention given on what happens to setLocalName if not set or if there is a length restrictiction.

Looking at BLEPeripheral.cpp not much help either…

setLocalName(const char* localName) just sets _local_name = localName; (… no length restrictions here… but upon further searching I see there are checks elsewhere for the _local_name variable… but it uses a difference constant for length checking… _adv_data_len + strlen(_local_name) + 2 <= BLE_MAX_ADV_SIZE)

On the other hand… with setDeviceName…

BLEPeripheral::setDeviceName(const char deviceName)
{
memset(_device_name, 0, sizeof(_device_name));
if (deviceName && deviceName[0]) {
int len = strlen(deviceName);
if (len > BLE_MAX_DEVICE_NAME)
len = BLE_MAX_DEVICE_NAME;
memcpy(_device_name, deviceName, len);
}
}


UPDATE: I uploaded and ran the LED example. I used Adafruit’s Bluefruit LE scanning app on my Android phone. I see that it is the local name that is displayed on the phone. It is also limited to JUST 8 characters.