BLE handle connection disconnects

Hi,

During the BLE provisioning process, I will occasionally lose connection to the phone app,
[hal.ble] TRACE: handleConnectionStateChanged: connection lost cause 0x108
I think that's (HCI_ERR | HCI_ERR_CONN_TIMEOUT), so, does that mean the P2 timed out in waiting to receive a reply from the app, or the other way around?

0001318185 [wiring.ble] TRACE: Connected
0001318219 [system.ctrl.ble] TRACE: Connected
0001318253 [app] INFO: BLE Event detected: ble_prov_mode_connected
0001327262 [system.ctrl.ble] TRACE: Handshake done
0001327307 [app] INFO: BLE Event detected: ble_prov_mode_handshake_done
0001327409 [system.ctrl.ble] TRACE: Received a request message; type: 20, ID: 40
0001327598 [system.ctrl.ble] TRACE: Enqueued a reply message for sending; ID: 40
0001328084 [system.ctrl.ble] TRACE: Received a request message; type: 200, ID: 41
0001328551 [system.ctrl.ble] TRACE: Enqueued a reply message for sending; ID: 41
0001328733 [system.ctrl.ble] TRACE: Received a request message; type: 506, ID: 42
0001333366 [system.ctrl.ble] TRACE: Enqueued a reply message for sending; ID: 42
0001336376 [hal.ble] TRACE: handleConnectionStateChanged: connection lost cause 0x108
0001336378 [wiring.ble] TRACE: Disconnected
0001336472 [system.ctrl.ble] TRACE: Disconnected
0001336513 [app] INFO: BLE Event detected: ble_prov_mode_disconnected

On the iOS side I see an error like this,

Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly.

So I'm really not sure. It's kind of hard to track down, and I've not seen it since I recently tried to compile 5.8.0 with BLE debugging (though I wasn't actually able to through the workbench anymore, I must've done it some other way before). So there's a small chance that this device just wasn't on 5.8.0 and now that it is the problem is gone. I'll certainly be back if I see it again, but I'd like to know if anyone else has run into this or has a solution.

I believe that error occurs when the P2/Photon 2 side stops receiving supervision packets from the other side, either data packets or empty packets. It looks like it occurs 3 seconds after the last packet, which is a little suspicious because the timeout should default to 5 seconds. You could try increasing the timeout using BLE.setPPCP(). lost connection cause 0x108 = HCI_ERR_CONN_TIMEOUT

I thought that was suspicious too, but I did see another log right after that I didn't record that had a value further from a flat second.
I did just see another one today.

0000060824 [system.ctrl.ble] TRACE: Received a request message; type: 200, ID: 67
0000061278 [system.ctrl.ble] TRACE: Enqueued a reply message for sending; ID: 67
0000061743 [system.ctrl.ble] TRACE: Received a request message; type: 506, ID: 68
0000066456 [system.ctrl.ble] TRACE: Enqueued a reply message for sending; ID: 68
0000067879 [hal.ble] TRACE: handleConnectionStateChanged: connection lost cause 0x108
0000067882 [wiring.ble] TRACE: Disconnected

And in Xcode I see,

Send packet: 67, 200, 65
Recv packet: 67, 200, 16
Send packet: 68, 506, 0
didDisconnectPeripheral(<CBPeripheral: 0x3024edc70, identifier = 9DDB3901-20F6-5057-6A90-3A0DD9F151F0, name = Ori004, mtu = 23, state = disconnected>) with error (Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.})

So, yeah in this case it's pretty close to taking 5 seconds for the P2 to respond with the scan networks result so it's probably just the app closing the connection. I'll play around with setPPCP() and see if I can get it to stay connected.

Increasing it didn't seem to help, I still experience timeouts from both sides.

I had found this document being referenced when googling around for the iOS side of the issue and figured I'd give it a try. When placing my phone close to the P2, I can request wifi networks without issue 40+ times in a row, but when I put my phone back on my desk, it immediately fails. I have a router on my desk so the 2.4 GHz band is pretty crowded, but even with the router's radios off it will still disconnect if the phone is more than a few inches away from the P2. It still may be interference related? I'll try with a regular Photon 2 later and report back.

...but in the meantime, it's definitely looks like an iOS issue since it blows up the connection when i hold the phone near my router, before the P2 prints the disconnection. So I'm going to mark this as "solved" lol

1 Like