payload converter fixes

This commit is contained in:
Klaus K Wilting 2018-11-25 19:16:31 +01:00
parent 15e8e0722d
commit e2c975178a
4 changed files with 30 additions and 30 deletions

View File

@ -15,7 +15,7 @@
#define LPP_MSG_CHANNEL 28 #define LPP_MSG_CHANNEL 28
#define LPP_HUMIDITY_CHANNEL 29 #define LPP_HUMIDITY_CHANNEL 29
#define LPP_BAROMETER_CHANNEL 30 #define LPP_BAROMETER_CHANNEL 30
#define LPP_GAS_CHANNEL 31 #define LPP_AIR_CHANNEL 31
#endif #endif
@ -66,8 +66,8 @@ private:
void writeUint32(uint32_t i); void writeUint32(uint32_t i);
void writeUint16(uint16_t i); void writeUint16(uint16_t i);
void writeUint8(uint8_t i); void writeUint8(uint8_t i);
void writeHumidity(float humidity); void writeFloat(float humidity);
void writeTemperature(float temperature); void writeUFloat(float temperature);
void writeVersion(char * version); void writeVersion(char * version);
void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g, void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g,
bool h); bool h);

View File

@ -29,21 +29,20 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; 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! ; 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 ; 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 MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA
upload_protocol = esptool upload_protocol = esptool
;upload_protocol = custom ;upload_protocol = custom
extra_scripts = pre:build.py extra_scripts = pre:build.py
keyfile = ota.conf keyfile = ota.conf
;platform_espressif32 = espressif32@1.5.0
platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6 platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
monitor_speed = 115200 monitor_speed = 115200
lib_deps_lora = lib_deps_lora =
; MCCI LoRaWAN LMIC library@^2.2.2 ; MCCI LoRaWAN LMIC library@2.3.0
lib_deps_display = lib_deps_display =
U8g2@>=2.25.0 U8g2@>=2.25.0
lib_deps_rgbled = lib_deps_rgbled =

View File

@ -43,7 +43,7 @@ function Decoder(bytes, port) {
if (port === 7) { if (port === 7) {
// BME680 sensor data // 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; hdop.BYTES = 2;
var temperature = function (bytes) { var float = function (bytes) {
if (bytes.length !== temperature.BYTES) { if (bytes.length !== float.BYTES) {
throw new Error('Temperature must have exactly 2 bytes'); throw new Error('Float must have exactly 2 bytes');
} }
var isNegative = bytes[0] & 0x80; var isNegative = bytes[0] & 0x80;
var b = ('00000000' + Number(bytes[0]).toString(2)).slice(-8) var b = ('00000000' + Number(bytes[0]).toString(2)).slice(-8)
@ -139,17 +139,17 @@ var temperature = function (bytes) {
} }
return +(t / 100).toFixed(1); return +(t / 100).toFixed(1);
}; };
temperature.BYTES = 2; float.BYTES = 2;
var humidity = function (bytes) { var ufloat = function (bytes) {
if (bytes.length !== humidity.BYTES) { if (bytes.length !== ufloat.BYTES) {
throw new Error('Humidity must have exactly 2 bytes'); throw new Error('Ufloat must have exactly 2 bytes');
} }
var h = bytesToInt(bytes); var h = bytesToInt(bytes);
return +(h / 100).toFixed(1); return +(h / 100).toFixed(1);
}; };
humidity.BYTES = 2; ufloat.BYTES = 2;
var bitmap = function (byte) { var bitmap = function (byte) {
if (byte.length !== bitmap.BYTES) { if (byte.length !== bitmap.BYTES) {
@ -193,8 +193,8 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
uint16: uint16, uint16: uint16,
uint32: uint32, uint32: uint32,
uptime: uptime, uptime: uptime,
temperature: temperature, float: float,
humidity: humidity, ufloat: ufloat,
latLng: latLng, latLng: latLng,
hdop: hdop, hdop: hdop,
bitmap: bitmap, bitmap: bitmap,

View File

@ -104,15 +104,16 @@ void PayloadConvert::addBME(bmeStatus_t value) {
#ifdef HAS_BME #ifdef HAS_BME
int16_t temperature = (int16_t)(value.temperature); // float -> int int16_t temperature = (int16_t)(value.temperature); // float -> int
uint16_t humidity = (uint16_t)(value.humidity); // 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 uint16_t iaq = (uint16_t)(value.iaq); // float -> int
buffer[cursor++] = highByte(temperature); buffer[cursor++] = highByte(temperature);
buffer[cursor++] = lowByte(temperature); buffer[cursor++] = lowByte(temperature);
buffer[cursor++] = highByte(value.pressure); buffer[cursor++] = highByte(pressure);
buffer[cursor++] = lowByte(value.pressure); buffer[cursor++] = lowByte(pressure);
buffer[cursor++] = highByte(humidity); buffer[cursor++] = highByte(humidity);
buffer[cursor++] = lowByte(humidity); buffer[cursor++] = lowByte(humidity);
buffer[cursor++] = highByte(value.iaq); buffer[cursor++] = highByte(iaq);
buffer[cursor++] = lowByte(value.iaq); buffer[cursor++] = lowByte(iaq);
#endif #endif
} }
@ -192,10 +193,10 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
void PayloadConvert::addBME(bmeStatus_t value) { void PayloadConvert::addBME(bmeStatus_t value) {
#ifdef HAS_BME #ifdef HAS_BME
writeTemperature(value.temperature); writeFloat(value.temperature);
writeUint16(value.pressure); writeUFloat(value.pressure);
writeHumidity(value.humidity); writeUFloat(value.humidity);
writeUint16(value.iaq); writeUFloat(value.iaq);
#endif #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::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); int16_t h = (int16_t)(humidity * 100);
intToBytes(cursor, h, 2); 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 * Uses a 16bit two's complement with two decimals, so the range is
* -327.68 to +327.67 degrees * -327.68 to +327.67 degrees
*/ */
void PayloadConvert::writeTemperature(float temperature) { void PayloadConvert::writeFloat(float temperature) {
int16_t t = (int16_t)(temperature * 100); int16_t t = (int16_t)(temperature * 100);
if (temperature < 0) { if (temperature < 0) {
t = ~-t; t = ~-t;
@ -375,7 +376,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
// 0.5% per bit => 0 .. 128 %C // 0.5% per bit => 0 .. 128 %C
uint8_t humidity = (uint8_t)(value.humidity * 2.0); uint8_t humidity = (uint8_t)(value.humidity * 2.0);
// 0.01 IAQ per bit => 0 .. 655,36 IAQ // 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) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL; 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++] = LPP_HUMIDITY; // 1 byte 0.5 % Unsigned
buffer[cursor++] = humidity; buffer[cursor++] = humidity;
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_GAS_CHANNEL; buffer[cursor++] = LPP_AIR_CHANNEL;
#endif #endif
buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed
buffer[cursor++] = highByte(iaq); buffer[cursor++] = highByte(iaq);