Bluetooth Close on Device Disconnect

Is there a special function with a callback that can be called upon device reboot / disconnection?

I would like to close any open bluetooth connections before the device reboots / disconnects.

Yes, you just call close on the bluetooth object: https://developer.electricimp.com/api/hardware/bluetooth/close

I wan’t to implicitly call bluetooth.close upon the event of disconnection. I don’t want to just call close by myself. I’m aware of the close method, that’s what I’m trying to do upon device disconnection.

It’s going to require a long explanation to why I want to do this. But the short explanation is that my bluetooth is physically forced to be turned on and I need a way to programmatically call the close method.

I’m not getting the issue I’m afraid…

You said you’d like to close any open bluetooth connections before the device reboots - so call close() on the bluetooth object before you reboot. If you want this to happen when new code is pushed to the device, you should install a server.onshutdown() handler which calls the bluetooth close.

If you want to close a single connection, then you can do that by using the close method on the btconnection object, see here https://developer.electricimp.com/api/hardware/bluetooth/onconnect

Both are APIs. You can call them any time you want programmatically.