I have taken over an associate's project working with the BLE Mesh, which I found they built upon one of the Cypress examples. I believe THIS is the example project. I have constructed a larger mesh system, about 50 BLE devices, using this mesh. About every 12th message (sometimes more, sometimes less), I get one device that gets stuck in Central mode. Since the device is in Central, I cannot access it via Bluetooth as it is not advertising, basically rendering the device useless to me. The only method to get the device back up and working is by cutting the power and turning it back on.
To move forward with the diagnosis, I needed to prove to myself that I was in fact in Central mode. So, I started using a timer to test this. I have added UART lines inside of main.c which will print a line to my output for every 20 timer cycles that ble_gap_state == Central Mode. The variable "ble_gap_state" is in the original example project, which is either equivalent to BLE_CENTRAL or BLE_PERIPHERAL. As a note, I only send a UART message every 20 cycles so that I don't slow down the MESH devices that are working properly.
Using the Debug lines, I have confirmed that I stay in BLE_CENTRAL when the device is unresponsive to messages. Further, I use the cypress function "CyBle_GetState()" to determine the state at the time I get stuck, which is "CYBLE_STATE_DISCONNECTED". At first I though it was possible that my android and iOS devices were failing to disconnect, but that is apparently not the case.
Any idea on why I am getting stuck in Central? I can likely do a soft reset if the timer reaches a certain point and i'm in Central + disconnected state, but i'd rather avoid that if I can properly address the issue. Either the stack is messed up, or the Watchdog timer is failing to count properly. If the watchdog is the issue, then a soft reset won't do anything to help.
As I see it, if the watchdog timer fails, the below code won't switch me back to the Peripheral role. As I know, the ble_gap_state is BLE_CENTRAL, and the state is CYBLE_STATE_DISCONNECTED. The only line I haven't determined in the below code is the line I have put in bold. Then again, it may or not even be the watchdog timer at all!
/* If the current role is Central and the Central time has exceeded the preset time,
* then set the flag to switch role to Peripheral */
if((BLE_CENTRAL == ble_gap_state) &&
(WatchDog_CurrentCount() - centralStartedTime > CENTRAL_STATE_SPAN) &&
((CYBLE_STATE_DISCONNECTED == CyBle_GetState()) || (CYBLE_STATE_SCANNING == CyBle_GetState())))
/* Switch role flag set, swtching us from BLE_CENTRAL to BLE_PERIPHERAL*/
switch_Role = TRUE;
Any thoughts on this? Thanks in advance!