payload decoder reworked for BME680 support

This commit is contained in:
Klaus K Wilting 2018-11-18 15:50:57 +01:00
parent 02b3f1e2d4
commit 06dcad6484
19 changed files with 105 additions and 92 deletions

View File

@ -204,7 +204,7 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
bytes 1-2: Temperature [°C] bytes 1-2: Temperature [°C]
bytes 3-4: Pressure [hPa] bytes 3-4: Pressure [hPa]
bytes 5-6: Humidity [%] bytes 5-6: Humidity [%]
bytes 7-8: Gas resistance [MOhm] bytes 7-8: Gas resistance [kOhm]
bytes 9-10: Altitude [meter] bytes 9-10: Altitude [meter]
# Remote control # Remote control

View File

@ -3,7 +3,7 @@
#define DISPLAY_IRQ 0x01 #define DISPLAY_IRQ 0x01
#define BUTTON_IRQ 0x02 #define BUTTON_IRQ 0x02
#define SENDPAYLOAD_IRQ 0x04 #define SENDCOUNTER_IRQ 0x04
#define CYCLIC_IRQ 0x08 #define CYCLIC_IRQ 0x08
#include "globals.h" #include "globals.h"

View File

@ -5,8 +5,8 @@
#include "lorawan.h" #include "lorawan.h"
#include "cyclic.h" #include "cyclic.h"
void SendData(uint8_t port); void SendPayload(uint8_t port);
void sendPayload(void); void sendCounter(void);
void checkSendQueues(void); void checkSendQueues(void);
void flushQueues(); void flushQueues();

View File

@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.6.68 release_version = 1.6.8
; 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 = 0 debug_level = 0
@ -41,10 +41,8 @@ keyfile = ota.conf
platform_espressif32 = espressif32@1.5.0 platform_espressif32 = espressif32@1.5.0
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
monitor_speed = 115200 monitor_speed = 115200
lib_deps_all = lib_deps_basic =
ArduinoJson@^5.13.1 ArduinoJson@^5.13.1
Adafruit Unified Sensor@^1.0.2
Adafruit BME680 Library@^1.0.7
Time@>=1.5 Time@>=1.5
lib_deps_lora = lib_deps_lora =
; MCCI LoRaWAN LMIC library@^2.2.2 ; MCCI LoRaWAN LMIC library@^2.2.2
@ -54,6 +52,16 @@ lib_deps_rgbled =
SmartLeds@>=1.1.3 SmartLeds@>=1.1.3
lib_deps_gps = lib_deps_gps =
TinyGPSPlus@>=1.0.2 TinyGPSPlus@>=1.0.2
lib_deps_sensors =
Adafruit Unified Sensor@^1.0.2
Adafruit BME680 Library@^1.0.7
lib_deps_all =
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
${common.lib_deps_sensors}
build_flags = build_flags =
-include src/hal/${PIOENV}.h -include src/hal/${PIOENV}.h
-include src/paxcounter.conf -include src/paxcounter.conf
@ -72,7 +80,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200 upload_speed = 115200
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
@ -87,8 +95,9 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200 upload_speed = 115200
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled}
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
upload_protocol = ${common.upload_protocol} upload_protocol = ${common.upload_protocol}
@ -102,7 +111,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -118,7 +127,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -134,7 +143,7 @@ board = ttgo-lora32-v1
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200 upload_speed = 115200
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -150,7 +159,7 @@ board = ttgo-lora32-v1
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -166,7 +175,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -182,7 +191,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_display} ${common.lib_deps_display}
build_flags = build_flags =
@ -198,7 +207,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_gps} ${common.lib_deps_gps}
build_flags = build_flags =
@ -215,7 +224,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
build_flags = build_flags =
@ -231,7 +240,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
${common.lib_deps_gps} ${common.lib_deps_gps}
@ -248,7 +257,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
${common.lib_deps_gps} ${common.lib_deps_gps}
@ -266,7 +275,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
build_flags = build_flags =
@ -282,7 +291,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
build_flags = build_flags =
@ -298,7 +307,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps =
${common.lib_deps_all} ${common.lib_deps_basic}
${common.lib_deps_rgbled} ${common.lib_deps_rgbled}
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
@ -312,13 +321,8 @@ framework = arduino
board = featheresp32 board = featheresp32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps = ${common.lib_deps_all}
${common.lib_deps_all} build_flags = ${common.build_flags}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_display}
build_flags =
${common.build_flags}
upload_protocol = ${common.upload_protocol} upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
@ -329,14 +333,8 @@ framework = arduino
board = heltec_wifi_lora_32 board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions} board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600 upload_speed = 921600
lib_deps = lib_deps = ${common.lib_deps_all}
${common.lib_deps_all} build_flags = ${common.build_flags}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
${common.lib_deps_display}
build_flags =
${common.build_flags}
upload_protocol = ${common.upload_protocol} upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts} extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}

View File

@ -43,7 +43,7 @@ function Decoder(bytes, port) {
if (port === 7) { if (port === 7) {
// BME680 sensor data // BME680 sensor data
return decode(bytes, [temperature, uint16, humidity, uint16, uint16], ['temperature', 'pressure', 'humidity', 'gas', 'altitude']); return decode(bytes, [temperature, uint16, humidity, uint16, temperature], ['temperature', 'pressure', 'humidity', 'air', 'altitude']);
} }
} }

View File

@ -46,7 +46,7 @@ function Decoder(bytes, port) {
decoded.temperature = ((bytes[i++] << 8) | bytes[i++]); decoded.temperature = ((bytes[i++] << 8) | bytes[i++]);
decoded.pressure = ((bytes[i++] << 8) | bytes[i++]); decoded.pressure = ((bytes[i++] << 8) | bytes[i++]);
decoded.humidity = ((bytes[i++] << 8) | bytes[i++]); decoded.humidity = ((bytes[i++] << 8) | bytes[i++]);
decoded.gas = ((bytes[i++] << 8) | bytes[i++]); decoded.air = ((bytes[i++] << 8) | bytes[i++]);
decoded.altitude = ((bytes[i++] << 8) | bytes[i++]); decoded.altitude = ((bytes[i++] << 8) | bytes[i++]);
} }

View File

@ -14,7 +14,7 @@ bmeStatus_t bme_status;
void bme_init(void) { void bme_init(void) {
// initialize BME680 sensor using default i2c address 0x77 // initialize BME680 sensor using default i2c address 0x77
if (bme.begin()) { if (bme.begin(HAS_BME)) {
// Set up oversampling and filter initialization // Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X); bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X); bme.setHumidityOversampling(BME680_OS_2X);
@ -31,11 +31,10 @@ bool bme_read(void) {
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 = bme.temperature; bme_status.temperature = bme.temperature;
bme_status.pressure = (uint16_t)(bme.pressure / 100.0); bme_status.pressure = (uint16_t)(bme.pressure / 100.0); // convert Pa -> hPa
bme_status.humidity = 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); // convert Ohm -> kOhm
bme_status.altitude = bme_status.altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
(uint16_t)(bme.readAltitude(SEALEVELPRESSURE_HPA / 1000.0));
ESP_LOGI(TAG, "BME680 sensor data read success"); ESP_LOGI(TAG, "BME680 sensor data read success");
} else { } else {
ESP_LOGI(TAG, "BME680 sensor read error"); ESP_LOGI(TAG, "BME680 sensor read error");

View File

@ -10,6 +10,6 @@ void readButton() {
ESP_LOGI(TAG, "Button pressed"); ESP_LOGI(TAG, "Button pressed");
payload.reset(); payload.reset();
payload.addButton(0x01); payload.addButton(0x01);
SendData(BUTTONPORT); SendPayload(BUTTONPORT);
} }
#endif #endif

View File

@ -23,10 +23,10 @@ void doHousekeeping() {
spi_housekeeping(); spi_housekeeping();
lora_housekeeping(); lora_housekeeping();
// time sync once per TIME_SYNC_INTERVAL_MIN // time sync once per TIME_SYNC_INTERVAL
#ifdef TIME_SYNC #ifdef TIME_SYNC_INTERVAL
if (millis() >= nextTimeSync) { if (millis() >= nextTimeSync) {
nextTimeSync = millis() + TIME_SYNC_INTERVAL_MIN * nextTimeSync = millis() + TIME_SYNC_INTERVAL *
60000; // set up next time sync period 60000; // set up next time sync period
do_timesync(); do_timesync();
} }
@ -63,7 +63,7 @@ void doHousekeeping() {
"Memory full, counter cleared (heap low water mark = %d Bytes / " "Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)", "free heap = %d bytes)",
esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
SendData(COUNTERPORT); // send data before clearing counters SendPayload(COUNTERPORT); // send data before clearing counters
reset_counters(); // clear macs container and reset all counters reset_counters(); // clear macs container and reset all counters
get_salt(); // get new salt for salting hashes get_salt(); // get new salt for salting hashes
@ -90,7 +90,7 @@ void reset_counters() {
} }
void do_timesync() { void do_timesync() {
#ifdef TIME_SYNC #ifdef TIME_SYNC_INTERVAL
// sync time & date if we have valid gps time // sync time & date if we have valid gps time
#ifdef HAS_GPS #ifdef HAS_GPS
if (gps.time.isValid()) { if (gps.time.isValid()) {
@ -106,7 +106,7 @@ void do_timesync() {
// Schedule a network time request at the next possible time // Schedule a network time request at the next possible time
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
ESP_LOGI(TAG, "Network time request scheduled"); ESP_LOGI(TAG, "Network time request scheduled");
#endif // TIME_SYNC #endif // TIME_SYNC_INTERVAL
} // do_timesync() } // do_timesync()
#ifndef VERBOSE #ifndef VERBOSE

View File

@ -13,7 +13,7 @@
#define SPI_SCLK GPIO_NUM_18 #define SPI_SCLK GPIO_NUM_18
#define SPI_CS GPIO_NUM_5 #define SPI_CS GPIO_NUM_5
#define HAS_BME 1 // BME680 sensor on I2C bus (SDA=4/SCL=15); comment out if not present #define HAS_BME 0x77 // BME680 sensor on I2C bus (SDA=4/SCL=15); comment out if not present
#define CFG_sx1276_radio 1 // select LoRa chip #define CFG_sx1276_radio 1 // select LoRa chip
//#define CFG_sx1272_radio 1 // select LoRa chip //#define CFG_sx1272_radio 1 // select LoRa chip

View File

@ -3,7 +3,7 @@
#include <stdint.h> #include <stdint.h>
//#define HAS_BME 1 // BME680 sensor on I2C bus (SDI=21/SCL=22); comment out if not present //#define HAS_BME 0x77 // BME680 sensor on I2C bus (SDI=21/SCL=22); comment out if not present
// Hardware related definitions for Heltec LoRa-32 Board // Hardware related definitions for Heltec LoRa-32 Board
#define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_LORA 1 // comment out if device shall not send data via LoRa

View File

@ -10,6 +10,8 @@
// disable brownout detection (avoid unexpected reset on some boards) // disable brownout detection (avoid unexpected reset on some boards)
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
#define HAS_BME 0x76 // BME680 sensor on I2C bus; comment out if not present
#define HAS_LED 13 // ESP32 GPIO12 (pin22) On Board LED #define HAS_LED 13 // ESP32 GPIO12 (pin22) On Board LED
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW #define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
//#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED //#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED

View File

@ -8,7 +8,7 @@
// This settings are for boards labeled v1.6 on pcb, NOT for v1.5 or older // This settings are for boards labeled v1.6 on pcb, NOT for v1.5 or older
*/ */
//#define HAS_BME 1 // BME680 sensor on I2C bus (SDI=21/SCL=22); comment out if not present #define HAS_BME 0x77 // BME680 sensor on I2C bus (SDI=21/SCL=22); comment out if not present
#define HAS_LORA 1 // comment out if device shall not send data via LoRa #define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define CFG_sx1276_radio 1 // HPD13A LoRa SoC

View File

@ -35,8 +35,8 @@ void irqHandler(void *pvParameters) {
doHousekeeping(); doHousekeeping();
// is time to send the payload? // is time to send the payload?
if (InterruptStatus & SENDPAYLOAD_IRQ) if (InterruptStatus & SENDCOUNTER_IRQ)
sendPayload(); sendCounter();
} }
vTaskDelete(NULL); // shoud never be reached vTaskDelete(NULL); // shoud never be reached
} }
@ -55,7 +55,7 @@ void IRAM_ATTR homeCycleIRQ() {
} }
void IRAM_ATTR SendCycleIRQ() { void IRAM_ATTR SendCycleIRQ() {
xTaskNotifyFromISR(irqHandlerTask, SENDPAYLOAD_IRQ, eSetBits, NULL); xTaskNotifyFromISR(irqHandlerTask, SENDCOUNTER_IRQ, eSetBits, NULL);
portYIELD_FROM_ISR(); portYIELD_FROM_ISR();
} }

View File

@ -107,7 +107,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
#endif #endif
payload.reset(); payload.reset();
payload.addAlarm(rssi, beaconID); payload.addAlarm(rssi, beaconID);
SendData(BEACONPORT); SendPayload(BEACONPORT);
} }
}; };

View File

@ -11,7 +11,7 @@
// Payload send cycle and encoding // Payload send cycle and encoding
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec. #define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
#define PAYLOAD_ENCODER 3 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed #define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
// Set this to include BLE counting and vendor filter functions // Set this to include BLE counting and vendor filter functions
#define VENDORFILTER 1 // comment out if you want to count things, not people #define VENDORFILTER 1 // comment out if you want to count things, not people
@ -74,8 +74,7 @@
#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] #define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds]
// setting for syncing time of node // setting for syncing time of node
#define TIME_SYNC 1 // comment out if no time sync of node necessary //#define TIME_SYNC_INTERVAL 60 // sync time each ... minutes [default = 60], comment out means off
#define TIME_SYNC_INTERVAL_MIN 60 // sync time each ... minutes [default = 60]
// LMIC settings // LMIC settings
// moved to src/lmic_config.h // moved to src/lmic_config.h

View File

@ -95,16 +95,19 @@ 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((int16_t)value.temperature); int16_t temperature = (int16_t)(value.temperature); // float -> int
buffer[cursor++] = lowByte((int16_t)value.temperature); uint16_t humidity = (uint16_t)(value.humidity); // float -> int
int16_t altitude = (int16_t)(value.altitude); // float -> int
buffer[cursor++] = highByte(temperature);
buffer[cursor++] = lowByte(temperature);
buffer[cursor++] = highByte(value.pressure); buffer[cursor++] = highByte(value.pressure);
buffer[cursor++] = lowByte(value.pressure); buffer[cursor++] = lowByte(value.pressure);
buffer[cursor++] = highByte((uint16_t)value.humidity); buffer[cursor++] = highByte(humidity);
buffer[cursor++] = lowByte((uint16_t)value.humidity); buffer[cursor++] = lowByte(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(altitude);
buffer[cursor++] = lowByte(value.altitude); buffer[cursor++] = lowByte(altitude);
#endif #endif
} }
@ -171,7 +174,7 @@ void PayloadConvert::addBME(bmeStatus_t value) {
writeUint16(value.pressure); writeUint16(value.pressure);
writeHumidity(value.humidity); writeHumidity(value.humidity);
writeUint16(value.gas_resistance); writeUint16(value.gas_resistance);
writeUint16(value.altitude); writeTemperature(value.altitude);
#endif #endif
} }
@ -331,29 +334,40 @@ void PayloadConvert::addGPS(gpsStatus_t value) {
void PayloadConvert::addBME(bmeStatus_t value) { void PayloadConvert::addBME(bmeStatus_t value) {
#ifdef HAS_BME #ifdef HAS_BME
// data value conversions to meet cayenne data type definition
// 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;
// 0.5% per bit => 0 .. 128 %C
uint8_t humidity = (uint8_t)(value.humidity * 2.0);
// 0.01 Ohm per bit => 0 .. 655,36 Ohm
uint16_t gas = value.gas_resistance * 100;
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_TEMPERATURE_CHANNEL; buffer[cursor++] = LPP_TEMPERATURE_CHANNEL;
#endif #endif
buffer[cursor++] = LPP_TEMPERATURE; buffer[cursor++] = LPP_TEMPERATURE; // 2 bytes 0.1 °C Signed MSB
buffer[cursor++] = highByte((int16_t)value.temperature); buffer[cursor++] = highByte(temperature);
buffer[cursor++] = lowByte((int16_t)value.temperature); buffer[cursor++] = lowByte(temperature);
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_BAROMETER_CHANNEL; buffer[cursor++] = LPP_BAROMETER_CHANNEL;
#endif #endif
buffer[cursor++] = LPP_BAROMETER; buffer[cursor++] = LPP_BAROMETER; // 2 bytes 0.1 hPa Unsigned MSB
buffer[cursor++] = highByte(value.pressure); buffer[cursor++] = highByte(pressure);
buffer[cursor++] = lowByte(value.pressure); buffer[cursor++] = lowByte(pressure);
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_HUMIDITY_CHANNEL; buffer[cursor++] = LPP_HUMIDITY_CHANNEL;
#endif #endif
buffer[cursor++] = LPP_HUMIDITY; buffer[cursor++] = LPP_HUMIDITY; // 1 byte 0.5 % Unsigned
buffer[cursor++] = (byte)value.humidity; buffer[cursor++] = humidity;
#if (PAYLOAD_ENCODER == 3) #if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_GAS_CHANNEL; buffer[cursor++] = LPP_GAS_CHANNEL;
#endif #endif
buffer[cursor++] = LPP_ANALOG_INPUT; buffer[cursor++] = LPP_ANALOG_INPUT; // 2 bytes 0.01 Signed
buffer[cursor++] = highByte(value.gas_resistance); buffer[cursor++] = highByte(gas);
buffer[cursor++] = lowByte(value.gas_resistance); buffer[cursor++] = lowByte(gas);
#endif // HAS_BME #endif // HAS_BME
} }

View File

@ -211,7 +211,7 @@ void get_config(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get device configuration"); ESP_LOGI(TAG, "Remote command: get device configuration");
payload.reset(); payload.reset();
payload.addConfig(cfg); payload.addConfig(cfg);
SendData(CONFIGPORT); SendPayload(CONFIGPORT);
}; };
void get_status(uint8_t val[]) { void get_status(uint8_t val[]) {
@ -225,7 +225,7 @@ void get_status(uint8_t val[]) {
payload.addStatus(voltage, uptime() / 1000, temperatureRead(), payload.addStatus(voltage, uptime() / 1000, temperatureRead(),
ESP.getFreeHeap(), rtc_get_reset_reason(0), ESP.getFreeHeap(), rtc_get_reset_reason(0),
rtc_get_reset_reason(1)); rtc_get_reset_reason(1));
SendData(STATUSPORT); SendPayload(STATUSPORT);
}; };
void get_gps(uint8_t val[]) { void get_gps(uint8_t val[]) {
@ -234,7 +234,7 @@ void get_gps(uint8_t val[]) {
gps_read(); gps_read();
payload.reset(); payload.reset();
payload.addGPS(gps_status); payload.addGPS(gps_status);
SendData(GPSPORT); SendPayload(GPSPORT)
#else #else
ESP_LOGW(TAG, "GPS function not supported"); ESP_LOGW(TAG, "GPS function not supported");
#endif #endif
@ -245,7 +245,7 @@ void get_bme(uint8_t val[]) {
#ifdef HAS_BME #ifdef HAS_BME
payload.reset(); payload.reset();
payload.addBME(bme_status); payload.addBME(bme_status);
SendData(BMEPORT); SendPayload(BMEPORT);
#else #else
ESP_LOGW(TAG, "BME680 sensor not supported"); ESP_LOGW(TAG, "BME680 sensor not supported");
#endif #endif

View File

@ -2,22 +2,24 @@
#include "senddata.h" #include "senddata.h"
// put data to send in RTos Queues used for transmit over channels Lora and SPI // put data to send in RTos Queues used for transmit over channels Lora and SPI
void SendData(uint8_t port) { void SendPayload(uint8_t port) {
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[] MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]
SendBuffer.MessageSize = payload.getSize(); SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePort = port; SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize()); memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
// enqueue message in device's send queues // enqueue message in device's send queues
lora_enqueuedata(&SendBuffer); lora_enqueuedata(&SendBuffer);
spi_enqueuedata(&SendBuffer); spi_enqueuedata(&SendBuffer);
} // SendData } // SendPayload
// interrupt triggered function to prepare payload to send // interrupt triggered function to prepare payload to send
void sendPayload() { void sendCounter() {
// append counter data to payload // append counter data to payload
payload.reset(); payload.reset();
@ -48,10 +50,9 @@ void sendPayload() {
ESP_LOGD(TAG, "No valid GPS position or GPS data mode disabled"); ESP_LOGD(TAG, "No valid GPS position or GPS data mode disabled");
} }
#endif #endif
SendData(PAYLOAD_ENCODER <= 2 ? COUNTERPORT SendPayload(COUNTERPORT);
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT));
} // sendpayload() } // sendCounter()
void flushQueues() { void flushQueues() {
lora_queuereset(); lora_queuereset();