When using iOS and Android smart Phones and Tablets in central mode to scan for Particle devices and to then setup WiFi over BLE, often the advertised name is not shown even when set on the peripheral device as part of setup(). Is there anything that can be done to improve the reliability of the given name being advertised and available to the central device? Once paired and then disconnected the name will typically be discovered thereafter.
Not shown at all or not changing when you update your code? I believe I've run into it not updating between runs, but when I looked into it further it seemed that the phones were aggressively caching the advertising names for scanned devices. If you restart your phone you should see the updated name. I don't think I saw anything in iOS or Android APIs for forcing a refresh of that cache, so it may be difficult to reliably change your advertised name on the fly.
In my apps I instead use a small set of known strings for the advertising name (sku001,sku002, etc.) and what I display to the user in-app is a longer more descriptive string on the device they're trying to connect to and they never see the raw advertised name at all.
@jettonj
Thanks for sharing your experience. I figured that the scanning device might be the cause. I guess this also explains why scanner apps seem to show the same behaviour.
Correct. Because the device name is not in the normal advertising packet it's cached by scanning apps and other mobile apps so it can remain as the old name after changing it.
Hi Rick, could you expand on your reply?
The Particle provisioning mode BLE service does include the device name in the advertisement. Because of the very limited payload (31 bytes), it's not included in custom advertisements, unless you use appendLocalName
. However, mobile apps do cache the name because many devices don't always publish the name always because there is not enough room to do so.
I am doing this currently:
BleAdvertisingData advData;
advData.appendServiceUUID(serviceUUID);
advData.appendLocalName(deviceName);
BLE.setAdvertisingParameters(400, 0, BleAdvertisingEventType::CONNECTABLE_SCANNABLE_UNDIRECRED);
BLE.setDeviceName(deviceName);
BLE.advertise(&advData);
Belt and braces - deviceName is a c-string of 20 chars.
I assume therefore I am doing everything I can? And the rest is down to the scanning mobile app.
Pretty much. Though I'm surprised a 20 character name fits. In some cases the name maximum length is 14 characters but with only a service UUID maybe 20 fits.