From ddc0524d98ac3be378286d6e7a68b1d6d53de6ae Mon Sep 17 00:00:00 2001 From: Jonathan Hanson Date: Sat, 12 Aug 2023 14:40:04 -0700 Subject: [PATCH 1/4] move the ith20r inkbird sensor to use battery_ok and the correct float range for the battery value --- src/devices/inkbird_ith20r.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/inkbird_ith20r.c b/src/devices/inkbird_ith20r.c index 0ad87202f..2167ccf9b 100644 --- a/src/devices/inkbird_ith20r.c +++ b/src/devices/inkbird_ith20r.c @@ -102,7 +102,7 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint32_t subtype = (msg[3] << 24 | msg[2] << 16 | msg[1] << 8 | msg[0]); int sensor_num = msg[4]; uint16_t word56 = (msg[6] << 8 | msg[5]); - int battery = msg[7]; + float battery = msg[7] * 0.01f; uint16_t sensor_id = (msg[9] << 8 | msg[8]); float temperature = ((int16_t)(msg[11] << 8 | msg[10])) * 0.1f; float temperature_ext = ((int16_t)(msg[13] << 8 | msg[12])) * 0.1f; @@ -115,7 +115,7 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) data = data_make( "model", "", DATA_STRING, "Inkbird-ITH20R", "id", "", DATA_INT, sensor_id, - "battery", "Battery", DATA_INT, battery, + "battery_ok", "Battery", DATA_FORMAT, "%.1f %%", DATA_DOUBLE, battery, "sensor_num", "", DATA_INT, sensor_num, "mic", "Integrity", DATA_STRING, "CRC", "temperature_C", "Temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, temperature, From c23f4dbec1d526ec41304dc1dc60b13bf6e0e822 Mon Sep 17 00:00:00 2001 From: Jonathan Hanson Date: Sat, 12 Aug 2023 14:43:41 -0700 Subject: [PATCH 2/4] move the mic field to the end of the list, per code review --- src/devices/inkbird_ith20r.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/inkbird_ith20r.c b/src/devices/inkbird_ith20r.c index 2167ccf9b..a9c9bf0b7 100644 --- a/src/devices/inkbird_ith20r.c +++ b/src/devices/inkbird_ith20r.c @@ -117,10 +117,10 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) "id", "", DATA_INT, sensor_id, "battery_ok", "Battery", DATA_FORMAT, "%.1f %%", DATA_DOUBLE, battery, "sensor_num", "", DATA_INT, sensor_num, - "mic", "Integrity", DATA_STRING, "CRC", "temperature_C", "Temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, temperature, "temperature_2_C", "Temperature2", DATA_FORMAT, "%.1f C", DATA_DOUBLE, temperature_ext, "humidity", "Humidity", DATA_FORMAT, "%.1f %%", DATA_DOUBLE, humidity, + "mic", "Integrity", DATA_STRING, "CRC", NULL); /* clang-format on */ @@ -133,10 +133,10 @@ static char const *const output_fields[] = { "id", "battery", "sensor_num", - "mic", "temperature_C", "temperature_2_C", "humidity", + "mic", NULL, }; From a575a8083c4a92bebb9317e84889d6c6d1363866 Mon Sep 17 00:00:00 2001 From: Jonathan Hanson Date: Sat, 12 Aug 2023 15:04:18 -0700 Subject: [PATCH 3/4] fix renamed battery field in output_fields --- src/devices/inkbird_ith20r.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/inkbird_ith20r.c b/src/devices/inkbird_ith20r.c index a9c9bf0b7..133ece701 100644 --- a/src/devices/inkbird_ith20r.c +++ b/src/devices/inkbird_ith20r.c @@ -131,7 +131,7 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) static char const *const output_fields[] = { "model", "id", - "battery", + "battery_ok", "sensor_num", "temperature_C", "temperature_2_C", From ffba182c1c8b14073b2a45656251cd6ca6b4efd0 Mon Sep 17 00:00:00 2001 From: Jonathan Hanson Date: Sun, 13 Aug 2023 11:14:17 -0700 Subject: [PATCH 4/4] rename the battery variable to be clearer, report the battery float without formatting --- src/devices/inkbird_ith20r.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/inkbird_ith20r.c b/src/devices/inkbird_ith20r.c index 133ece701..6fe4de886 100644 --- a/src/devices/inkbird_ith20r.c +++ b/src/devices/inkbird_ith20r.c @@ -102,7 +102,7 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint32_t subtype = (msg[3] << 24 | msg[2] << 16 | msg[1] << 8 | msg[0]); int sensor_num = msg[4]; uint16_t word56 = (msg[6] << 8 | msg[5]); - float battery = msg[7] * 0.01f; + float battery_ok = msg[7] * 0.01f; uint16_t sensor_id = (msg[9] << 8 | msg[8]); float temperature = ((int16_t)(msg[11] << 8 | msg[10])) * 0.1f; float temperature_ext = ((int16_t)(msg[13] << 8 | msg[12])) * 0.1f; @@ -115,7 +115,7 @@ static int inkbird_ith20r_callback(r_device *decoder, bitbuffer_t *bitbuffer) data = data_make( "model", "", DATA_STRING, "Inkbird-ITH20R", "id", "", DATA_INT, sensor_id, - "battery_ok", "Battery", DATA_FORMAT, "%.1f %%", DATA_DOUBLE, battery, + "battery_ok", "Battery", DATA_DOUBLE, battery_ok, "sensor_num", "", DATA_INT, sensor_num, "temperature_C", "Temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, temperature, "temperature_2_C", "Temperature2", DATA_FORMAT, "%.1f C", DATA_DOUBLE, temperature_ext,