This is probably a simple question for an experienced nRF developer.
I have a demo going where I can read or write any of four characteristics I have set up on my peripheral (in my case an nRF58232 dev board) from the central. IE: I can easily use nRF Connect to R/W any of these characteristics. This demonstrates that I can send data from the central to the peripheral.
Now, I want to send data from the peripheral to the central. I am aware I need to assign a CCCD to the characteristics and set the NOTIFY bit. All good so far. I can see the notify field in nRF Connect for my four characteristics and am able to enable or disable this value.
Next, I want to modify the characteristic value based on an action taken AT THE PERIPHERAL. In this case, the dev board has four buttons. If I press one of the buttons, I want to do two things:
1) Increment the respective characteristic value by one.
2) Notify the central which characteristic has changed and what the updated value is.
QUESTION 1) What is the preferred call to update the characteristic value from within the peripheral itself?
QUESTION 2) What is the recommended code for sending this update back to the central?
From one of the online tutorials, I believe a partial answer to Question 2 is code that looks something like:
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &len;
hvx_params.p_data = (uint8_t*)characteristic_value;