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 ? :)

  • 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

  • Hopefully I don't come off as being obtuse, because I don't mean to be. It sounds like you want the Nordic BLE equivalent of "Hello World". Which you certainly can do, but it is more work than it would be with a simple PC program. The best thing to do IMHO would be to experiment with the examples Nordic provides with its SDK. There are examples of central and peripheral applications that you can point at each other and get communicating. Alternatively there is also a Nordic iOS toolbox with examples for an iPhone if that is what you are using for a Central device. Another way of doing a "hello world" type of experiment would be to use the Master Control Panel as your Central application and use it to connect and talk to one of the peripheral projects provided in the SDK.

  • Not at all, as you say it's probably more complicated than I get.

    I am playing around with the examples and got a bunch of peripherals/robots being controlled from a multilink central combined with the UART examples, but every time I try to add or change features as I want them, I sort of bump into issues like this one where it's just not as simple to do as it usually is on the MCUs i've been playing with before.

    Thanks for your reply though, I will use your suggestion on my project :)

Related