espressif/esp-idf-provisioning-ios

Device disconnected but not reporting by bleConnectionStatusHandler

doraemondavidlai opened this issue · 5 comments

My device was manually disconnect after calling espDevice.connect, but bleConnectionStatusHandler did not trigger connectionStatus changing to disconnected.

As shown in line 601 and 602,
image

Shouldn't these two lines being place there? .... or I'm misunderstanding the usage?

Hi @doraemondavidlai, In order to get status for BLE connection you need to use the bleDelegate property of the ESPDevice object. First, create a class that conforms to the ESPBleDelegate as shown below:
Screenshot 2022-02-23 at 7 16 10 PM

Then assign the instance of the above class to espDevice.bleDelegate property before calling connect. Make sure your BLEDelegate object remains in scope for the entire duration of provisioning in order to receive the callbacks.

@vikas-chandra-mnnit
Thanks for your reply. I do use this method to achieve what I need right now.
I mean... isn't espDevice.connectionStatus status being update to .disconnected when peripheral is disconnected? Or .disconnected is only use to initialize the variable connectionStatus?

@vikas-chandra-mnnit Thanks for your reply. I do use this method to achieve what I need right now. I mean... isn't espDevice.connectionStatus status being update to .disconnected when peripheral is disconnected? Or .disconnected is only use to initialize the variable connectionStatus?

We use the connectionStatus variable to track the status internally while the user is trying to connect with ESP device. After connection also there are certain steps involved like reading the version information of the device. If the device is disconnected during this stage the espDevice.connect completion handler will return the .disconnected state. However once espDevice.connect returns with any status, it can no longer be used to track the connection status of the ESP device.

Ok, got it.

Thank you.