From f7806d4c7e31a3e8c43553cc2ae92ec4eee7a564 Mon Sep 17 00:00:00 2001 From: rbaron Date: Sun, 4 Dec 2022 10:32:20 +0100 Subject: [PATCH] Really fixing BTHome v2 illuminance encoding this time --- code/nrf-connect/samples/ble/src/encoding.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/nrf-connect/samples/ble/src/encoding.c b/code/nrf-connect/samples/ble/src/encoding.c index ee89d16..82a5a21 100644 --- a/code/nrf-connect/samples/ble/src/encoding.c +++ b/code/nrf-connect/samples/ble/src/encoding.c @@ -108,9 +108,11 @@ int prst_ble_encode_service_data(const prst_sensors_t* sensors, out[8] = humi_val >> 8; // Illuminance. out[9] = 0x05; - out[10] = sensors->photo.brightness & 0xff; - out[11] = sensors->photo.brightness >> 8; - out[12] = 0; + // 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; // Battery voltage. out[13] = 0x0c; // Value. Factor of 0.001.