Using CySmart API how can I detect the loss of a connection (c# application)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi

I am developing an application using a low power BLE device based on the CyBLE 214009-000 module, and a windows program using c# and the CySmart API Started from the published example).

Most of the app is written and works, including reading and setting ports, getting A/D info both reading and by notification and I am now (belatedly!) exploring the low power behavior of the device. Both firmware and software are getting a bit sizeable, so I am not going to post the entire thing, but if someone wants more details about some aspect please let me know and I will try and reduce to a managable size and still demonstrate that aspect.

I have two problems, one around the behaviour of CySmart, and one on the behavior of C#.

1) The CySmart application removes the "connected" tic when the peripheral is timed out.

I would like to do the same in order to manage the graceful degredation of the link, and show the user (me!) what is going on. However I cannot find any way of achieving this directly using the CySmart API to interrogate the status of the connection. Is there an elegant way to do this or does it have to be achieved using timers and then monitoring the return of a packet request somehow?

2) I want part of the app functionaliy to allow a user to nominate a specic device address from the scan list, after which that device will automatically be connected when it it is seen in the scan list.

The code has been written to take a focused device address and place it in escrow. When a button is pressed to restart the scan the code compares each device as it is scanned with the device address in escrow. If a match is found the scan continues to completion. Another button is then used to take the escrow address and creates the connection. All this works, but if I move the creation of the connection into the scanning code I end up in horrible issues with null pointers or getting locked in unresolved wait states. I have tried forcing a button click for the button that works, embedding the code into the scan routine or at various places further down line from that point, and even using global flags to try and force it from the main program loop...... all failed with the same problems.

This seems to be because the call to "BLEManager.Connect(new CyConnectInfo(PEER_DEVICE_BD_ADDR, new CyBleConnectionSettings()));" results in a callback to the "BLEManagerCallBack.ConnectionHandler" (which "sets" an essential AutoResetEvent) if the code is run from a  Form control event, but not if the routine is called from any other place. I cannot follow the program execution here as it is hidden inside the API.  I know this is a bit specific but any general thoughts and or comments might get me started again!

Any and all comments or suggestions very welcome!

0 Likes
1 Solution
Anonymous
Not applicable

1) BLE has a supervision timeout and transmits data within windowed intervals for standard BLE connections. I would assume there is some sort of API/signaling for the CySmart API to support this. Try looking at Supervision Timeout, Disconnection Event occurring when connection is lost, or something related to Connection Timing. The detection of lost communications is fundamental to wireless applications and should be built into APIs regardless of which protocol/medium it is.

2) You first need to stop scanning before you can initiate a connection. Try ending the scanning, THEN connecting to the escrowed device.

The BLE radio functions as: Scanning,Advertising, Connected, Idle. Scanning can only transition to/from Idle, Advertising can transition to Connected and from Idle, and Connected can only transition to Idle.

The Connect() function you are calling should have an API return value that tells you if you are trying to do an invalid operation (at least on the PSoC API it does for the functions). The API might be different for the Bluetooth for the CySmart APIs, but I wouldn't expect them to have significantly different code architecture from the PSoC chips themselves.

View solution in original post

2 Replies
Anonymous
Not applicable

1) BLE has a supervision timeout and transmits data within windowed intervals for standard BLE connections. I would assume there is some sort of API/signaling for the CySmart API to support this. Try looking at Supervision Timeout, Disconnection Event occurring when connection is lost, or something related to Connection Timing. The detection of lost communications is fundamental to wireless applications and should be built into APIs regardless of which protocol/medium it is.

2) You first need to stop scanning before you can initiate a connection. Try ending the scanning, THEN connecting to the escrowed device.

The BLE radio functions as: Scanning,Advertising, Connected, Idle. Scanning can only transition to/from Idle, Advertising can transition to Connected and from Idle, and Connected can only transition to Idle.

The Connect() function you are calling should have an API return value that tells you if you are trying to do an invalid operation (at least on the PSoC API it does for the functions). The API might be different for the Bluetooth for the CySmart APIs, but I wouldn't expect them to have significantly different code architecture from the PSoC chips themselves.

D_Sd_3235936
Level 4
Level 4
25 sign-ins 50 questions asked 25 replies posted

Hi

Can you please explain how you achieved :


1) The CySmart application removes the "connected" tic when the peripheral is timed out.

I would like to do the same in order to manage the graceful degredation of the link, and show the user (me!) what is going on. However I cannot find any way of achieving this directly using the CySmart API to interrogate the status of the connection.

0 Likes