BME 680 support: payload converters addes
This commit is contained in:
parent
2b96f6e0bf
commit
ddd5764a8b
@ -6,7 +6,6 @@
|
|||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
#include "Adafruit_BME680.h"
|
#include "Adafruit_BME680.h"
|
||||||
|
|
||||||
extern Adafruit_BME680 bme; // Make bme instance globally availabe
|
|
||||||
extern bmeStatus_t
|
extern bmeStatus_t
|
||||||
bme_status; // Make struct for storing gps data globally available
|
bme_status; // Make struct for storing gps data globally available
|
||||||
|
|
||||||
|
@ -47,10 +47,10 @@ typedef struct {
|
|||||||
} gpsStatus_t;
|
} gpsStatus_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t temperature; // Temperature * 100 in degrees Centigrade
|
float temperature; // Temperature in degrees Centigrade
|
||||||
uint16_t pressure; // Barometic pressure in hecto pascals
|
uint16_t pressure; // Barometic pressure in hecto pascals
|
||||||
uint8_t humidity; // Relative humidity in percent
|
float humidity; // Relative humidity in percent
|
||||||
uint32_t gas_resistance; // Resistance in Ohms
|
uint16_t gas_resistance; // Resistance in MOhms
|
||||||
uint16_t altitude; // Altitude in meters
|
uint16_t altitude; // Altitude in meters
|
||||||
} bmeStatus_t;
|
} bmeStatus_t;
|
||||||
|
|
||||||
|
@ -10,19 +10,25 @@
|
|||||||
#define LPP_BATT_CHANNEL 23
|
#define LPP_BATT_CHANNEL 23
|
||||||
#define LPP_BUTTON_CHANNEL 24
|
#define LPP_BUTTON_CHANNEL 24
|
||||||
#define LPP_ADR_CHANNEL 25
|
#define LPP_ADR_CHANNEL 25
|
||||||
#define LPP_TEMP_CHANNEL 26
|
#define LPP_TEMPERATURE_CHANNEL 26
|
||||||
#define LPP_ALARM_CHANNEL 27
|
#define LPP_ALARM_CHANNEL 27
|
||||||
#define LPP_MSG_CHANNEL 28
|
#define LPP_MSG_CHANNEL 28
|
||||||
|
#define LPP_HUMIDITY_CHANNEL 29
|
||||||
|
#define LPP_BAROMETER_CHANNEL 30
|
||||||
|
#define LPP_GAS_CHANNEL 31
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MyDevices CayenneLPP types
|
// MyDevices CayenneLPP types
|
||||||
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m
|
#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_INPUT 0 // 1 byte
|
||||||
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
|
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
|
||||||
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
|
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
|
||||||
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
|
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
|
||||||
#define LPP_PRESENCE 102 // 1 byte
|
#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 {
|
class PayloadConvert {
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
|
|||||||
release_version = 1.6.63
|
release_version = 1.6.63
|
||||||
; 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
|
||||||
|
@ -41,6 +41,11 @@ function Decoder(bytes, port) {
|
|||||||
return decode(bytes, [uint8, uint8], ['rssi', 'beacon']);
|
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) {
|
if (isNegative) {
|
||||||
t = -t;
|
t = -t;
|
||||||
}
|
}
|
||||||
return t / 1e2;
|
return +(t / 100).toFixed(1);
|
||||||
};
|
};
|
||||||
temperature.BYTES = 2;
|
temperature.BYTES = 2;
|
||||||
|
|
||||||
@ -142,7 +147,7 @@ var humidity = function (bytes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var h = bytesToInt(bytes);
|
var h = bytesToInt(bytes);
|
||||||
return h / 1e2;
|
return +(h / 100).toFixed(1);
|
||||||
};
|
};
|
||||||
humidity.BYTES = 2;
|
humidity.BYTES = 2;
|
||||||
|
|
||||||
|
@ -40,6 +40,15 @@ function Decoder(bytes, port) {
|
|||||||
decoded.rssi = bytes[i++];
|
decoded.rssi = bytes[i++];
|
||||||
decoded.beacon = 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;
|
return decoded;
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ bool bme_read(void) {
|
|||||||
bool ret = bme.performReading();
|
bool ret = bme.performReading();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
// read current BME data and buffer in global struct
|
// 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.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.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0);
|
||||||
bme_status.altitude =
|
bme_status.altitude =
|
||||||
(uint16_t)(bme.readAltitude(SEALEVELPRESSURE_HPA / 1000.0));
|
(uint16_t)(bme.readAltitude(SEALEVELPRESSURE_HPA / 1000.0));
|
||||||
|
@ -95,11 +95,12 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
|
|
||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
buffer[cursor++] = highByte(value.temperature);
|
buffer[cursor++] = highByte((int16_t)value.temperature);
|
||||||
buffer[cursor++] = lowByte(value.temperature);
|
buffer[cursor++] = lowByte((int16_t)value.temperature);
|
||||||
buffer[cursor++] = highByte(value.pressure);
|
buffer[cursor++] = highByte(value.pressure);
|
||||||
buffer[cursor++] = lowByte(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++] = highByte(value.gas_resistance);
|
||||||
buffer[cursor++] = lowByte(value.gas_resistance);
|
buffer[cursor++] = lowByte(value.gas_resistance);
|
||||||
buffer[cursor++] = highByte(value.altitude);
|
buffer[cursor++] = highByte(value.altitude);
|
||||||
@ -166,9 +167,9 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
|
|
||||||
void PayloadConvert::addBME(bmeStatus_t value) {
|
void PayloadConvert::addBME(bmeStatus_t value) {
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
writeUint16(value.temperature);
|
writeTemperature(value.temperature);
|
||||||
writeUint16(value.pressure);
|
writeUint16(value.pressure);
|
||||||
writeUint8(value.humidity);
|
writeHumidity(value.humidity);
|
||||||
writeUint16(value.gas_resistance);
|
writeUint16(value.gas_resistance);
|
||||||
writeUint16(value.altitude);
|
writeUint16(value.altitude);
|
||||||
#endif
|
#endif
|
||||||
@ -250,13 +251,13 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
|||||||
#if (PAYLOAD_ENCODER == 3)
|
#if (PAYLOAD_ENCODER == 3)
|
||||||
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
||||||
#endif
|
#endif
|
||||||
buffer[cursor++] = LPP_LUMINOSITY; // workaround, type meter not found?
|
buffer[cursor++] = LPP_TEMPERATURE;
|
||||||
buffer[cursor++] = highByte(value1);
|
buffer[cursor++] = highByte(value1);
|
||||||
buffer[cursor++] = lowByte(value1);
|
buffer[cursor++] = lowByte(value1);
|
||||||
#if (PAYLOAD_ENCODER == 3)
|
#if (PAYLOAD_ENCODER == 3)
|
||||||
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
||||||
#endif
|
#endif
|
||||||
buffer[cursor++] = LPP_LUMINOSITY; // workaround, type meter not found?
|
buffer[cursor++] = LPP_HUMIDITY;
|
||||||
buffer[cursor++] = highByte(value2);
|
buffer[cursor++] = highByte(value2);
|
||||||
buffer[cursor++] = lowByte(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++] = LPP_ANALOG_INPUT;
|
||||||
buffer[cursor++] = highByte(volt);
|
buffer[cursor++] = highByte(volt);
|
||||||
buffer[cursor++] = lowByte(volt);
|
buffer[cursor++] = lowByte(volt);
|
||||||
#endif
|
#endif // HAS_BATTERY_PROBE
|
||||||
|
|
||||||
#if (PAYLOAD_ENCODER == 3)
|
#if (PAYLOAD_ENCODER == 3)
|
||||||
buffer[cursor++] = LPP_TEMP_CHANNEL;
|
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
|
||||||
#endif
|
#endif
|
||||||
buffer[cursor++] = LPP_TEMPERATURE;
|
buffer[cursor++] = LPP_TEMPERATURE;
|
||||||
buffer[cursor++] = highByte(temp);
|
buffer[cursor++] = highByte(temp);
|
||||||
@ -316,11 +318,39 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
|
|||||||
buffer[cursor++] = (byte)((lat & 0x0000FF));
|
buffer[cursor++] = (byte)((lat & 0x0000FF));
|
||||||
buffer[cursor++] = (byte)((lon & 0xFF0000) >> 16);
|
buffer[cursor++] = (byte)((lon & 0xFF0000) >> 16);
|
||||||
buffer[cursor++] = (byte)((lon & 0x00FF00) >> 8);
|
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 & 0xFF0000) >> 16);
|
||||||
buffer[cursor++] = (byte)((alt & 0x00FF00) >> 8);
|
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
|
#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) {
|
void PayloadConvert::addButton(uint8_t value) {
|
||||||
@ -330,7 +360,7 @@ void PayloadConvert::addButton(uint8_t value) {
|
|||||||
#endif
|
#endif
|
||||||
buffer[cursor++] = LPP_DIGITAL_INPUT;
|
buffer[cursor++] = LPP_DIGITAL_INPUT;
|
||||||
buffer[cursor++] = value;
|
buffer[cursor++] = value;
|
||||||
#endif
|
#endif // HAS_BUTTON
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user