From 1aac8c9f15b8e0499d0e2b8647d8f72acc3e5f00 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Sun, 26 Jan 2020 17:14:12 +0100 Subject: [PATCH] [Firmware] Adapt Decoder for Optimized Payload Format --- Firmware/README.md | 23 +++++++++++++++-------- Firmware/src/main.cpp | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Firmware/README.md b/Firmware/README.md index 3cbf908..101a3a0 100644 --- a/Firmware/README.md +++ b/Firmware/README.md @@ -11,14 +11,21 @@ Project was created using PlatformIO Atmel-AVR Framework ``` function Decoder(bytes, port) { var decoded = {}; - decoded.t = (bytes[0]) | (bytes[1] << 8 ) | (bytes[2] << 16 ) | (bytes[3] << 24) - decoded.t = decoded.t / 100 - decoded.p = (bytes[4]) | (bytes[5] << 8 ) | (bytes[6] << 16 ) | (bytes[7] << 24) - decoded.p = decoded.p / 100 - decoded.h = (bytes[8]) | (bytes[9] << 8 ) | (bytes[10] << 16 ) | (bytes[11] << 24) - decoded.h = decoded.h / 100 - decoded.v = (bytes[12]) | (bytes[13] << 8 ) | (bytes[14] << 16 ) | (bytes[15] << 24) - decoded.v = decoded.v / 1000 + + // We always have Battery Voltage + 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; + + // Humidity (int32_t) + if (bytes.length >= 9) + decoded.t = (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; return decoded; } diff --git a/Firmware/src/main.cpp b/Firmware/src/main.cpp index e4ab652..504de65 100644 --- a/Firmware/src/main.cpp +++ b/Firmware/src/main.cpp @@ -202,7 +202,7 @@ void loop() #ifdef RF_LORA #ifdef HAS_NO_SENSOR - // Send Packet in all 12 SFs for Beacon Mode + // Send Packet in all 6 SFs for Beacon Mode unsigned char Frame_Port =0x07; for (int i = SF7BW125; i<=SF12BW125; i++) { lora_data tdata = data; @@ -213,7 +213,7 @@ void loop() } #else // Send LoRa Packet, Increment Frame Counter - lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125); + lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01); Frame_Counter_Tx++; #endif #endif @@ -230,4 +230,4 @@ void loop() // Sleep until next Measurement sleep(SLEEP_TIME); -} \ No newline at end of file +}