BME 680 support: payload converters addes
This commit is contained in:
1 parent
2b96f6e0bf
commit
ddd5764a8b
8 files changed
+72
-23
No files matched your search
@@ -41,6 +41,11 @@ function Decoder(bytes, port) {
|
||||
return decode(bytes, [uint8, uint8], ['rssi', 'beacon']);
|
||||
}
|
||||
|
||||
if (port === 7) {
|
||||
// BME680 sensor data
|
||||
return decode(bytes, [temperature, uint16, humidity, uint16, uint16], ['temperature', 'pressure', 'humidity', 'gas', 'altitude']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +137,7 @@ var temperature = function (bytes) {
|
||||
if (isNegative) {
|
||||
t = -t;
|
||||
}
|
||||
return t / 1e2;
|
||||
return +(t / 100).toFixed(1);
|
||||
};
|
||||
temperature.BYTES = 2;
|
||||
|
||||
@@ -142,7 +147,7 @@ var humidity = function (bytes) {
|
||||
}
|
||||
|
||||
var h = bytesToInt(bytes);
|
||||
return h / 1e2;
|
||||
return +(h / 100).toFixed(1);
|
||||
};
|
||||
humidity.BYTES = 2;
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ function Decoder(bytes, port) {
|
||||
decoded.rssi = bytes[i++];
|
||||
decoded.beacon = bytes[i++];
|
||||
}
|
||||
|
||||
if (port === 7) {
|
||||
var i = 0;
|
||||
decoded.temperature = ((bytes[i++] << 8) | bytes[i++]);
|
||||
decoded.pressure = ((bytes[i++] << 8) | bytes[i++]);
|
||||
decoded.humidity = ((bytes[i++] << 8) | bytes[i++]);
|
||||
decoded.gas = ((bytes[i++] << 8) | bytes[i++]);
|
||||
decoded.altitude = ((bytes[i++] << 8) | bytes[i++]);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@ bool bme_read(void) {
|
||||
bool ret = bme.performReading();
|
||||
if (ret) {
|
||||
// read current BME data and buffer in global struct
|
||||
bme_status.temperature = (uint16_t)(bme.temperature * 100.0);
|
||||
bme_status.temperature = bme.temperature;
|
||||
bme_status.pressure = (uint16_t)(bme.pressure / 100.0);
|
||||
bme_status.humidity = (uint8_t)bme.humidity;
|
||||
bme_status.humidity = bme.humidity;
|
||||
bme_status.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0);
|
||||
bme_status.altitude =
|
||||
(uint16_t)(bme.readAltitude(SEALEVELPRESSURE_HPA / 1000.0));
|
||||
|
||||
+42
-12
@@ -95,11 +95,12 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
|
||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
buffer[cursor++] = highByte(value.temperature);
|
||||
buffer[cursor++] = lowByte(value.temperature);
|
||||
buffer[cursor++] = highByte((int16_t)value.temperature);
|
||||
buffer[cursor++] = lowByte((int16_t)value.temperature);
|
||||
buffer[cursor++] = highByte(value.pressure);
|
||||
buffer[cursor++] = lowByte(value.pressure);
|
||||
buffer[cursor++] = (byte)(value.humidity);
|
||||
buffer[cursor++] = highByte((uint16_t)value.humidity);
|
||||
buffer[cursor++] = lowByte((uint16_t)value.humidity);
|
||||
buffer[cursor++] = highByte(value.gas_resistance);
|
||||
buffer[cursor++] = lowByte(value.gas_resistance);
|
||||
buffer[cursor++] = highByte(value.altitude);
|
||||
@@ -166,9 +167,9 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
|
||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
writeUint16(value.temperature);
|
||||
writeTemperature(value.temperature);
|
||||
writeUint16(value.pressure);
|
||||
writeUint8(value.humidity);
|
||||
writeHumidity(value.humidity);
|
||||
writeUint16(value.gas_resistance);
|
||||
writeUint16(value.altitude);
|
||||
#endif
|
||||
@@ -250,13 +251,13 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_LUMINOSITY; // workaround, type meter not found?
|
||||
buffer[cursor++] = LPP_TEMPERATURE;
|
||||
buffer[cursor++] = highByte(value1);
|
||||
buffer[cursor++] = lowByte(value1);
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_LUMINOSITY; // workaround, type meter not found?
|
||||
buffer[cursor++] = LPP_HUMIDITY;
|
||||
buffer[cursor++] = highByte(value2);
|
||||
buffer[cursor++] = lowByte(value2);
|
||||
}
|
||||
@@ -293,9 +294,10 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
|
||||
buffer[cursor++] = LPP_ANALOG_INPUT;
|
||||
buffer[cursor++] = highByte(volt);
|
||||
buffer[cursor++] = lowByte(volt);
|
||||
#endif
|
||||
#endif // HAS_BATTERY_PROBE
|
||||
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_TEMP_CHANNEL;
|
||||
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_TEMPERATURE;
|
||||
buffer[cursor++] = highByte(temp);
|
||||
@@ -316,11 +318,39 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
||||
buffer[cursor++] = (byte)((lat & 0x0000FF));
|
||||
buffer[cursor++] = (byte)((lon & 0xFF0000) >> 16);
|
||||
buffer[cursor++] = (byte)((lon & 0x00FF00) >> 8);
|
||||
buffer[cursor++] = (byte)((lon & 0x0000FF));
|
||||
buffer[cursor++] = (byte)(lon & 0x0000FF);
|
||||
buffer[cursor++] = (byte)((alt & 0xFF0000) >> 16);
|
||||
buffer[cursor++] = (byte)((alt & 0x00FF00) >> 8);
|
||||
buffer[cursor++] = (byte)((alt & 0x0000FF));
|
||||
buffer[cursor++] = (byte)(alt & 0x0000FF);
|
||||
#endif // HAS_GPS
|
||||
}
|
||||
|
||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||
#ifdef HAS_BME
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_TEMPERATURE;
|
||||
buffer[cursor++] = highByte((int16_t)value.temperature);
|
||||
buffer[cursor++] = lowByte((int16_t)value.temperature);
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_BAROMETER_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_BAROMETER;
|
||||
buffer[cursor++] = highByte(value.pressure);
|
||||
buffer[cursor++] = lowByte(value.pressure);
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_HUMIDITY_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_HUMIDITY;
|
||||
buffer[cursor++] = (byte)value.humidity;
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_GAS_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] = LPP_ANALOG_INPUT;
|
||||
buffer[cursor++] = highByte(value.gas_resistance);
|
||||
buffer[cursor++] = lowByte(value.gas_resistance);
|
||||
#endif // HAS_BME
|
||||
}
|
||||
|
||||
void PayloadConvert::addButton(uint8_t value) {
|
||||
@@ -330,7 +360,7 @@ void PayloadConvert::addButton(uint8_t value) {
|
||||
#endif
|
||||
buffer[cursor++] = LPP_DIGITAL_INPUT;
|
||||
buffer[cursor++] = value;
|
||||
#endif
|
||||
#endif // HAS_BUTTON
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user