BME280 payload corrections
This commit is contained in:
parent
54dea2e505
commit
4da2260852
@ -66,8 +66,9 @@ 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 writeFloat(float humidity);
|
void writeFloat(float value);
|
||||||
void writeUFloat(float temperature);
|
void writeUFloat(float value);
|
||||||
|
void writePressure(float value);
|
||||||
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);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
; ---> SELECT TARGET PLATFORM HERE! <---
|
; ---> SELECT TARGET PLATFORM HERE! <---
|
||||||
[platformio]
|
[platformio]
|
||||||
;env_default = generic
|
env_default = generic
|
||||||
;env_default = ebox
|
;env_default = ebox
|
||||||
;env_default = eboxtube
|
;env_default = eboxtube
|
||||||
;env_default = heltec
|
;env_default = heltec
|
||||||
@ -15,7 +15,7 @@
|
|||||||
;env_default = ttgov2
|
;env_default = ttgov2
|
||||||
;env_default = ttgov21old
|
;env_default = ttgov21old
|
||||||
;env_default = ttgov21new
|
;env_default = ttgov21new
|
||||||
env_default = ttgobeam
|
;env_default = ttgobeam
|
||||||
;env_default = lopy
|
;env_default = lopy
|
||||||
;env_default = lopy4
|
;env_default = lopy4
|
||||||
;env_default = fipy
|
;env_default = fipy
|
||||||
@ -29,13 +29,13 @@ 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.88
|
release_version = 1.6.9
|
||||||
; 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 = 3
|
debug_level = 0
|
||||||
; 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 = https://github.com/platformio/platform-espressif32.git#a7b1fe6
|
platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6
|
||||||
|
@ -43,7 +43,7 @@ function Decoder(bytes, port) {
|
|||||||
|
|
||||||
if (port === 7) {
|
if (port === 7) {
|
||||||
// BME680 sensor data
|
// BME680 sensor data
|
||||||
return decode(bytes, [float, ufloat, ufloat, ufloat], ['temperature', 'pressure', 'humidity', 'air']);
|
return decode(bytes, [float, uint16, ufloat, ufloat], ['temperature', 'pressure', 'humidity', 'air']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -151,6 +151,16 @@ var ufloat = function (bytes) {
|
|||||||
};
|
};
|
||||||
ufloat.BYTES = 2;
|
ufloat.BYTES = 2;
|
||||||
|
|
||||||
|
var pressure = function (bytes) {
|
||||||
|
if (bytes.length !== pressure.BYTES) {
|
||||||
|
throw new Error('Pressure must have exactly 2 bytes');
|
||||||
|
}
|
||||||
|
|
||||||
|
var h = bytesToInt(bytes);
|
||||||
|
return +(h / 10).toFixed(1);
|
||||||
|
};
|
||||||
|
pressure.BYTES = 2;
|
||||||
|
|
||||||
var bitmap = function (byte) {
|
var bitmap = function (byte) {
|
||||||
if (byte.length !== bitmap.BYTES) {
|
if (byte.length !== bitmap.BYTES) {
|
||||||
throw new Error('Bitmap must have exactly 1 byte');
|
throw new Error('Bitmap must have exactly 1 byte');
|
||||||
@ -195,6 +205,7 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
|||||||
uptime: uptime,
|
uptime: uptime,
|
||||||
float: float,
|
float: float,
|
||||||
ufloat: ufloat,
|
ufloat: ufloat,
|
||||||
|
pressure: pressure,
|
||||||
latLng: latLng,
|
latLng: latLng,
|
||||||
hdop: hdop,
|
hdop: hdop,
|
||||||
bitmap: bitmap,
|
bitmap: bitmap,
|
||||||
|
@ -194,7 +194,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
|
|||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
writeFloat(value.temperature);
|
writeFloat(value.temperature);
|
||||||
writeUFloat(value.pressure);
|
writePressure(value.pressure);
|
||||||
writeUFloat(value.humidity);
|
writeUFloat(value.humidity);
|
||||||
writeUFloat(value.iaq);
|
writeUFloat(value.iaq);
|
||||||
#endif
|
#endif
|
||||||
@ -233,8 +233,13 @@ 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::writeUFloat(float humidity) {
|
void PayloadConvert::writeUFloat(float value) {
|
||||||
int16_t h = (int16_t)(humidity * 100);
|
int16_t h = (int16_t)(value * 100);
|
||||||
|
intToBytes(cursor, h, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PayloadConvert::writePressure(float value) {
|
||||||
|
int16_t h = (int16_t)(value);
|
||||||
intToBytes(cursor, h, 2);
|
intToBytes(cursor, h, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,9 +247,9 @@ void PayloadConvert::writeUFloat(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::writeFloat(float temperature) {
|
void PayloadConvert::writeFloat(float value) {
|
||||||
int16_t t = (int16_t)(temperature * 100);
|
int16_t t = (int16_t)(value * 100);
|
||||||
if (temperature < 0) {
|
if (value < 0) {
|
||||||
t = ~-t;
|
t = ~-t;
|
||||||
t = t + 1;
|
t = t + 1;
|
||||||
}
|
}
|
||||||
@ -372,11 +377,10 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
|||||||
// 0.1°C per bit => -3276,7 .. +3276,7 °C
|
// 0.1°C per bit => -3276,7 .. +3276,7 °C
|
||||||
int16_t temperature = (int16_t)(value.temperature * 10.0);
|
int16_t temperature = (int16_t)(value.temperature * 10.0);
|
||||||
// 0.1 hPa per bit => 0 .. 6553,6 hPa
|
// 0.1 hPa per bit => 0 .. 6553,6 hPa
|
||||||
uint16_t pressure = value.pressure * 10;
|
uint16_t pressure = (uint16_t)(value.pressure * 10);
|
||||||
// 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
|
int16_t iaq = (int16_t)(value.iaq);
|
||||||
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;
|
||||||
@ -398,7 +402,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
|||||||
#if (PAYLOAD_ENCODER == 3)
|
#if (PAYLOAD_ENCODER == 3)
|
||||||
buffer[cursor++] = LPP_AIR_CHANNEL;
|
buffer[cursor++] = LPP_AIR_CHANNEL;
|
||||||
#endif
|
#endif
|
||||||
buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed
|
buffer[cursor++] = LPP_LUMINOSITY; // 2 bytes, 1.0 unsigned
|
||||||
buffer[cursor++] = highByte(iaq);
|
buffer[cursor++] = highByte(iaq);
|
||||||
buffer[cursor++] = lowByte(iaq);
|
buffer[cursor++] = lowByte(iaq);
|
||||||
#endif // HAS_BME
|
#endif // HAS_BME
|
||||||
|
@ -7,9 +7,20 @@ void SendPayload(uint8_t port) {
|
|||||||
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]
|
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]
|
||||||
|
|
||||||
SendBuffer.MessageSize = payload.getSize();
|
SendBuffer.MessageSize = payload.getSize();
|
||||||
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
|
switch (PAYLOAD_ENCODER) {
|
||||||
? port
|
case 1:
|
||||||
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
|
case 2:
|
||||||
|
SendBuffer.MessagePort = port;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
SendBuffer.MessagePort = LPP1PORT;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
SendBuffer.MessagePort = LPP2PORT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SendBuffer.MessagePort = port;
|
||||||
|
}
|
||||||
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
|
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
|
||||||
|
|
||||||
// enqueue message in device's send queues
|
// enqueue message in device's send queues
|
||||||
|
Loading…
Reference in New Issue
Block a user