BME280 payload corrections
This commit is contained in:
1 parent
54dea2e505
commit
4da2260852
5 files changed
+49
-22
No files matched your search
@@ -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,
|
||||
|
||||
+14
-10
@@ -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
|
||||
|
||||
+14
-3
@@ -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
|
||||
|
||||
Reference in new issue
Block a user