I am developing a simple ble peripheral device that will measure temperature and humidity. For the most
part, it's working but I can't get the behavior I expect when enabling notifications. I have searched various
web sites - including Zephyr - for info; but am coming up short. Some help would be appreciated.
I am using latest nrf connect sdk to develop the app, I have been having problems consistently using
the vscode front-end, so I am currently using the nrf connect cli for building the app and nrf downloading
tool to flash. Will leave questions about vscode for another thread. I can reliably build and flash apps
using the above and am using the android nrf connect test app on smartphone for verifying correct
service behavior. Service declaration is as follows:
int bt_svc_set_temperature(int temp_ble) {
int rc = bt_gatt_notify(NULL, &svc.attrs[1], &temp_ble, sizeof(temp_ble));
return rc == -ENOTCONN ? 0 : rc;
}
int bt_svc_set_humidity(int hum_ble) {
int rc = bt_gatt_notify(NULL, &svc.attrs[3], &hum_ble, sizeof(hum_ble));
return rc == -ENOTCONN ? 0 : rc;
}
int main(void) {
// start advertising
int error = bt_enable(NULL);
........
error = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
.........
printk("Advertising successfully started\n");
while (1) {
k_sleep(K_SECONDS(2));
if (sensor_sample_fetch(sht)) {
printf("Failed to fetch sample from SHT4X device\n");
} else {
sensor_channel_get(sht, SENSOR_CHAN_AMBIENT_TEMP, &temp);
temp_ble = temp.val1; // Only integer part of temp for now
bt_svc_set_temperature(temp_ble);
sensor_channel_get(sht, SENSOR_CHAN_HUMIDITY, &hum);
hum_ble = hum.val1; // Only integer part of hum for now;
bt_svc_set_humidity(hum_ble);
}