BME 680 support: payload converters addes

This commit is contained in:
Klaus K Wilting 2018-11-17 21:39:49 +01:00
parent 2b96f6e0bf
commit ddd5764a8b
8 changed files with 72 additions and 23 deletions

View File

@ -6,7 +6,6 @@
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
extern Adafruit_BME680 bme; // Make bme instance globally availabe
extern bmeStatus_t
bme_status; // Make struct for storing gps data globally available

View File

@ -47,10 +47,10 @@ typedef struct {
} gpsStatus_t;
typedef struct {
uint16_t temperature; // Temperature * 100 in degrees Centigrade
float temperature; // Temperature in degrees Centigrade
uint16_t pressure; // Barometic pressure in hecto pascals
uint8_t humidity; // Relative humidity in percent
uint32_t gas_resistance; // Resistance in Ohms
float humidity; // Relative humidity in percent
uint16_t gas_resistance; // Resistance in MOhms
uint16_t altitude; // Altitude in meters
} bmeStatus_t;

View File

@ -10,19 +10,25 @@
#define LPP_BATT_CHANNEL 23
#define LPP_BUTTON_CHANNEL 24
#define LPP_ADR_CHANNEL 25
#define LPP_TEMP_CHANNEL 26
#define LPP_TEMPERATURE_CHANNEL 26
#define LPP_ALARM_CHANNEL 27
#define LPP_MSG_CHANNEL 28
#define LPP_HUMIDITY_CHANNEL 29
#define LPP_BAROMETER_CHANNEL 30
#define LPP_GAS_CHANNEL 31
#endif
// MyDevices CayenneLPP types
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed MSB
#define LPP_DIGITAL_INPUT 0 // 1 byte
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
#define LPP_PRESENCE 102 // 1 byte
#define LPP_HUMIDITY 104 // 1 byte, 0.5 % unsigned
#define LPP_BAROMETER 115 // 2 bytes, hPa unsigned MSB
class PayloadConvert {

View File

@ -32,7 +32,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
release_version = 1.6.63
; 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

View File

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

View File

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

View File

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

View File

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