From 9c661673039a28e565313ebfd3920f564ec21a66 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 14 Nov 2018 23:10:59 +0100 Subject: [PATCH] BME680 support (experimental) --- include/globals.h | 10 +++++----- include/payload.h | 1 + platformio.ini | 4 ++-- src/bme680read.cpp | 15 +++++++-------- src/hal/heltec.h | 4 ---- src/lmic_config.h | 5 +++-- src/payload.cpp | 20 ++++++++++++++++++++ 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/include/globals.h b/include/globals.h index 4ccace4b..0966ba95 100644 --- a/include/globals.h +++ b/include/globals.h @@ -47,11 +47,11 @@ typedef struct { } gpsStatus_t; typedef struct { - uint16_t temperature; - uint16_t pressure; - uint16_t humidity; - uint16_t gas_resistance; - uint16_t altitude; + float_t temperature; + float_t pressure; + float_t humidity; + float_t gas_resistance; + float_t altitude; } bmeStatus_t; // global variables diff --git a/include/payload.h b/include/payload.h index 57bb8964..5c71a5cd 100644 --- a/include/payload.h +++ b/include/payload.h @@ -39,6 +39,7 @@ public: uint8_t reset1, uint8_t reset2); void addAlarm(int8_t rssi, uint8_t message); void addGPS(gpsStatus_t value); + void addBME(bmeStatus_t value); void addButton(uint8_t value); #if PAYLOAD_ENCODER == 1 // format plain diff --git a/platformio.ini b/platformio.ini index 558db934..6abb2b08 100644 --- a/platformio.ini +++ b/platformio.ini @@ -6,10 +6,10 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = generic +env_default = generic ;env_default = ebox ;env_default = eboxtube -env_default = heltec +;env_default = heltec ;env_default = heltecv2 ;env_default = ttgov1 ;env_default = ttgov2 diff --git a/src/bme680read.cpp b/src/bme680read.cpp index 6114d305..f49c11ea 100644 --- a/src/bme680read.cpp +++ b/src/bme680read.cpp @@ -47,15 +47,14 @@ void bme_loop(void *pvParameters) { if (!bme.performReading()) { ESP_LOGE(TAG, "BME680 read error"); continue; + } else { + // read current BME data and buffer in global struct + bme_status.temperature = bme.temperature; + bme_status.pressure = bme.pressure / 100.0; + bme_status.humidity = bme.humidity; + bme_status.gas_resistance = bme.gas_resistance / 1000.0; + bme_status.altitude = bme.readAltitude(SEALEVELPRESSURE_HPA); } - - // read BME data and cast to global struct - bme_status.temperature = (uint16_t)bme.temperature; - bme_status.pressure = (uint16_t)(bme.pressure / 100.0); - bme_status.humidity = (uint16_t)bme.humidity; - bme_status.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0); - bme_status.altitude = (uint16_t)bme.readAltitude(SEALEVELPRESSURE_HPA); - } // end of infinite loop vTaskDelete(NULL); // shoud never be reached diff --git a/src/hal/heltec.h b/src/hal/heltec.h index fa61fd31..d3c54ee3 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -3,13 +3,9 @@ #include -#define HAS_BME 1 // BME680 sensor on I2C bus (SDA=4/SCL=15); comment out if not present - // Hardware related definitions for Heltec LoRa-32 Board - #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define CFG_sx1276_radio 1 - #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board #define HAS_LED (25) // white LED on board #define HAS_BUTTON (0) // button "PROG" on board diff --git a/src/lmic_config.h b/src/lmic_config.h index 33a08a45..bfa52ec3 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -21,7 +21,8 @@ //#define LMIC_USE_INTERRUPTS -#define LMIC_ENABLE_DeviceTimeReq 1 +//time sync via LoRaWAN network, is not yet supported by TTN (LoRaWAN spec v1.0.3) +//#define LMIC_ENABLE_DeviceTimeReq 1 // 16 μs per tick // LMIC requires ticks to be 15.5μs - 100 μs long @@ -40,7 +41,7 @@ // enable more verbose output. Make sure that printf is actually // configured (e.g. on AVR it is not by default), otherwise using it can // cause crashing. -#define LMIC_DEBUG_LEVEL 2 +#define LMIC_DEBUG_LEVEL 0 // Enable this to allow using printf() to print to the given serial port // (or any other Print object). This can be easy for debugging. The diff --git a/src/payload.cpp b/src/payload.cpp index ba7e2f06..56c87fce 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -93,6 +93,16 @@ void PayloadConvert::addGPS(gpsStatus_t value) { #endif } +void PayloadConvert::addBME(bmeStatus_t value) { +#ifdef HAS_BME + buffer[cursor++] = (byte)(value.temperature); + buffer[cursor++] = (byte)(value.pressure); + buffer[cursor++] = (byte)(value.humidity); + buffer[cursor++] = (byte)(value.gas_resistance); + buffer[cursor++] = (byte)(value.altitude); +#endif +} + void PayloadConvert::addButton(uint8_t value) { #ifdef HAS_BUTTON buffer[cursor++] = value; @@ -150,6 +160,16 @@ void PayloadConvert::addGPS(gpsStatus_t value) { #endif } +void PayloadConvert::addBME(bmeStatus_t value) { +#ifdef HAS_BME + writeUint8((byte)value.temperature); + writeUint8((byte)value.pressure); + writeUint8((byte)value.humidity); + writeUint8((byte)value.gas_resistance); + writeUint8((byte)value.altitude); +#endif +} + void PayloadConvert::addButton(uint8_t value) { #ifdef HAS_BUTTON writeUint8(value);