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

writing to an attribute without a server connection?

 Good afternoon, 

     I have a question regarding the ble_app_hrs_rscs_relay example. I am using this example to read scan response data from a peripheral without pairing with it. I am parsing the data and would like to send it to a cell phone that connects to the ble_app_hrs_rscs_relay example.

     I have written a simple service that shows up no my phone once i pair with the ble_app_hrs_rscs_relay. What is the best way to write to the attribute value of this example? again the ble_app_hrs_rscs_relay example i am using is not connected to any device except my phone. All the relay_example is doing is receiving scan responses and i would like to write these to an attribute that i can see from my phone.  The problem i am having when writing to the attribute is that since the ble_app_hrs_rscs_relay example is not connected to any peer, i cannot write data with sd_ble_gatts_hvx(p_relay_service->conn_handle, &hvx_params) since the conn_handle is invalid(because there is no connection to another server).

 I am a using nrf52840 Board with softdevice s140 nRF5_SDK_15.2.0. 

 -- many thanks

  • Hi Gianfranco,

    Yes, you can do scan request to other sensors to collect data and then send data to the phone via a connection. 

    When you send data to the phone in a connection, the easiest way is to call sd_ble_gatts_hvx() as you mentioned. This function will send a notification to the phone and the phone then can display/store the data on the app. 

    But the conn_handle you need to provide to the function is not the connection to the sensor but the connection handle to the phone. And you should have a valid conn_handle to the phone to be able to send the notification. Make sure you enable notification on the phone prior to that. 

    I would suggest you to study the ble_app_hrs example in the SDK where it send notification to the phone using the *_hvx function. The ble_app_uart example is also useful. 

    Note that you would need to find a way in your relay application to tell the app on the phone the data was from which sensor. Maybe by using one extra byte in the notification payload.  

Related