This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Send / return a message to acknowledge that my peripheral is successfully connected

I am having some issues figuring out how to send a simple string or character to my central.

What I want is the peripheral to send an acknowledgement back to the central that it is connected.

I am building on the ble_app_uart example in ble_peripherals

I figured that it needs to happen in the BLE_GAP_EVT_CONNECTED case in on_ble_evt, and I need to use the ble_nus_string_send(&m_nus, data_array, index); function, however I can't figure out how to make it send a string out of this, I imagined it would be sufficient to replace data_array with for example connected_message = "yay, connected!"; and set index = sizeof(connected_message); but it doesnt work.. Some help please ? :)

Parents
  • I don't think you want to do that in the on_ble_evt function. That is running in the event (interrupt) context IIRC. You would want to set a flag and use that in your main loop to trigger sending the message to the central device. Also, it looks like that ble_nus_string_send uses notifications, so you will want to wait until the CCCD is turned on for notification. You can detect that where you handle write events and you can see the write to the CCCD handle and use that to trigger setting your flag.

  • Ok, I will probably use this instead, allthough I am still curious on how I can send something simple over ble, I cannot figure out how to do it and no answers regarding similar topics really clarify this for me

Reply Children
No Data
Related