Skip to content

Commit

Permalink
payload decoder reworked for BME680 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus K Wilting authored and Klaus K Wilting committed Nov 18, 2018
1 parent 02b3f1e commit 06dcad6
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Hereafter described is the default *plain* format, which uses MSB bit numbering.
bytes 1-2: Temperature [°C]
bytes 3-4: Pressure [hPa]
bytes 5-6: Humidity [%]
bytes 7-8: Gas resistance [MOhm]
bytes 7-8: Gas resistance [kOhm]
bytes 9-10: Altitude [meter]

# Remote control
Expand Down
2 changes: 1 addition & 1 deletion include/irqhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define DISPLAY_IRQ 0x01
#define BUTTON_IRQ 0x02
#define SENDPAYLOAD_IRQ 0x04
#define SENDCOUNTER_IRQ 0x04
#define CYCLIC_IRQ 0x08

#include "globals.h"
Expand Down
4 changes: 2 additions & 2 deletions include/senddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "lorawan.h"
#include "cyclic.h"

void SendData(uint8_t port);
void sendPayload(void);
void SendPayload(uint8_t port);
void sendCounter(void);
void checkSendQueues(void);
void flushQueues();

Expand Down
68 changes: 33 additions & 35 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng

[common]
; 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!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 0
Expand All @@ -41,10 +41,8 @@ keyfile = ota.conf
platform_espressif32 = [email protected]
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
lib_deps_all =
lib_deps_basic =
ArduinoJson@^5.13.1
Adafruit Unified Sensor@^1.0.2
Adafruit BME680 Library@^1.0.7
Time@>=1.5
lib_deps_lora =
; MCCI LoRaWAN LMIC library@^2.2.2
Expand All @@ -54,6 +52,16 @@ lib_deps_rgbled =
SmartLeds@>=1.1.3
lib_deps_gps =
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 =
-include src/hal/${PIOENV}.h
-include src/paxcounter.conf
Expand All @@ -72,7 +80,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
build_flags =
${common.build_flags}
Expand All @@ -87,8 +95,9 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
build_flags =
${common.build_flags}
upload_protocol = ${common.upload_protocol}
Expand All @@ -102,7 +111,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -118,7 +127,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -134,7 +143,7 @@ board = ttgo-lora32-v1
board_build.partitions = ${common.board_build.partitions}
upload_speed = 115200
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -150,7 +159,7 @@ board = ttgo-lora32-v1
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -166,7 +175,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -182,7 +191,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_display}
build_flags =
Expand All @@ -198,7 +207,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_gps}
build_flags =
Expand All @@ -215,7 +224,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
build_flags =
Expand All @@ -231,7 +240,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
Expand All @@ -248,7 +257,7 @@ board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
Expand All @@ -266,7 +275,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
build_flags =
Expand All @@ -282,7 +291,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
build_flags =
Expand All @@ -298,7 +307,7 @@ board = lolin32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_basic}
${common.lib_deps_rgbled}
build_flags =
${common.build_flags}
Expand All @@ -312,13 +321,8 @@ framework = arduino
board = featheresp32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_display}
build_flags =
${common.build_flags}
lib_deps = ${common.lib_deps_all}
build_flags = ${common.build_flags}
upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed}
Expand All @@ -329,14 +333,8 @@ framework = arduino
board = heltec_wifi_lora_32
board_build.partitions = ${common.board_build.partitions}
upload_speed = 921600
lib_deps =
${common.lib_deps_all}
${common.lib_deps_lora}
${common.lib_deps_rgbled}
${common.lib_deps_gps}
${common.lib_deps_display}
build_flags =
${common.build_flags}
lib_deps = ${common.lib_deps_all}
build_flags = ${common.build_flags}
upload_protocol = ${common.upload_protocol}
extra_scripts = ${common.extra_scripts}
monitor_speed = ${common.monitor_speed}
monitor_speed = ${common.monitor_speed}
2 changes: 1 addition & 1 deletion src/TTN/packed_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function Decoder(bytes, port) {

if (port === 7) {
// 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']);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/TTN/plain_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Decoder(bytes, port) {
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.air = ((bytes[i++] << 8) | bytes[i++]);
decoded.altitude = ((bytes[i++] << 8) | bytes[i++]);
}

Expand Down
9 changes: 4 additions & 5 deletions src/bme680read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bmeStatus_t bme_status;

void bme_init(void) {
// initialize BME680 sensor using default i2c address 0x77
if (bme.begin()) {
if (bme.begin(HAS_BME)) {
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
Expand All @@ -31,11 +31,10 @@ bool bme_read(void) {
if (ret) {
// read current BME data and buffer in global struct
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.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0);
bme_status.altitude =
(uint16_t)(bme.readAltitude(SEALEVELPRESSURE_HPA / 1000.0));
bme_status.gas_resistance = (uint16_t)(bme.gas_resistance / 1000.0); // convert Ohm -> kOhm
bme_status.altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
ESP_LOGI(TAG, "BME680 sensor data read success");
} else {
ESP_LOGI(TAG, "BME680 sensor read error");
Expand Down
2 changes: 1 addition & 1 deletion src/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ void readButton() {
ESP_LOGI(TAG, "Button pressed");
payload.reset();
payload.addButton(0x01);
SendData(BUTTONPORT);
SendPayload(BUTTONPORT);
}
#endif
12 changes: 6 additions & 6 deletions src/cyclic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ void doHousekeeping() {
spi_housekeeping();
lora_housekeeping();

// time sync once per TIME_SYNC_INTERVAL_MIN
#ifdef TIME_SYNC
// time sync once per TIME_SYNC_INTERVAL
#ifdef TIME_SYNC_INTERVAL
if (millis() >= nextTimeSync) {
nextTimeSync = millis() + TIME_SYNC_INTERVAL_MIN *
nextTimeSync = millis() + TIME_SYNC_INTERVAL *
60000; // set up next time sync period
do_timesync();
}
Expand Down Expand Up @@ -63,7 +63,7 @@ void doHousekeeping() {
"Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)",
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
get_salt(); // get new salt for salting hashes

Expand All @@ -90,7 +90,7 @@ void reset_counters() {
}

void do_timesync() {
#ifdef TIME_SYNC
#ifdef TIME_SYNC_INTERVAL
// sync time & date if we have valid gps time
#ifdef HAS_GPS
if (gps.time.isValid()) {
Expand All @@ -106,7 +106,7 @@ void do_timesync() {
// Schedule a network time request at the next possible time
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
ESP_LOGI(TAG, "Network time request scheduled");
#endif // TIME_SYNC
#endif // TIME_SYNC_INTERVAL
} // do_timesync()

#ifndef VERBOSE
Expand Down
2 changes: 1 addition & 1 deletion src/hal/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define SPI_SCLK GPIO_NUM_18
#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_sx1272_radio 1 // select LoRa chip
Expand Down
2 changes: 1 addition & 1 deletion src/hal/heltec.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#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
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
Expand Down
2 changes: 2 additions & 0 deletions src/hal/octopus32.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// disable brownout detection (avoid unexpected reset on some boards)
#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 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
Expand Down
2 changes: 1 addition & 1 deletion src/hal/ttgov21new.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// 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 CFG_sx1276_radio 1 // HPD13A LoRa SoC
Expand Down
6 changes: 3 additions & 3 deletions src/irqhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void irqHandler(void *pvParameters) {
doHousekeeping();

// is time to send the payload?
if (InterruptStatus & SENDPAYLOAD_IRQ)
sendPayload();
if (InterruptStatus & SENDCOUNTER_IRQ)
sendCounter();
}
vTaskDelete(NULL); // shoud never be reached
}
Expand All @@ -55,7 +55,7 @@ void IRAM_ATTR homeCycleIRQ() {
}

void IRAM_ATTR SendCycleIRQ() {
xTaskNotifyFromISR(irqHandlerTask, SENDPAYLOAD_IRQ, eSetBits, NULL);
xTaskNotifyFromISR(irqHandlerTask, SENDCOUNTER_IRQ, eSetBits, NULL);
portYIELD_FROM_ISR();
}

Expand Down
2 changes: 1 addition & 1 deletion src/macsniff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
#endif
payload.reset();
payload.addAlarm(rssi, beaconID);
SendData(BEACONPORT);
SendPayload(BEACONPORT);
}
};

Expand Down
Loading

0 comments on commit 06dcad6

Please sign in to comment.