I have a bluetooth blueNRG device on STM32 mcu firmware to which I'm programming. I want user to be able to change the name under which device is visible over bluetooth. The app sends new name to device, device stores it and upon next start when initializing bluetooth it sets it by updating the device name characteristic:
aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0,
strlen(name), (uint8_t *)name);
However, after new name was set and device (and iOS app) rebooted, iOS app continues to see it with old name:
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
let deviceName = peripheral.name // sees it as old one
}
But after app connects and disconnects from device, on the next connection attempt it sees the new name even if device was not rebooted. I made an experiment with two iPhones and got following result:
Suppose the current device name is oldName. iPhone1 connects to device and changes it's name to newName. Rebooting the device, restating iPhone1 app. Trying to connect from iPhone1 - it sees the device as oldName. iPhone2 also sees device as oldName. Connecting to device from iPhone1, disconnecting, and trying to connect again from iPhone1 - now it sees it as newName. Meanwhile iPhone2 continues to see it as oldName, even after iPhone2 app restart. So at the same time iPhone1 sees it as newName, and iPhone2 as oldName. After connect and disconnect procedure is done on iPhone2 it also starts to see it as newName.
Can someone explain me this highly mysterious behavior please? Why device name updates on each iPhone only after it connects and disconnects to device?