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_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);

View File

@ -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 =

View File

@ -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,

View File

@ -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;
@ -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);