From 163fd13d5129a498b7b185471fe2a473f00ee621 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Fri, 7 Feb 2020 08:24:17 +0100 Subject: [PATCH] [Firmware] Fix Copy-Paste Error in Decoder --- Firmware/README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Firmware/README.md b/Firmware/README.md index 101a3a0..dc68bd0 100644 --- a/Firmware/README.md +++ b/Firmware/README.md @@ -12,20 +12,29 @@ Project was created using PlatformIO Atmel-AVR Framework function Decoder(bytes, port) { var decoded = {}; - // We always have Battery Voltage - decoded.v = (bytes[0] * 20) / 1000.0; + if (bytes.length == 16) { + // Old Payload Format + decoded.t = (bytes[0]) | (bytes[1] << 8 ) | (bytes[2] << 16 ) | (bytes[3] << 24) / 100.0; + decoded.p = (bytes[4]) | (bytes[5] << 8 ) | (bytes[6] << 16 ) | (bytes[7] << 24) / 100.0; + decoded.h = (bytes[8]) | (bytes[9] << 8 ) | (bytes[10] << 16 ) | (bytes[11] << 24) / 100.0; + decoded.v = (bytes[12]) | (bytes[13] << 8 ) | (bytes[14] << 16 ) | (bytes[15] << 24) / 1000.0; + } else { + // New Payload Format + // We always have Battery Voltage (uint8_t) + decoded.v = (bytes[0] * 20) / 1000.0; - // Temperature (int32_t) - if (bytes.length >= 5) - decoded.t = (bytes[1]) | (bytes[2] << 8 ) | (bytes[3] << 16 ) | (bytes[4] << 24) / 100.0; + // Temperature (int32_t) + if (bytes.length >= 5) + decoded.t = (bytes[1]) | (bytes[2] << 8 ) | (bytes[3] << 16 ) | (bytes[4] << 24) / 100.0; - // Humidity (int32_t) - if (bytes.length >= 9) - decoded.t = (bytes[5]) | (bytes[6] << 8 ) | (bytes[7] << 16 ) | (bytes[8] << 24) / 100.0; + // Humidity (int32_t) + if (bytes.length >= 9) + decoded.h = (bytes[5]) | (bytes[6] << 8 ) | (bytes[7] << 16 ) | (bytes[8] << 24) / 100.0; - // Atmospheric Pressure (int32t) - if (bytes.length >= 13) - decoded.t = (bytes[9]) | (bytes[10] << 8 ) | (bytes[11] << 16 ) | (bytes[12] << 24) / 100.0; + // Atmospheric Pressure (int32t) + if (bytes.length >= 13) + decoded.p = (bytes[9]) | (bytes[10] << 8 ) | (bytes[11] << 16 ) | (bytes[12] << 24) / 100.0; + } return decoded; }