BME280 payload corrections
This commit is contained in:
parent
54dea2e505
commit
4da2260852
@ -66,8 +66,9 @@ private:
|
||||
void writeUint32(uint32_t i);
|
||||
void writeUint16(uint16_t i);
|
||||
void writeUint8(uint8_t i);
|
||||
void writeFloat(float humidity);
|
||||
void writeUFloat(float temperature);
|
||||
void writeFloat(float value);
|
||||
void writeUFloat(float value);
|
||||
void writePressure(float value);
|
||||
void writeVersion(char * version);
|
||||
void writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bool g,
|
||||
bool h);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
; ---> SELECT TARGET PLATFORM HERE! <---
|
||||
[platformio]
|
||||
;env_default = generic
|
||||
env_default = generic
|
||||
;env_default = ebox
|
||||
;env_default = eboxtube
|
||||
;env_default = heltec
|
||||
@ -15,7 +15,7 @@
|
||||
;env_default = ttgov2
|
||||
;env_default = ttgov21old
|
||||
;env_default = ttgov21new
|
||||
env_default = ttgobeam
|
||||
;env_default = ttgobeam
|
||||
;env_default = lopy
|
||||
;env_default = lopy4
|
||||
;env_default = fipy
|
||||
@ -29,13 +29,13 @@ 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.88
|
||||
release_version = 1.6.9
|
||||
; 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 = 3
|
||||
debug_level = 0
|
||||
; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA
|
||||
;upload_protocol = esptool
|
||||
upload_protocol = custom
|
||||
upload_protocol = esptool
|
||||
;upload_protocol = custom
|
||||
extra_scripts = pre:build.py
|
||||
keyfile = ota.conf
|
||||
platform_espressif32 = https://github.com/platformio/platform-espressif32.git#a7b1fe6
|
||||
|
@ -43,7 +43,7 @@ function Decoder(bytes, port) {
|
||||
|
||||
if (port === 7) {
|
||||
// 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;
|
||||
|
||||
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) {
|
||||
if (byte.length !== bitmap.BYTES) {
|
||||
throw new Error('Bitmap must have exactly 1 byte');
|
||||
@ -195,6 +205,7 @@ if (typeof module === 'object' && typeof module.exports !== 'undefined') {
|
||||
uptime: uptime,
|
||||
float: float,
|
||||
ufloat: ufloat,
|
||||
pressure: pressure,
|
||||
latLng: latLng,
|
||||
hdop: hdop,
|
||||
bitmap: bitmap,
|
||||
|
@ -194,7 +194,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) {
|
||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
writeFloat(value.temperature);
|
||||
writeUFloat(value.pressure);
|
||||
writePressure(value.pressure);
|
||||
writeUFloat(value.humidity);
|
||||
writeUFloat(value.iaq);
|
||||
#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::writeUFloat(float humidity) {
|
||||
int16_t h = (int16_t)(humidity * 100);
|
||||
void PayloadConvert::writeUFloat(float value) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -242,9 +247,9 @@ void PayloadConvert::writeUFloat(float humidity) {
|
||||
* Uses a 16bit two's complement with two decimals, so the range is
|
||||
* -327.68 to +327.67 degrees
|
||||
*/
|
||||
void PayloadConvert::writeFloat(float temperature) {
|
||||
int16_t t = (int16_t)(temperature * 100);
|
||||
if (temperature < 0) {
|
||||
void PayloadConvert::writeFloat(float value) {
|
||||
int16_t t = (int16_t)(value * 100);
|
||||
if (value < 0) {
|
||||
t = ~-t;
|
||||
t = t + 1;
|
||||
}
|
||||
@ -372,11 +377,10 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
// 0.1°C per bit => -3276,7 .. +3276,7 °C
|
||||
int16_t temperature = (int16_t)(value.temperature * 10.0);
|
||||
// 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
|
||||
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;
|
||||
int16_t iaq = (int16_t)(value.iaq);
|
||||
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
|
||||
@ -398,7 +402,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_AIR_CHANNEL;
|
||||
#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++] = lowByte(iaq);
|
||||
#endif // HAS_BME
|
||||
|
@ -7,9 +7,20 @@ void SendPayload(uint8_t port) {
|
||||
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]
|
||||
|
||||
SendBuffer.MessageSize = payload.getSize();
|
||||
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
|
||||
? port
|
||||
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
|
||||
switch (PAYLOAD_ENCODER) {
|
||||
case 1:
|
||||
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());
|
||||
|
||||
// enqueue message in device's send queues
|
||||
|
Loading…
Reference in New Issue
Block a user