How to implement a write handler in nRF Connect SDK?

Hi,

Perhaps this question is too basic, but I haven't been able to find this anywhere.

I've followed this tutorial successfully with an nRF52832 DK:  nRF Connect SDK Bluetooth Low Energy tutorial part 1: Custom Service in Peripheral role

However, I'm missing the part about how to implement a peripheral write handler. In other words, how to make writing to a characteristic operate on a uC peripheral; something as simple as turning on/off a GPIO by writing 1/0 to a characteristic.

In this tutorial (using the old nRF SDK) it is clear how to implement this write handler and initialize it: https://novelbits.io/smart-ble-lightbulb-application-nrf52/. The function in question is the "static void led_write_handler" function that receives a led state uint8_t, and is able to write to an LED. Furthermore, it also shows how to declare a function pointer to it within structure linked to the service and how to initialize it from the main.c

My question is: how can I implement such a function and "register" it with the service? If there's a tutorial that shows how to do it, I'd greatly appreciate it.

Thanks in advance for your help



Parents
  • Hi Builder01
    I'm on a quest to do this as well.
    I haven't followed the example that you have given, I will take a deeper look tomorrow.
    I've found that the sample zephyr/samples/bluetooth/peripheral has custom service and characteristics that have read/write/notify/indicate, its not a tutorial and I'm currently working on understand to create my own write  and then notify characteristics. Not there yet. But it does look promising. Hope its helpful for you and I would also in interesting in a tutorial that does this.

Reply
  • Hi Builder01
    I'm on a quest to do this as well.
    I haven't followed the example that you have given, I will take a deeper look tomorrow.
    I've found that the sample zephyr/samples/bluetooth/peripheral has custom service and characteristics that have read/write/notify/indicate, its not a tutorial and I'm currently working on understand to create my own write  and then notify characteristics. Not there yet. But it does look promising. Hope its helpful for you and I would also in interesting in a tutorial that does this.

Children
No Data
Related