Hello! I'm trying to figure out how to program a nRF52832 to subscribe and read from a TX or custom characteristic on another nRF52832.
My environment:
- NRF Connect SDK in VSCode - Version 2.1.1
- Zephyr v3.1.99
What I've done so far:
- I've adapted the peripheral_uart example such that I can use nRF Connect app in iOS to connect to the peripheral BLE device, subscribe to the UART TX Characteristic, and see an incrementing integer in the Log every 3 seconds.
- I've tested the central_uart example such that I can form a successful connection between the central nRF52832 device and the peripheral nRF52832 device I've described above.
I can't seem to locate a tutorial on the procedure to subscribe to the TX characteristic or any custom characteristic for that matter. I've looked through some tutorials, such as:
For my code, I haven't really made many changes to either the peripheral_uart or central_uart base examples.
My thread for writing the incrementing integer is as follows, and is part of the firmware on my peripheral device.
void ble_write_thread(void) { /* Don't go any further until BLE is initialized */ k_sem_take(&ble_init_ok, K_FOREVER); int i = 0; for (;;) { uint8_t testbuf[10]; sprintf(testbuf, "%d", i); //send message stream on connection if (current_conn != 0){ printk("\nMessage Sent!\n"); bt_nus_send(NULL, testbuf, 10); i += 1; k_sleep(K_MSEC(3000)); } } }
I've looked into some of the functions found within Gatt Client API such as bt_gatt_subscribe() and bt_gatt_read(), but I'm having trouble getting them to work (if they're even the correct function to use). Is there any advice on how I should be polling and storing the output from the peripheral TX characteristic on my central device? It would also be great to know how to do the same for a custom characteristic, created in the same way as the tutorial I've linked above.
Thank you in advance!