From e2c975178a97da03d07e414da5ccd42c73d266d4 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 25 Nov 2018 19:16:31 +0100 Subject: [PATCH] payload converter fixes --- include/payload.h | 6 +++--- platformio.ini | 7 +++---- src/TTN/packed_decoder.js | 22 +++++++++++----------- src/payload.cpp | 25 +++++++++++++------------ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/payload.h b/include/payload.h index 91bf3778..2fce0fff 100644 --- a/include/payload.h +++ b/include/payload.h @@ -15,7 +15,7 @@ #define LPP_MSG_CHANNEL 28 #define LPP_HUMIDITY_CHANNEL 29 #define LPP_BAROMETER_CHANNEL 30 -#define LPP_GAS_CHANNEL 31 +#define LPP_AIR_CHANNEL 31 #endif @@ -66,8 +66,8 @@ private: void writeUint32(uint32_t i); void writeUint16(uint16_t i); void writeUint8(uint8_t i); - void writeHumidity(float humidity); - void writeTemperature(float temperature); + void writeFloat(float humidity); + void writeUFloat(float temperature); void writeVersion(char * version); void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h); diff --git a/platformio.ini b/platformio.ini index 69d42cb9..08731c11 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,21 +29,20 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.6.85 +release_version = 1.6.86 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose -debug_level = 0 +debug_level = 3 ; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA upload_protocol = esptool ;upload_protocol = custom extra_scripts = pre:build.py keyfile = ota.conf -;platform_espressif32 = espressif32@1.5.0 platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6 board_build.partitions = min_spiffs.csv monitor_speed = 115200 lib_deps_lora = -; MCCI LoRaWAN LMIC library@^2.2.2 +; MCCI LoRaWAN LMIC library@2.3.0 lib_deps_display = U8g2@>=2.25.0 lib_deps_rgbled = diff --git a/src/TTN/packed_decoder.js b/src/TTN/packed_decoder.js index 0571bfa0..46ac91c2 100644 --- a/src/TTN/packed_decoder.js +++ b/src/TTN/packed_decoder.js @@ -43,7 +43,7 @@ function Decoder(bytes, port) { if (port === 7) { // BME680 sensor data - return decode(bytes, [temperature, uint16, humidity, uint16], ['temperature', 'pressure', 'humidity', 'air']); + return decode(bytes, [float, ufloat, ufloat, ufloat], ['temperature', 'pressure', 'humidity', 'air']); } } @@ -116,9 +116,9 @@ var hdop = function (bytes) { }; hdop.BYTES = 2; -var temperature = function (bytes) { - if (bytes.length !== temperature.BYTES) { - throw new Error('Temperature must have exactly 2 bytes'); +var float = function (bytes) { + if (bytes.length !== float.BYTES) { + throw new Error('Float must have exactly 2 bytes'); } var isNegative = bytes[0] & 0x80; var b = ('00000000' + Number(bytes[0]).toString(2)).slice(-8) @@ -139,17 +139,17 @@ var temperature = function (bytes) { } return +(t / 100).toFixed(1); }; -temperature.BYTES = 2; +float.BYTES = 2; -var humidity = function (bytes) { - if (bytes.length !== humidity.BYTES) { - throw new Error('Humidity must have exactly 2 bytes'); +var ufloat = function (bytes) { + if (bytes.length !== ufloat.BYTES) { + throw new Error('Ufloat must have exactly 2 bytes'); } var h = bytesToInt(bytes); return +(h / 100).toFixed(1); }; -humidity.BYTES = 2; +ufloat.BYTES = 2; var bitmap = function (byte) { if (byte.length !== bitmap.BYTES) { @@ -193,8 +193,8 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') { uint16: uint16, uint32: uint32, uptime: uptime, - temperature: temperature, - humidity: humidity, + float: float, + ufloat: ufloat, latLng: latLng, hdop: hdop, bitmap: bitmap, diff --git a/src/payload.cpp b/src/payload.cpp index 301034f2..14991e96 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -104,15 +104,16 @@ void PayloadConvert::addBME(bmeStatus_t value) { #ifdef HAS_BME int16_t temperature = (int16_t)(value.temperature); // float -> int uint16_t humidity = (uint16_t)(value.humidity); // float -> int + uint16_t pressure = (uint16_t)(value.pressure); // float -> int uint16_t iaq = (uint16_t)(value.iaq); // float -> int buffer[cursor++] = highByte(temperature); buffer[cursor++] = lowByte(temperature); - buffer[cursor++] = highByte(value.pressure); - buffer[cursor++] = lowByte(value.pressure); + buffer[cursor++] = highByte(pressure); + buffer[cursor++] = lowByte(pressure); buffer[cursor++] = highByte(humidity); buffer[cursor++] = lowByte(humidity); - buffer[cursor++] = highByte(value.iaq); - buffer[cursor++] = lowByte(value.iaq); + buffer[cursor++] = highByte(iaq); + buffer[cursor++] = lowByte(iaq); #endif } @@ -192,10 +193,10 @@ void PayloadConvert::addSensor(uint8_t buf[]) { void PayloadConvert::addBME(bmeStatus_t value) { #ifdef HAS_BME - writeTemperature(value.temperature); - writeUint16(value.pressure); - writeHumidity(value.humidity); - writeUint16(value.iaq); + writeFloat(value.temperature); + writeUFloat(value.pressure); + writeUFloat(value.humidity); + writeUFloat(value.iaq); #endif } @@ -232,7 +233,7 @@ void PayloadConvert::writeUint16(uint16_t i) { intToBytes(cursor, i, 2); } void PayloadConvert::writeUint8(uint8_t i) { intToBytes(cursor, i, 1); } -void PayloadConvert::writeHumidity(float humidity) { +void PayloadConvert::writeUFloat(float humidity) { int16_t h = (int16_t)(humidity * 100); intToBytes(cursor, h, 2); } @@ -241,7 +242,7 @@ void PayloadConvert::writeHumidity(float humidity) { * Uses a 16bit two's complement with two decimals, so the range is * -327.68 to +327.67 degrees */ -void PayloadConvert::writeTemperature(float temperature) { +void PayloadConvert::writeFloat(float temperature) { int16_t t = (int16_t)(temperature * 100); if (temperature < 0) { t = ~-t; @@ -375,7 +376,7 @@ void PayloadConvert::addBME(bmeStatus_t value) { // 0.5% per bit => 0 .. 128 %C uint8_t humidity = (uint8_t)(value.humidity * 2.0); // 0.01 IAQ per bit => 0 .. 655,36 IAQ - uint16_t iaq = (uint16_t) value.iaq * 100; + uint16_t iaq = (uint16_t)value.iaq * 100; #if (PAYLOAD_ENCODER == 3) buffer[cursor++] = LPP_TEMPERATURE_CHANNEL; @@ -395,7 +396,7 @@ void PayloadConvert::addBME(bmeStatus_t value) { buffer[cursor++] = LPP_HUMIDITY; // 1 byte 0.5 % Unsigned buffer[cursor++] = humidity; #if (PAYLOAD_ENCODER == 3) - buffer[cursor++] = LPP_GAS_CHANNEL; + buffer[cursor++] = LPP_AIR_CHANNEL; #endif buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed buffer[cursor++] = highByte(iaq);