From 9574a194fd47f15bc14fd1e107ad38a2b934cc8e Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 21 Dec 2018 00:35:21 +0100 Subject: [PATCH] v1.6.996 --- README.md | 3 ++- include/bme680mems.h | 1 + include/globals.h | 22 +++++++++++----------- platformio.ini | 6 +++--- src/bme680mems.cpp | 4 ++-- src/cyclic.cpp | 16 +++++++++++----- src/display.cpp | 3 +-- src/hal/ttgobeam_new.h | 9 ++++++++- src/irqhandler.cpp | 2 +- src/lmic_config.h | 4 ++-- src/main.cpp | 12 +++++++++--- src/paxcounter.conf | 2 +- src/wifiscan.cpp | 2 -- 13 files changed, 52 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 87178ece..2214012c 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,8 @@ Target platform must be selected in [platformio.ini](https://github.com/cyberman Hardware dependent settings (pinout etc.) are stored in board files in /hal directory. If you want to use a ESP32 board which is not yet supported, use hal file generic.h and tailor pin mappings to your needs. Pull requests for new boards welcome.
3D printable cases can be found (and, if wanted so, ordered) on Thingiverse, see -Heltec, TTGOv2, TTGOv2.1, T-BEAM for example.
+Heltec, TTGOv2, TTGOv2.1, T-BEAM, +T-BEAM parts for example.
Power consumption was metered at around 450 - 1000mW, depending on board and user settings in paxcounter.conf. By default bluetooth sniffing is disabled (line *#define BLECOUNTER* in paxcounter.conf is commented out). Enabling bluetooth costs 30% more power + 30% flash storage for the software stack. Proof of concept showed that for passenger flow metering wifi sniffing shows better results than bluetooth sniffing. If you enable bluetooth be aware that this goes on expense of wifi sniffing results, because then wifi and bt stack must share the 2,4 GHz RF ressources of ESP32. If you need to sniff wifi and bt in parallel and need best possible results, use two boards - one for wifi only and one for bt only - and add counted results. diff --git a/include/bme680mems.h b/include/bme680mems.h index 70dd8fec..ad66c7cb 100644 --- a/include/bme680mems.h +++ b/include/bme680mems.h @@ -4,6 +4,7 @@ #include "globals.h" #include #include "bsec_integration.h" +#include "irqhandler.h" extern const uint8_t bsec_config_iaq[454]; diff --git a/include/globals.h b/include/globals.h index 83fa1677..da547af3 100644 --- a/include/globals.h +++ b/include/globals.h @@ -71,14 +71,14 @@ typedef struct { } gpsStatus_t; typedef struct { -float iaq; // IAQ signal -uint8_t iaq_accuracy; // accuracy of IAQ signal -float temperature; // temperature signal -float humidity; // humidity signal -float pressure; // pressure signal -float raw_temperature; // raw temperature signal -float raw_humidity; // raw humidity signal -float gas; // raw gas sensor signal + float iaq; // IAQ signal + uint8_t iaq_accuracy; // accuracy of IAQ signal + float temperature; // temperature signal + float humidity; // humidity signal + float pressure; // pressure signal + float raw_temperature; // raw temperature signal + float raw_humidity; // raw humidity signal + float gas; // raw gas sensor signal } bmeStatus_t; // global variables @@ -86,9 +86,9 @@ extern configData_t cfg; // current device configuration extern char display_line6[], display_line7[]; // screen buffers extern uint8_t volatile channel; // wifi channel rotation counter extern uint16_t volatile macs_total, macs_wifi, macs_ble, - batt_voltage; // display values -extern std::set macs; // temp storage for MACs -extern hw_timer_t *channelSwitch, *sendCycle; + batt_voltage; // display values +extern std::set macs; // temp storage for MACs +extern hw_timer_t *channelSwitch, *sendCycle, *displaytimer; extern std::array::iterator it; extern std::array beacons; diff --git a/platformio.ini b/platformio.ini index 2f557886..e3423f2e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,13 +30,13 @@ 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.995 +release_version = 1.6.996 ; 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 ; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA -upload_protocol = esptool -;upload_protocol = custom +;upload_protocol = esptool +upload_protocol = custom extra_scripts = pre:build.py keyfile = ota.conf ;platform_espressif32 = espressif32@1.5.0 diff --git a/src/bme680mems.cpp b/src/bme680mems.cpp index 86bb7ac1..468e85da 100644 --- a/src/bme680mems.cpp +++ b/src/bme680mems.cpp @@ -8,7 +8,7 @@ static const char TAG[] = "main"; bmeStatus_t bme_status; TaskHandle_t BmeTask; -float bme_offset = (float) BME_TEMP_OFFSET; +float bme_offset = (float)BME_TEMP_OFFSET; // --- Bosch BSEC library configuration --- // 3,3V supply voltage; 3s max time between sensor_control calls; 4 days @@ -59,7 +59,7 @@ int bme_init(void) { return_values_init ret = bsec_iot_init(BSEC_SAMPLE_RATE_LP, bme_offset, i2c_write, i2c_read, user_delay_ms, state_load, config_load); - + if ((int)ret.bme680_status) { ESP_LOGE(TAG, "Could not initialize BME680, error %d", (int)ret.bme680_status); diff --git a/src/cyclic.cpp b/src/cyclic.cpp index b0bc812d..137ea7f6 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -26,8 +26,8 @@ void doHousekeeping() { // time sync once per TIME_SYNC_INTERVAL #ifdef TIME_SYNC_INTERVAL if (millis() >= nextTimeSync) { - nextTimeSync = millis() + TIME_SYNC_INTERVAL * - 60000; // set up next time sync period + nextTimeSync = + millis() + TIME_SYNC_INTERVAL * 60000; // set up next time sync period do_timesync(); } #endif @@ -62,8 +62,8 @@ void doHousekeeping() { "free heap = %d bytes)", esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); SendPayload(COUNTERPORT); // send data before clearing counters - reset_counters(); // clear macs container and reset all counters - get_salt(); // get new salt for salting hashes + reset_counters(); // clear macs container and reset all counters + get_salt(); // get new salt for salting hashes if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again do_reset(); // memory leak, reset device @@ -89,7 +89,8 @@ void reset_counters() { void do_timesync() { #ifdef TIME_SYNC_INTERVAL -// sync time & date if we have valid gps time + +// sync time & date by GPS if we have valid gps time #ifdef HAS_GPS if (gps.time.isValid()) { setTime(gps.time.hour(), gps.time.minute(), gps.time.second(), @@ -101,9 +102,14 @@ void do_timesync() { ESP_LOGI(TAG, "No valid GPS time"); } #endif // HAS_GPS + +// sync time by LoRa Network if network supports DevTimeReq +#ifdef LMIC_ENABLE_DeviceTimeReq // 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 + #endif // TIME_SYNC_INTERVAL } // do_timesync() diff --git a/src/display.cpp b/src/display.cpp index ae7120c5..63f56831 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -121,8 +121,7 @@ void refreshtheDisplay() { // update Battery status (line 2) #ifdef HAS_BATTERY_PROBE u8x8.setCursor(0, 2); - u8x8.printf(batt_voltage > 4000 ? "B:USB " : "B:%.1fV", - batt_voltage / 1000.0); + u8x8.printf("B:%.1fV", batt_voltage / 1000.0); #endif // update GPS status (line 2) diff --git a/src/hal/ttgobeam_new.h b/src/hal/ttgobeam_new.h index 93f729a3..45f77d3c 100644 --- a/src/hal/ttgobeam_new.h +++ b/src/hal/ttgobeam_new.h @@ -13,13 +13,20 @@ // BME680 sensor on I2C bus // don't forget to connect SDIO of BME680 to GND for selecting i2c addr 0x76 // -//#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL +#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL #define HAS_LED GPIO_NUM_14 // on board green LED // user defined sensors //#define HAS_SENSORS 1 // comment out if device has user defined sensors +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +// Pins for I2C interface of OLED Display +#define MY_OLED_SDA (21) +#define MY_OLED_SCL (22) +#define MY_OLED_RST (NOT_A_PIN) +//#define DISPLAY_FLIP 1 // use if display is rotated + #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define BOARD_HAS_PSRAM // use extra 4MB external RAM diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index f79e035e..a9192a2b 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -61,7 +61,7 @@ void IRAM_ATTR SendCycleIRQ() { #ifdef HAS_DISPLAY void IRAM_ATTR DisplayIRQ() { - xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL); + xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL); portYIELD_FROM_ISR(); } #endif diff --git a/src/lmic_config.h b/src/lmic_config.h index 33e336aa..a28f24a5 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -22,7 +22,7 @@ //#define LMIC_USE_INTERRUPTS //time sync via LoRaWAN network, is not yet supported by TTN (LoRaWAN spec v1.0.3) -#define LMIC_ENABLE_DeviceTimeReq 1 +//#define LMIC_ENABLE_DeviceTimeReq 1 // 16 μs per tick // LMIC requires ticks to be 15.5μs - 100 μs long @@ -34,7 +34,7 @@ // faster or slower. This causes the transceiver to be earlier switched on, // so consuming more power. You may sharpen (reduce) this value if you are // limited on battery. -#define CLOCK_ERROR_PROCENTAGE 20 +#define CLOCK_ERROR_PROCENTAGE 3 // Set this to 1 to enable some basic debug output (using printf) about // RF settings used during transmission and reception. Set to 2 to diff --git a/src/main.cpp b/src/main.cpp index 42d1c48f..50eed5a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ configData_t cfg; // struct holds current device configuration char display_line6[16], display_line7[16]; // display buffers uint8_t volatile channel = 0; // channel rotation counter uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0, - batt_voltage = 0; // globals for display + batt_voltage = 0; // globals for display hw_timer_t *channelSwitch = NULL, *sendCycle = NULL, *homeCycle = NULL, *displaytimer = NULL; // irq tasks @@ -105,9 +105,15 @@ void setup() { chip_info.revision, spi_flash_get_chip_size() / (1024 * 1024), (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); - ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion()); + ESP_LOGI(TAG, "Internal Total heap %d, internal Free Heap %d", + ESP.getHeapSize(), ESP.getFreeHeap()); + ESP_LOGI(TAG, "SPIRam Total heap %d, SPIRam Free Heap %d", ESP.getPsramSize(), + ESP.getFreePsram()); + ESP_LOGI(TAG, "ChipRevision %d, Cpu Freq %d, SDK Version %s", + ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion()); + ESP_LOGI(TAG, "Flash Size %d, Flash Speed %d", ESP.getFlashChipSize(), + ESP.getFlashChipSpeed()); ESP_LOGI(TAG, "Wifi/BT software coexist version: %s", esp_coex_version_get()); - ESP_LOGI(TAG, "Free RAM: %d bytes", ESP.getFreeHeap()); #ifdef HAS_GPS ESP_LOGI(TAG, "TinyGPS+ v%s", TinyGPSPlus::libraryVersion()); diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 370a5ce3..94cdfd1d 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -81,7 +81,7 @@ #define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] // setting for syncing time of node -//#define TIME_SYNC_INTERVAL 60 // sync time each ... minutes [default = 60], comment out means off +#define TIME_SYNC_INTERVAL 60 // sync time each ... minutes [default = 60], comment out means off // LMIC settings // moved to src/lmic_config.h \ No newline at end of file diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 5a7a77a6..675d511b 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -54,8 +54,6 @@ void wifi_sniffer_init(void) { ESP_ERROR_CHECK(esp_coex_preference_set( ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib - coex_deinit(); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg ESP_ERROR_CHECK( esp_wifi_set_country(&wifi_country)); // set locales for RF and channels