Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spp_server example question/issue (IDFGH-9207) #10597

Closed
3 tasks done
bheestandLMT opened this issue Jan 22, 2023 · 2 comments
Closed
3 tasks done

spp_server example question/issue (IDFGH-9207) #10597

bheestandLMT opened this issue Jan 22, 2023 · 2 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@bheestandLMT
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

When running the example code for the spp_server under Nimbke BLE, I receive an error when a device is disconnected and a notification is sent.

Once a device disconnects, and I send a notification, I get error #7 for the disconnected device notification. (Other connected devices receive the notification OK)

I see an array is made to keep track of the connected devices
uint16_t connection_handle[CONFIG_BT_NIMBLE_MAX_CONNECTIONS];

and that array is populated when a device connects:
connection_handle[event->connect.conn_handle - 1] = event->connect.conn_handle;

The connection never gets deleted from the connect_handle array on disconnect.
What is the proper way to remove the particular connection_handle when a device disconnects so that error #7 is not thrown when sending notifications.

Thanks!

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 22, 2023
@github-actions github-actions bot changed the title spp_server example question/issue spp_server example question/issue (IDFGH-9207) Jan 22, 2023
@IshaESP
Copy link
Contributor

IshaESP commented Jan 23, 2023

Hi @bheestandLMT ,
Can you tell me on which chip you are facing this issue?

After disconnecting with one device, the connection_handle array is not being updated and while sending notifications it's giving error as the connection is not present.
Can you try these two things:

  1. In disconnect event, set connection_handle[event->connect.conn_handle - 1] as -1
  2. Before sending notifications, add a check that if connection_handle[event->connect.conn_handle - 1] == -1 don't send the notification.

If the above doesn't work, can you please share the error logs with us?
Thank You.

@bheestandLMT
Copy link
Author

bheestandLMT commented Jan 23, 2023

Thanks for the reply.
I had to alter your code slightly to get it to work.
Since the code already checked if connection_handle[ ] was = 0 in a for statement before sending a notification, i made the disconnected connection_handle array = 0 instead of -1. See the for statement code that sends notification below:
for ( int i = 0; i < CONFIG_BT_NIMBLE_MAX_CONNECTIONS; i++) { if (connection_handle[i] != 0) { struct os_mbuf *txom; txom = ble_hs_mbuf_from_flat(ntf, sizeof(ntf)); rc = ble_gatts_notify_custom(connection_handle[i], ble_spp_svc_gatt_read_val_handle, txom); if ( rc == 0 ) { ESP_LOGI(tag,"Notification sent successfully"); } else { ESP_LOGI(tag,"Error in sending notification rc = %d", rc); } } }

I also had to change the in disconnect event from event->connect.conn_handle to event->disconnect.conn.conn_handle. Here is the code I ended up using:
connection_handle[event->disconnect.conn.conn_handle - 1] = 0;

that worked perfectly and still sends notifications to any other devices that are still connected.

Please feel free to close this and thank you again!

@espressif-bot espressif-bot added Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants