Hello All,
I am programming an nrf52480 using zephyr on a windows machine.
I am trying to write a bluetooth peripheral characteristic, ore specifically to the led characteristic in the nordic led and button service.
In my code far I have verified:
- the central scanning mechanism works to find the peripheral device I want to attached to,
- filtering is working correctly such that I connect to the correct device.
Upon this step I didn't know how to write to the characteristic to turn on an led on the peripheral and I have determined the following steps need to be followed to write to a characteristic:
- I need to discover the characteristics that are attached with the uuid using the bt_gatt_discover function
- Once the desired characteristic is found using the discover_cb funciton that is set in the bt_gatt_discover funciton as a parameter structure then the handles value can be extracted.
- The characteristic handle value is used with bt_gatt_write_without_response function to transmit the data.
Please correct me if the above understanding is incorrect.
Given these steps I am getting stuck on step one.
The following is th ebackground for the steps I am taking before getting stuck. I think the issue is how I have implemented the bt_gatt_discover function:
- Once the filter match is done, the system automatically attempts to connect with the device at which point the scan_connecting callback function is called. INn my case this function just produces the logs.
- To my understanding the scan_connecting function is a call back before the actuatl connection is done.
- Once the connection to the peripheral is made the connected callbacck set using the bt_conn_cb_resiter funciton is called.
- In the connected callback I am attempting to call the bt_gatt_discover function.
My program either crashes or stalls when I call the bt_gatt)discover function. I think the issue is how or when I am calling this function because if I do not include it the logs for the connected callback function are outputted properly as shown below:
```
[00:01:07.612,884] <inf> button_control: IN the connected callback
[00:01:07.612,915] <inf> button_control: Bluetooth Connection Sucessfull
[00:01:07.612,915] <err> button_control: RIGHT BEFORE THE DISCOVER FUNCTION
```
Given this connected code:
```
```
When I uncomment the bt_gatt_discover line as below:
```
```
I get the following log output (the connected function doesn't provide it's log)
```
[00:00:06.744,781] <inf> button_control: Connected in the Scan Connecting callback
```
What is going on? What is incorrect about my thinking and code? Any guidance on this would be much appreciated.
the below are the important pieces of code then settingup the bluetooth connection in the bluetooth_control.c file:
```
```
The below is my bluetooth implementation in my main.c file:
```
```
I have also attached the full main.c and the bluetooth_control.c files as well for your reference.