diff --git a/code/nrf-connect/samples/ble/src/encoding.c b/code/nrf-connect/samples/ble/src/encoding.c index d252984..362caf1 100644 --- a/code/nrf-connect/samples/ble/src/encoding.c +++ b/code/nrf-connect/samples/ble/src/encoding.c @@ -104,33 +104,36 @@ int prst_ble_encode_service_data(const prst_sensors_t* sensors, out[4] = temp_val & 0xff; out[5] = temp_val >> 8; // Humidity. - out[6] = 0x03; - // Value. Factor 0.01, over 100%. - uint16_t humi_val = 10000 * sensors->shtc3.rel_humi; - out[7] = humi_val & 0xff; - out[8] = humi_val >> 8; + out[6] = 0x2E; + // Value. Factor 1 over 100%. + uint8_t humi_val = 100*sensors->shtc3.rel_humi + 0.5f; + out[7] = humi_val; // Illuminance. - out[9] = 0x05; + out[8] = 0x05; // Value. Factor of 0.01. uint32_t lux_val = sensors->photo.brightness * 100; - out[10] = lux_val & 0xff; - out[11] = (lux_val >> 8) & 0xff; - out[12] = (lux_val >> 16) & 0xff; + out[9] = lux_val & 0xff; + out[10] = (lux_val >> 8) & 0xff; + out[11] = (lux_val >> 16) & 0xff; // Battery voltage. - out[13] = 0x0c; + out[12] = 0x0c; // Value. Factor of 0.001. uint16_t batt_val = sensors->batt.adc_read.millivolts; - out[14] = batt_val & 0xff; - out[15] = batt_val >> 8; + out[13] = batt_val & 0xff; + out[14] = batt_val >> 8; // Soil moisture. - out[16] = 0x14; - // Factor of 0.01, so we need to multiply our the value in 100% by 1/0.01 = 100. - uint16_t soil_val = 10000 * sensors->soil.percentage; - out[17] = soil_val & 0xff; - out[18] = soil_val >> 8; + out[15] = 0x2F; + // Factor of 1 over 100% + uint8_t soil_val = 100*sensors->soil.percentage + 0.5f; + out[16] = soil_val; + // Battery percentage. + out[17] = 0x01; + // Value. Factor 1 over 100% + uint8_t batt_percentage_val = 100*sensors->batt.percentage + 0.5f; + out[18] = batt_percentage_val; #endif // Encoding protocols LOG_HEXDUMP_DBG(out, out_len, "Encoded BLE adv: "); return 0; -} \ No newline at end of file +}