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

Notifications and read function to be used in the same application

Hi Devs,

based on this example

https://github.com/NordicPlayground/nRF52-Bluetooth-Course

i was able to run it, and the value field appear below the Unknown Characteristics properties incremented every second as expected.

MY question however is whether it is possible at all to have both the enable notification and "read" button to run at the same time and update that value field. The purpose is that if i don't enable notifications, and just push the read button, the value field will be read on demand and not pushed to the client. Of course a better functionality would be if "notifications enabled" and read button pushed, both will not crash each other and just update the value field at a faster pace. Hope i have explained the situation clearly, and any help would be appreciated. thx.

  • Hi Pete,

    I'm not sure I understand the issue. As far as I can see the example already have both notification and read available. Isn't it :

     

  • Hi Hung,

    the "read" doesn't work in the nRF connect application. When pressed it does nothing. Does it work at your side ? thx

  • I haven't tried myself. But I don't see any reason why it wouldn't work. 

    If you are getting started and want to continue, I would suggest to have a look at the ble_app_blinky . You can use the nRFBlinky app to interact with it. The source code of the app is available on our github

    You can also have a look at ble_app_uart example . 

  • Hi Hung,

    thanks for directing me back to the basics. Helped clear my mind that i wasn't explaining the situation clearly.

    Let me try this again.

    Recently i finished projects using the ESP32, and the EVT handler had WRITE_EVT and READ_EVT;

    The nRF doesn't have READ_EVT; this seems to be done automatically by the stack on a "normal" read request. There however seems to be an authorize read/write http://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v7.x.x/doc/7.2.0/s110/html/a00888.html ( do clarify if wrong). But I have no clue how to update the unknown characteristic value field when receiving this event. I understand that the notification evt starts a timer that does an update every second, calling the ble_cus_custom_value_update(); However, trying to run the ble_cus_custom_value_update() on RW_AUTHORIZE_REQUEST event causes a fatal error and reboots the nRF528.

    I need to do the following on a read event:

    1) Update the value field of the unknown characteristic from a sensor reading when receive a read request.

    2) Sleep after that for "some" time

    3) Wake up and advertise, re-connect , back to step 1. The cycle continues.

    So I am asking is there any way to update the custom characteristic field when receiving a authorize read request ? thx.

  • Hi Pete, 

    You are correct on that the normal read (unauthorized read) is handled by the softdevice and you have no event for that. 

    The application receive an event for authorized read. But you would need to configure the characteristic for that. Please set attr_md.rd_auth = 1 when you add the characteristic.

    If you use S132 you should look at the documentation for S132 instead of S110. Please have a look here. Make sure you call the reply api in the event so that the softdevice would be able to reply to the peer. 

    When you receive an error, please try to find the line that cause the error and the error code. With that you can compare to the description of the list of errors for the function and can find the cause. Please have a look at the debug guide here

    Regarding your requirements, at step 2 how long do you plan to sleep ? Do you plan to keep the connection ? If not, you can simply trigger a disconnection and then enter sleep mode. 

Related