From a9f19d4459a70e006636f0ae661da6422d4f59a8 Mon Sep 17 00:00:00 2001 From: Chrisotph Schultz Date: Fri, 25 Sep 2020 23:41:43 +0200 Subject: [PATCH 01/21] set configs --- src/loraconf.sample.h | 89 ------------------------------------------- src/paxcounter.conf | 8 ++-- 2 files changed, 4 insertions(+), 93 deletions(-) delete mode 100644 src/loraconf.sample.h diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h deleted file mode 100644 index a088cdc2..00000000 --- a/src/loraconf.sample.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef __LORACONF_H__ -#define __LORACONF_H__ - -#if (HAS_LORA) - -/************************************************************ - * LMIC LoRaWAN configuration - * - * Read the values from TTN console (or whatever applies), insert them here, - * and rename this file to src/loraconf.h - * - * You can configure OTAA or ABP Activation. In order to use ABP, uncomment - * (enable) the following line, but you should only do so, if you have good - * reasons for not using OTAA. - * - *************************************************************/ - -//#define LORA_ABP - -#ifndef LORA_ABP -/************************************************************ - * OTAA configuration - * - * DEVEUI, APPEUI and APPKEY should all be specified in MSB format as - * displayed in TTN console, so you can cut & paste from there. This is different - * from standard LMIC-Arduino which expects DEVEUI and APPEUI in LSB format. - * For TTN, APPEUI in MSB format always starts with 0x70, 0xB3, 0xD5. - - * Set your DEVEUI here, if your device has have a fixed one. - * If you leave this untouched, then the DEVEUI will be derived from device's - * MAC adress during startup and will be displayed on device's screen as well as - * on serial console, if you set 'verbose 1' in paxcounter.conf and - * 'debug_level 3' in platformio.ini. - * If using a board with Microchip 24AA02E64 Uinique ID for deveui, the DEVEUI - * will be overwritten by the one contained in the Microchip module. - * - ************************************************************/ - -static const u1_t DEVEUI[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -static const u1_t APPEUI[8] = {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00}; - -static const u1_t APPKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -#endif - -#ifdef LORA_ABP -/************************************************************ - * ABP configuration (for development) - * - * Get your - * - Network Session Key (NWKSKEY) - * - App Session Key and your (APPSKEY) - * - Device Address (DEVADDR) - * from e.g. TTN console and replace the example values below. - * - * NOTE: Use MSB format (as displayed in TTN console, so you can cut & paste - * from there) - * - * NOTE: You may also need to adjust lorawan_abp.cpp in order to configure - * different channels and data rate channels to match your country's regulations - * and your network's settings. - * - ************************************************************/ - -// ID of LoRaAlliance assigned Network (for a list, see e.g. here -// https://www.thethingsnetwork.org/docs/lorawan/prefix-assignments.html) -static const u1_t NETID = 0x13; // TTN - -static const u1_t NWKSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - -static const u1_t APPSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - -static const u4_t DEVADDR = - 0x00000000; // <-- Change this address for every node! - -// set additional ABP parameters in loraconf_abp.cpp -void setABPParameters(); - -#endif - -#endif // HAS_LORA - -#endif // __LORACONF_H__ \ No newline at end of file diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 57264b72..41a61673 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -16,8 +16,8 @@ // Set this to include BLE counting and vendor filter functions, or to switch off WIFI counting #define VENDORFILTER 0 // set to 0 if you want to scan all devices, not filtering smartphone OUIs -#define BLECOUNTER 0 // set to 0 if you do not want to install the BLE sniffer -#define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer +#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer +#define WIFICOUNTER 0 // set to 0 if you do not want to install the WIFI sniffer // BLE scan parameters #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below @@ -25,11 +25,11 @@ #define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle // Corona Exposure Notification Service(ENS) counter -#define COUNT_ENS 0 // count found number of devices which advertise Exposure Notification Service +#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service // set to 0 if you do not want to enable this function // for additional sensors (added by some user) -#define HAS_SENSOR_1 0 // set to 1 if you want to transmit CWA counter +#define HAS_SENSOR_1 1 // set to 1 if you want to transmit CWA counter #define HAS_SENSOR_2 0 // not used #define HAS_SENSOR_3 0 // not used #define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) // to simplify things From e117f6945fba60e61802ea21c669b4c8883097ef Mon Sep 17 00:00:00 2001 From: Chrisotph Schultz Date: Sun, 27 Sep 2020 19:29:31 +0200 Subject: [PATCH 02/21] done chages --- platformio.ini | 10 +++++----- src/ota.sample.conf | 8 -------- src/paxcounter.conf | 4 ++-- 3 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 src/ota.sample.conf diff --git a/platformio.ini b/platformio.ini index 695b6435..d2669781 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,7 +7,7 @@ ; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -halfile = generic.h +;halfile = generic.h ;halfile = ebox.h ;halfile = eboxtube.h ;halfile = ecopower.h @@ -16,7 +16,7 @@ halfile = generic.h ;halfile = ttgov1.h ;halfile = ttgov2.h ;halfile = ttgov21old.h -;halfile = ttgov21new.h +halfile = ttgov21new.h ;halfile = ttgofox.h ;halfile = ttgobeam.h ;halfile = ttgobeam10.h @@ -46,7 +46,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 2.0.12 +release_version = 2.0.13 ; 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 = 3 @@ -73,7 +73,7 @@ lib_deps_gps = lib_deps_sensors = adafruit/Adafruit Unified Sensor @ ^1.1.4 adafruit/Adafruit BME280 Library @ ^2.1.0 - adafruit/Adafruit BMP085 Library @ ^1.1.0 + adafruit/Adafruit BMP085 Unified boschsensortec/BSEC Software Library @ 1.5.1474 https://github.com/ricki-z/SDS011.git lib_deps_basic = @@ -110,7 +110,7 @@ build_flags_all = [env] lib_ldf_mode = deep ; #632 Fixes compiler error with OneBitDisplay library framework = arduino -board = esp32dev +board = ttgo-lora32-v21new board_build.partitions = min_spiffs.csv upload_speed = ${common.upload_speed} ;upload_port = COM8 diff --git a/src/ota.sample.conf b/src/ota.sample.conf deleted file mode 100644 index a10d79dc..00000000 --- a/src/ota.sample.conf +++ /dev/null @@ -1,8 +0,0 @@ -[ota] -OTA_WIFI_SSID = MyHomeWifi -OTA_WIFI_PASS = FooBar42! - -[bintray] -BINTRAY_USER = MyBintrayUser -BINTRAY_REPO = MyBintrayRepo -BINTRAY_API_TOKEN = 3894a7a51d70c6523c1b7479261c34845ebf7878 \ No newline at end of file diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 41a61673..e82d6adb 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -17,7 +17,7 @@ // Set this to include BLE counting and vendor filter functions, or to switch off WIFI counting #define VENDORFILTER 0 // set to 0 if you want to scan all devices, not filtering smartphone OUIs #define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer -#define WIFICOUNTER 0 // set to 0 if you do not want to install the WIFI sniffer +#define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer // BLE scan parameters #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below @@ -89,7 +89,7 @@ #define TIME_SYNC_INTERVAL_RETRY 10 // retry time sync after lost sync each .. minutes [default = 10], 0 means off #define TIME_SYNC_SAMPLES 1 // number of time requests for averaging, max. 255 #define TIME_SYNC_CYCLE 60 // delay between two time samples [seconds] -#define TIME_SYNC_TIMEOUT 300 // timeout waiting for timeserver answer [seconds] +#define TIME_SYNC_TIMEOUT 400 // timeout waiting for timeserver answer [seconds] #define TIME_SYNC_COMPILEDATE 0 // set to 1 to use compile date to initialize RTC after power outage [default = 0] // time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino From 6d3222a7eb627ec8225588ebd93338a0d284c14e Mon Sep 17 00:00:00 2001 From: Chrisotph Schultz Date: Sun, 27 Sep 2020 22:44:56 +0200 Subject: [PATCH 03/21] added description of payload mask --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 2d18ce1e..4f2d9093 100644 --- a/README.md +++ b/README.md @@ -481,6 +481,15 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat 0x14 set payload mask byte 1 = sensor data payload mask (0..255, meaning of bits see above) + 0x01 = GPS_DATA + 0x02 = ALARM_DATA + 0x04 = MEMS_DATA + 0x08 = COUNT_DATA (default) + 0x10 = SENSOR_1_DATA (ENS-COUNTS) + 0x20 = SENSOR_2_DATA + 0x40 = SENSOR_3_DATA + 0x80 = BATT_DATA + bytes can be combined eg COUNT_DATA ;SENSOR_1_DATA ;BATT_DATA: `0x08 | 0x10 |0x80 = 0x98` 0x15 set BME data on/off From 1c40572c9b76a6d9b1431b85ed81c636512f4fd2 Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Mon, 28 Sep 2020 09:49:41 +1300 Subject: [PATCH 04/21] Synch time from GPX on first valid GPS time received --- src/gpsread.cpp | 15 +++++++++++++++ src/timekeeper.cpp | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 45f1b65d..650c5866 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -21,6 +21,9 @@ static uint16_t nmea_txDelay_ms = static uint16_t nmea_txDelay_ms = 0; #endif +// did the last packet contain a valid time? +bool hasValidTime = false; + // initialize and configure GPS int gps_init(void) { @@ -159,6 +162,18 @@ void gps_loop(void *pvParameters) { delay(2); // 2ms delay according L76 datasheet } #endif + +#if !TIME_SYNC_LORASERVER && !TIME_SYNC_LORAWAN + if (!hasValidTime) { + if (gpstime.isUpdated() && gpstime.isValid()) { + hasValidTime = true; + if (timeSource == _unsynced) { + calibrateTime(); + } + } + } +#endif + } // if // show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index bc9e52b5..01777be7 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -26,7 +26,8 @@ Ticker timesyncer; void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); } void calibrateTime(void) { - + ESP_LOGD(TAG, "[%0.3f] calibrateTime, timeSource == %d", millis() / 1000.0, + timeSource); time_t t = 0; uint16_t t_msec = 0; @@ -49,7 +50,9 @@ void calibrateTime(void) { // no RTC -> fallback to GPS time #if (HAS_GPS) t = get_gpstime(&t_msec); - timeSource = _gps; + if (t) { + timeSource = _gps; + } #endif setMyTime((uint32_t)t, t_msec, timeSource); // set time From db281e11f9b74980361e03b1ac7a7d9506dfdf94 Mon Sep 17 00:00:00 2001 From: Chrisotph Schultz Date: Sun, 27 Sep 2020 23:15:50 +0200 Subject: [PATCH 05/21] created paxcounter_orig.conf and platformio_orig.ini, added platformio.ini and paxcounter.conf to .gitignore and update Readme.md --- .gitignore | 4 +- README.md | 8 +-- platformio_orig.ini | 135 +++++++++++++++++++++++++++++++++++++++ src/loarconf_sample_h | 88 +++++++++++++++++++++++++ src/ota_sample.conf | 8 +++ src/paxcounter_orig.conf | 122 +++++++++++++++++++++++++++++++++++ 6 files changed, 360 insertions(+), 5 deletions(-) create mode 100644 platformio_orig.ini create mode 100644 src/loarconf_sample_h create mode 100644 src/ota_sample.conf create mode 100644 src/paxcounter_orig.conf diff --git a/.gitignore b/.gitignore index da637fe1..ff171159 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ .clang_complete .gcc-flags.json src/loraconf.h -src/ota.conf \ No newline at end of file +src/ota.conf +platformio.ini +src/paxcounter.conf \ No newline at end of file diff --git a/README.md b/README.md index 4f2d9093..9de1ebf1 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,11 @@ By default bluetooth sniffing not installed (#define *BLECOUNTER* 0 in paxcounte Compile time configuration is spread across several files. Before compiling the code, edit or create the following files: -## platformio.ini -Edit `platformio.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards. +## platformio_orig.ini +Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards. and rename to `platformio.ini` -## src/paxcounter.conf -Edit `src/paxcounter.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. +## src/paxcounter_orig.conf +Edit `src/paxcounter.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Rename to `paxcounter.conf` If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in `paxcounter.conf`. diff --git a/platformio_orig.ini b/platformio_orig.ini new file mode 100644 index 00000000..00c89342 --- /dev/null +++ b/platformio_orig.ini @@ -0,0 +1,135 @@ +; PlatformIO Project Configuration File +; NOTE: PlatformIO v4 is needed! +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + + +; ---> SELECT THE TARGET PLATFORM HERE! <--- +[board] +halfile = generic.h +;halfile = ebox.h +;halfile = eboxtube.h +;halfile = ecopower.h +;halfile = heltec.h +;halfile = heltecv2.h +;halfile = ttgov1.h +;halfile = ttgov2.h +;halfile = ttgov21old.h +;halfile = ttgov21new.h +;halfile = ttgofox.h +;halfile = ttgobeam.h +;halfile = ttgobeam10.h +;halfile = fipy.h +;halfile = lopy.h +;halfile = lopy4.h +;halfile = lolin32litelora.h +;halfile = lolin32lora.h +;halfile = lolin32lite.h +;halfile = wemos32oled.h +;halfile = wemos32matrix.h +;halfile = octopus32.h +;halfile = tinypico.h +;halfile = tinypicomatrix.h +;halfile = m5core.h +;halfile = m5fire.h +;halfile = olimexpoeiso.h + +[platformio] +; upload firmware to board with usb cable +default_envs = usb +; upload firmware to a jfrog bintray repository +;default_envs = ota +; use latest versions of libraries +;default_envs = dev +description = Paxcounter is a device for metering passenger flows in realtime. It counts how many mobile devices are around. + +[common] +; for release_version use max. 10 chars total, use any decimal format like "a.b.c" +release_version = 2.0.12 +; 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 = 3 +extra_scripts = pre:build.py +otakeyfile = ota.conf +lorakeyfile = loraconf.h +lmicconfigfile = lmic_config.h +platform_espressif32 = espressif32@2.0.0 +monitor_speed = 115200 +upload_speed = 115200 ; set by build.py and taken from hal file +display_library = ; set by build.py and taken from hal file +lib_deps_lora = + mcci-catena/MCCI LoRaWAN LMIC library @ ^3.2.0 +lib_deps_display = + bitbank2/OneBitDisplay @ 1.5.0 + ricmoo/QRCode @ ^0.0.1 + bodmer/TFT_eSPI @ ^2.2.20 +lib_deps_ledmatrix = + seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0 +lib_deps_rgbled = + roboticsbrno/SmartLeds @ ^1.2.1 +lib_deps_gps = + mikalhart/TinyGPSPlus @ ^1.0.2 +lib_deps_sensors = + adafruit/Adafruit Unified Sensor @ ^1.1.4 + adafruit/Adafruit BME280 Library @ ^2.1.0 + adafruit/Adafruit BMP085 Library @ ^1.1.0 + boschsensortec/BSEC Software Library @ 1.5.1474 + https://github.com/ricki-z/SDS011.git +lib_deps_basic = + bblanchon/ArduinoJson @ <6 + jchristensen/Timezone @ ^1.2.4 + makuna/RTC @ ^2.3.5 + spacehuhn/SimpleButton + lewisxhe/AXP202X_Library @ ^1.1.2 + geeksville/esp32-micro-sdcard @ ^0.1.1 + 256dpi/MQTT @ ^2.4.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} + ${common.lib_deps_ledmatrix} +build_flags_basic = + -include "src/hal/${board.halfile}" + -include "src/paxcounter.conf" + -w + '-DCORE_DEBUG_LEVEL=${common.debug_level}' + '-DLOG_LOCAL_LEVEL=${common.debug_level}' + '-DPROGVERSION="${common.release_version}"' +build_flags_sensors = + -Llib/Bosch-BSEC/src/esp32/ + -lalgobsec +build_flags_all = + ${common.build_flags_basic} + ${common.build_flags_sensors} + -mfix-esp32-psram-cache-issue + +[env] +lib_ldf_mode = deep ; #632 Fixes compiler error with OneBitDisplay library +framework = arduino +board = esp32dev +board_build.partitions = min_spiffs.csv +upload_speed = ${common.upload_speed} +;upload_port = COM8 +platform = ${common.platform_espressif32} +lib_deps = ${common.lib_deps_all} +build_flags = ${common.build_flags_all} +upload_protocol = ${common.upload_protocol} +extra_scripts = ${common.extra_scripts} +monitor_speed = ${common.monitor_speed} +monitor_filters = time, esp32_exception_decoder, default + +[env:ota] +upload_protocol = custom + +[env:usb] +upload_protocol = esptool + +[env:dev] +upload_protocol = esptool +build_type = debug +platform = https://github.com/platformio/platform-espressif32.git#develop +platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git \ No newline at end of file diff --git a/src/loarconf_sample_h b/src/loarconf_sample_h new file mode 100644 index 00000000..d3dfb08c --- /dev/null +++ b/src/loarconf_sample_h @@ -0,0 +1,88 @@ +#ifndef __LORACONF_H__ +#define __LORACONF_H__ + +#if (HAS_LORA) + +/************************************************************ + * LMIC LoRaWAN configuration + * + * Read the values from TTN console (or whatever applies), insert them here, + * and rename this file to src/loraconf.h + * + * You can configure OTAA or ABP Activation. In order to use ABP, uncomment + * (enable) the following line, but you should only do so, if you have good + * reasons for not using OTAA. + * + *************************************************************/ + +//#define LORA_ABP + +#ifndef LORA_ABP +/************************************************************ + * OTAA configuration + * + * DEVEUI, APPEUI and APPKEY should all be specified in MSB format as + * displayed in TTN console, so you can cut & paste from there. This is different + * from standard LMIC-Arduino which expects DEVEUI and APPEUI in LSB format. + * For TTN, APPEUI in MSB format always starts with 0x70, 0xB3, 0xD5. + * Set your DEVEUI here, if your device has have a fixed one. + * If you leave this untouched, then the DEVEUI will be derived from device's + * MAC adress during startup and will be displayed on device's screen as well as + * on serial console, if you set 'verbose 1' in paxcounter.conf and + * 'debug_level 3' in platformio.ini. + * If using a board with Microchip 24AA02E64 Uinique ID for deveui, the DEVEUI + * will be overwritten by the one contained in the Microchip module. + * + ************************************************************/ + +static const u1_t DEVEUI[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +static const u1_t APPEUI[8] = {0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00}; + +static const u1_t APPKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +#endif + +#ifdef LORA_ABP +/************************************************************ + * ABP configuration (for development) + * + * Get your + * - Network Session Key (NWKSKEY) + * - App Session Key and your (APPSKEY) + * - Device Address (DEVADDR) + * from e.g. TTN console and replace the example values below. + * + * NOTE: Use MSB format (as displayed in TTN console, so you can cut & paste + * from there) + * + * NOTE: You may also need to adjust lorawan_abp.cpp in order to configure + * different channels and data rate channels to match your country's regulations + * and your network's settings. + * + ************************************************************/ + +// ID of LoRaAlliance assigned Network (for a list, see e.g. here +// https://www.thethingsnetwork.org/docs/lorawan/prefix-assignments.html) +static const u1_t NETID = 0x13; // TTN + +static const u1_t NWKSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const u1_t APPSKEY[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const u4_t DEVADDR = + 0x00000000; // <-- Change this address for every node! + +// set additional ABP parameters in loraconf_abp.cpp +void setABPParameters(); + +#endif + +#endif // HAS_LORA + +#endif // __LORACONF_H__ \ No newline at end of file diff --git a/src/ota_sample.conf b/src/ota_sample.conf new file mode 100644 index 00000000..a10d79dc --- /dev/null +++ b/src/ota_sample.conf @@ -0,0 +1,8 @@ +[ota] +OTA_WIFI_SSID = MyHomeWifi +OTA_WIFI_PASS = FooBar42! + +[bintray] +BINTRAY_USER = MyBintrayUser +BINTRAY_REPO = MyBintrayRepo +BINTRAY_API_TOKEN = 3894a7a51d70c6523c1b7479261c34845ebf7878 \ No newline at end of file diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf new file mode 100644 index 00000000..7cded6cf --- /dev/null +++ b/src/paxcounter_orig.conf @@ -0,0 +1,122 @@ +// clang-format off + +// ----- Paxcounter user config file ------ +// +// --> adapt to your needs and use case <-- +// +// Note: After editing, before "build", use "clean" button in PlatformIO! + +// Verbose enables additional serial debug output +#define VERBOSE 1 // set to 0 to silence the device, for mute use build option + +// Payload send cycle and encoding +#define SENDCYCLE 30 // payload send cycle [seconds/2], 0 .. 255 +#define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed +#define COUNTERMODE 1 // 0=cyclic, 1=cumulative, 2=cyclic confirmed + +// Set this to include BLE counting and vendor filter functions, or to switch off WIFI counting +#define VENDORFILTER 0 // set to 0 if you want to scan all devices, not filtering smartphone OUIs +#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer +#define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer + +// BLE scan parameters +#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below +#define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms +#define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle + +// Corona Exposure Notification Service(ENS) counter +#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service + // set to 0 if you do not want to enable this function + +// for additional sensors (added by some user) +#define HAS_SENSOR_1 1 // set to 1 if you want to transmit CWA counter +#define HAS_SENSOR_2 0 // not used +#define HAS_SENSOR_3 0 // not used +#define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) // to simplify things + +/* Note: guide for setting bluetooth parameters +* +* |< Scan Window > |< Scan Window > | ... |< Scan Window > | +* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >| +* |< Scan duration >| +* +* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default). +* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL. +* Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising. +* -> Adjust these values with power consumption in mind if power is limited. +* -> Scan interval can be changed during runtime by remote comammand. +*/ + +// WiFi scan parameters +#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings +#define WIFI_CHANNEL_MAX 13 // total channel number to scan +#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings +#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. + +// LoRa payload default parameters +#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle +#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results +#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit +#define PAYLOAD_OPENSENSEBOX 0 // send payload compatible to sensebox.de (swap geo position and pax data) +#define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] +#define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] +#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy +#define SEND_QUEUE_SIZE 10 // maximum number of messages in payload send queue [1 = no queue] + +// Hardware settings +#define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%] +#define DISPLAYREFRESH_MS 40 // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second +#define DISPLAYCONTRAST 80 // 0 .. 255, OLED display contrast [default = 80] +#define DISPLAYCYCLE 3 // Auto page flip delay in sec [default = 2] for devices without button +#define HOMECYCLE 30 // house keeping cycle in seconds [default = 30 secs] + +// Settings for BME680 environmental sensor +#define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C] +#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day +#define BMECYCLE 1 // bme sensor read cycle in seconds [default = 1 secs] + +// OTA settings +#define USE_OTA 1 // set to 0 to disable OTA update +#define WIFI_MAX_TRY 5 // maximum number of wifi connect attempts for OTA update [default = 20] +#define OTA_MAX_TRY 5 // maximum number of attempts for OTA download and write to flash [default = 3] +#define OTA_MIN_BATT 50 // minimum battery level for OTA [percent] +#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] + +// settings for syncing time of node with a time source (network / gps / rtc / timeserver) +#define TIME_SYNC_LORAWAN 1 // set to 1 to use LORA network as time source, 0 means off [default = 1] +#define TIME_SYNC_LORASERVER 0 // set to 1 to use LORA timeserver as time source, 0 means off [default = 0] +#define TIME_SYNC_INTERVAL 60 // sync time attempt each .. minutes from time source [default = 60], 0 means off +#define TIME_SYNC_INTERVAL_RETRY 10 // retry time sync after lost sync each .. minutes [default = 10], 0 means off +#define TIME_SYNC_SAMPLES 1 // number of time requests for averaging, max. 255 +#define TIME_SYNC_CYCLE 60 // delay between two time samples [seconds] +#define TIME_SYNC_TIMEOUT 400 // timeout waiting for timeserver answer [seconds] +#define TIME_SYNC_COMPILEDATE 0 // set to 1 to use compile date to initialize RTC after power outage [default = 0] + +// time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino +#define DAYLIGHT_TIME {"CEST", Last, Sun, Mar, 2, 120} // Central European Summer Time +#define STANDARD_TIME {"CET ", Last, Sun, Oct, 3, 60} // Central European Standard Time + +// Ports on which the device sends and listenes on LoRaWAN and SPI +#define COUNTERPORT 1 // counts +#define MACPORT 0 // network commands +#define RCMDPORT 2 // remote commands +#define STATUSPORT 2 // remote command results +#define CONFIGPORT 3 // config query results +#define GPSPORT 4 // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload +#define BUTTONPORT 5 // button pressed signal +#define BEACONPORT 6 // beacon alarms +#define BMEPORT 7 // BME680 sensor +#define BATTPORT 8 // battery voltage +#define TIMEPORT 9 // time query and response +#define SENSOR1PORT 10 // user sensor #1 +#define SENSOR2PORT 11 // user sensor #2 +#define SENSOR3PORT 12 // user sensor #3 + +// Cayenne LPP Ports, see https://community.mydevices.com/t/cayenne-lpp-2-0/7510 +#define CAYENNE_LPP1 1 // dynamic sensor payload (LPP 1.0) +#define CAYENNE_LPP2 2 // packed sensor payload (LPP 2.0) +#define CAYENNE_GPS 3 // full scale GPS payload +#define CAYENNE_ACTUATOR 10 // actuator commands +#define CAYENNE_DEVICECONFIG 11 // device period configuration +#define CAYENNE_SENSORREAD 13 // sensor period configuration +#define CAYENNE_SENSORENABLE 14 // sensor enable configuration \ No newline at end of file From 09ce8751033f5fc2f4f0400c44273bc7731f618f Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Sun, 27 Sep 2020 23:19:01 +0200 Subject: [PATCH 06/21] Delete platformio.ini --- platformio.ini | 135 ------------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 platformio.ini diff --git a/platformio.ini b/platformio.ini deleted file mode 100644 index d2669781..00000000 --- a/platformio.ini +++ /dev/null @@ -1,135 +0,0 @@ -; PlatformIO Project Configuration File -; NOTE: PlatformIO v4 is needed! -; -; Please visit documentation for the other options and examples -; http://docs.platformio.org/page/projectconf.html - - -; ---> SELECT THE TARGET PLATFORM HERE! <--- -[board] -;halfile = generic.h -;halfile = ebox.h -;halfile = eboxtube.h -;halfile = ecopower.h -;halfile = heltec.h -;halfile = heltecv2.h -;halfile = ttgov1.h -;halfile = ttgov2.h -;halfile = ttgov21old.h -halfile = ttgov21new.h -;halfile = ttgofox.h -;halfile = ttgobeam.h -;halfile = ttgobeam10.h -;halfile = fipy.h -;halfile = lopy.h -;halfile = lopy4.h -;halfile = lolin32litelora.h -;halfile = lolin32lora.h -;halfile = lolin32lite.h -;halfile = wemos32oled.h -;halfile = wemos32matrix.h -;halfile = octopus32.h -;halfile = tinypico.h -;halfile = tinypicomatrix.h -;halfile = m5core.h -;halfile = m5fire.h -;halfile = olimexpoeiso.h - -[platformio] -; upload firmware to board with usb cable -default_envs = usb -; upload firmware to a jfrog bintray repository -;default_envs = ota -; use latest versions of libraries -;default_envs = dev -description = Paxcounter is a device for metering passenger flows in realtime. It counts how many mobile devices are around. - -[common] -; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 2.0.13 -; 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 = 3 -extra_scripts = pre:build.py -otakeyfile = ota.conf -lorakeyfile = loraconf.h -lmicconfigfile = lmic_config.h -platform_espressif32 = espressif32@2.0.0 -monitor_speed = 115200 -upload_speed = 115200 ; set by build.py and taken from hal file -display_library = ; set by build.py and taken from hal file -lib_deps_lora = - mcci-catena/MCCI LoRaWAN LMIC library @ ^3.2.0 -lib_deps_display = - bitbank2/OneBitDisplay @ 1.5.0 - ricmoo/QRCode @ ^0.0.1 - bodmer/TFT_eSPI @ ^2.2.20 -lib_deps_ledmatrix = - seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0 -lib_deps_rgbled = - roboticsbrno/SmartLeds @ ^1.2.1 -lib_deps_gps = - mikalhart/TinyGPSPlus @ ^1.0.2 -lib_deps_sensors = - adafruit/Adafruit Unified Sensor @ ^1.1.4 - adafruit/Adafruit BME280 Library @ ^2.1.0 - adafruit/Adafruit BMP085 Unified - boschsensortec/BSEC Software Library @ 1.5.1474 - https://github.com/ricki-z/SDS011.git -lib_deps_basic = - bblanchon/ArduinoJson @ <6 - jchristensen/Timezone @ ^1.2.4 - makuna/RTC @ ^2.3.5 - spacehuhn/SimpleButton - lewisxhe/AXP202X_Library @ ^1.1.2 - geeksville/esp32-micro-sdcard @ ^0.1.1 - 256dpi/MQTT @ ^2.4.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} - ${common.lib_deps_ledmatrix} -build_flags_basic = - -include "src/hal/${board.halfile}" - -include "src/paxcounter.conf" - -w - '-DCORE_DEBUG_LEVEL=${common.debug_level}' - '-DLOG_LOCAL_LEVEL=${common.debug_level}' - '-DPROGVERSION="${common.release_version}"' -build_flags_sensors = - -Llib/Bosch-BSEC/src/esp32/ - -lalgobsec -build_flags_all = - ${common.build_flags_basic} - ${common.build_flags_sensors} - -mfix-esp32-psram-cache-issue - -[env] -lib_ldf_mode = deep ; #632 Fixes compiler error with OneBitDisplay library -framework = arduino -board = ttgo-lora32-v21new -board_build.partitions = min_spiffs.csv -upload_speed = ${common.upload_speed} -;upload_port = COM8 -platform = ${common.platform_espressif32} -lib_deps = ${common.lib_deps_all} -build_flags = ${common.build_flags_all} -upload_protocol = ${common.upload_protocol} -extra_scripts = ${common.extra_scripts} -monitor_speed = ${common.monitor_speed} -monitor_filters = time, esp32_exception_decoder, default - -[env:ota] -upload_protocol = custom - -[env:usb] -upload_protocol = esptool - -[env:dev] -upload_protocol = esptool -build_type = debug -platform = https://github.com/platformio/platform-espressif32.git#develop -platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git From c739b548f9329030d8087229c7cd5883490c2eff Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Sun, 27 Sep 2020 23:21:06 +0200 Subject: [PATCH 07/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9de1ebf1..51a4ec96 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Compile time configuration is spread across several files. Before compiling the Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards. and rename to `platformio.ini` ## src/paxcounter_orig.conf -Edit `src/paxcounter.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Rename to `paxcounter.conf` +Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Rename to `paxcounter.conf` If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in `paxcounter.conf`. From 5a931f6495faebf08db8509713f3c8d6eac9843e Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Sun, 27 Sep 2020 23:23:08 +0200 Subject: [PATCH 08/21] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ff171159..fa273fab 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ src/loraconf.h src/ota.conf platformio.ini -src/paxcounter.conf \ No newline at end of file +src/paxcounter.conf From c9680e665e820ccc23618827957b88611bf9836c Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Sun, 27 Sep 2020 23:26:21 +0200 Subject: [PATCH 09/21] Delete paxcounter.conf --- src/paxcounter.conf | 122 -------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 src/paxcounter.conf diff --git a/src/paxcounter.conf b/src/paxcounter.conf deleted file mode 100644 index e82d6adb..00000000 --- a/src/paxcounter.conf +++ /dev/null @@ -1,122 +0,0 @@ -// clang-format off - -// ----- Paxcounter user config file ------ -// -// --> adapt to your needs and use case <-- -// -// Note: After editing, before "build", use "clean" button in PlatformIO! - -// Verbose enables additional serial debug output -#define VERBOSE 1 // set to 0 to silence the device, for mute use build option - -// Payload send cycle and encoding -#define SENDCYCLE 30 // payload send cycle [seconds/2], 0 .. 255 -#define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed -#define COUNTERMODE 1 // 0=cyclic, 1=cumulative, 2=cyclic confirmed - -// Set this to include BLE counting and vendor filter functions, or to switch off WIFI counting -#define VENDORFILTER 0 // set to 0 if you want to scan all devices, not filtering smartphone OUIs -#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer -#define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer - -// BLE scan parameters -#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below -#define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms -#define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle - -// Corona Exposure Notification Service(ENS) counter -#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service - // set to 0 if you do not want to enable this function - -// for additional sensors (added by some user) -#define HAS_SENSOR_1 1 // set to 1 if you want to transmit CWA counter -#define HAS_SENSOR_2 0 // not used -#define HAS_SENSOR_3 0 // not used -#define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) // to simplify things - -/* Note: guide for setting bluetooth parameters -* -* |< Scan Window > |< Scan Window > | ... |< Scan Window > | -* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >| -* |< Scan duration >| -* -* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default). -* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL. -* Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising. -* -> Adjust these values with power consumption in mind if power is limited. -* -> Scan interval can be changed during runtime by remote comammand. -*/ - -// WiFi scan parameters -#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings -#define WIFI_CHANNEL_MAX 13 // total channel number to scan -#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings -#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. - -// LoRa payload default parameters -#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle -#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results -#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit -#define PAYLOAD_OPENSENSEBOX 0 // send payload compatible to sensebox.de (swap geo position and pax data) -#define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5] -#define LORATXPOWDEFAULT 14 // 0 .. 255, LoRaWAN TX power in dBm [default = 14] -#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy -#define SEND_QUEUE_SIZE 10 // maximum number of messages in payload send queue [1 = no queue] - -// Hardware settings -#define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%] -#define DISPLAYREFRESH_MS 40 // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second -#define DISPLAYCONTRAST 80 // 0 .. 255, OLED display contrast [default = 80] -#define DISPLAYCYCLE 3 // Auto page flip delay in sec [default = 2] for devices without button -#define HOMECYCLE 30 // house keeping cycle in seconds [default = 30 secs] - -// Settings for BME680 environmental sensor -#define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C] -#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day -#define BMECYCLE 1 // bme sensor read cycle in seconds [default = 1 secs] - -// OTA settings -#define USE_OTA 1 // set to 0 to disable OTA update -#define WIFI_MAX_TRY 5 // maximum number of wifi connect attempts for OTA update [default = 20] -#define OTA_MAX_TRY 5 // maximum number of attempts for OTA download and write to flash [default = 3] -#define OTA_MIN_BATT 50 // minimum battery level for OTA [percent] -#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] - -// settings for syncing time of node with a time source (network / gps / rtc / timeserver) -#define TIME_SYNC_LORAWAN 1 // set to 1 to use LORA network as time source, 0 means off [default = 1] -#define TIME_SYNC_LORASERVER 0 // set to 1 to use LORA timeserver as time source, 0 means off [default = 0] -#define TIME_SYNC_INTERVAL 60 // sync time attempt each .. minutes from time source [default = 60], 0 means off -#define TIME_SYNC_INTERVAL_RETRY 10 // retry time sync after lost sync each .. minutes [default = 10], 0 means off -#define TIME_SYNC_SAMPLES 1 // number of time requests for averaging, max. 255 -#define TIME_SYNC_CYCLE 60 // delay between two time samples [seconds] -#define TIME_SYNC_TIMEOUT 400 // timeout waiting for timeserver answer [seconds] -#define TIME_SYNC_COMPILEDATE 0 // set to 1 to use compile date to initialize RTC after power outage [default = 0] - -// time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino -#define DAYLIGHT_TIME {"CEST", Last, Sun, Mar, 2, 120} // Central European Summer Time -#define STANDARD_TIME {"CET ", Last, Sun, Oct, 3, 60} // Central European Standard Time - -// Ports on which the device sends and listenes on LoRaWAN and SPI -#define COUNTERPORT 1 // counts -#define MACPORT 0 // network commands -#define RCMDPORT 2 // remote commands -#define STATUSPORT 2 // remote command results -#define CONFIGPORT 3 // config query results -#define GPSPORT 4 // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload -#define BUTTONPORT 5 // button pressed signal -#define BEACONPORT 6 // beacon alarms -#define BMEPORT 7 // BME680 sensor -#define BATTPORT 8 // battery voltage -#define TIMEPORT 9 // time query and response -#define SENSOR1PORT 10 // user sensor #1 -#define SENSOR2PORT 11 // user sensor #2 -#define SENSOR3PORT 12 // user sensor #3 - -// Cayenne LPP Ports, see https://community.mydevices.com/t/cayenne-lpp-2-0/7510 -#define CAYENNE_LPP1 1 // dynamic sensor payload (LPP 1.0) -#define CAYENNE_LPP2 2 // packed sensor payload (LPP 2.0) -#define CAYENNE_GPS 3 // full scale GPS payload -#define CAYENNE_ACTUATOR 10 // actuator commands -#define CAYENNE_DEVICECONFIG 11 // device period configuration -#define CAYENNE_SENSORREAD 13 // sensor period configuration -#define CAYENNE_SENSORENABLE 14 // sensor enable configuration From 9c8b41105e33e71e2adc3566bbf710db295c0176 Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Mon, 28 Sep 2020 22:17:59 +0200 Subject: [PATCH 10/21] Update paxcounter_orig.conf remade original settings --- src/paxcounter_orig.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index 7cded6cf..653893ed 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -16,7 +16,7 @@ // Set this to include BLE counting and vendor filter functions, or to switch off WIFI counting #define VENDORFILTER 0 // set to 0 if you want to scan all devices, not filtering smartphone OUIs -#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer +#define BLECOUNTER 0 // set to 0 if you do not want to install the BLE sniffer #define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer // BLE scan parameters @@ -25,11 +25,11 @@ #define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle // Corona Exposure Notification Service(ENS) counter -#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service +#define COUNT_ENS 0 // count found number of devices which advertise Exposure Notification Service // set to 0 if you do not want to enable this function // for additional sensors (added by some user) -#define HAS_SENSOR_1 1 // set to 1 if you want to transmit CWA counter +#define HAS_SENSOR_1 0 // set to 1 if you want to transmit CWA counter #define HAS_SENSOR_2 0 // not used #define HAS_SENSOR_3 0 // not used #define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) // to simplify things @@ -119,4 +119,4 @@ #define CAYENNE_ACTUATOR 10 // actuator commands #define CAYENNE_DEVICECONFIG 11 // device period configuration #define CAYENNE_SENSORREAD 13 // sensor period configuration -#define CAYENNE_SENSORENABLE 14 // sensor enable configuration \ No newline at end of file +#define CAYENNE_SENSORENABLE 14 // sensor enable configuration From 84f94516e87f05b8f39f9c907cc32f7b969d4665 Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Mon, 28 Sep 2020 22:29:15 +0200 Subject: [PATCH 11/21] Update platformio_orig.ini added newline at the end of file. --- platformio_orig.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 00c89342..695b6435 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -132,4 +132,4 @@ upload_protocol = esptool upload_protocol = esptool build_type = debug platform = https://github.com/platformio/platform-espressif32.git#develop -platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git \ No newline at end of file +platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git From 9c2b8db36fe1325894a07623fdfadf91641b2797 Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Mon, 28 Sep 2020 22:44:45 +0200 Subject: [PATCH 12/21] Update README.md desired changes applied --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 51a4ec96..ef460b2a 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ By default bluetooth sniffing not installed (#define *BLECOUNTER* 0 in paxcounte Compile time configuration is spread across several files. Before compiling the code, edit or create the following files: ## platformio_orig.ini -Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections boards. and rename to `platformio.ini` +Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections board. Rename to `platformio.ini` ## src/paxcounter_orig.conf Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Rename to `paxcounter.conf` @@ -480,7 +480,7 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat 0x14 set payload mask - byte 1 = sensor data payload mask (0..255, meaning of bits see above) + byte 1 = sensor data payload mask (0..255, meaning of bits see below) 0x01 = GPS_DATA 0x02 = ALARM_DATA 0x04 = MEMS_DATA From 0a510a0c33b64ef360a43d4e01a5fc0d3f1440f0 Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Tue, 29 Sep 2020 18:59:53 +1300 Subject: [PATCH 13/21] Improved time synch handling for GPS based time This will update the time from GPS on first valid time received by GPS. --- src/gpsread.cpp | 16 ++++------------ src/main.cpp | 5 ----- src/timekeeper.cpp | 12 +++++------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 650c5866..78683b7a 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -21,9 +21,6 @@ static uint16_t nmea_txDelay_ms = static uint16_t nmea_txDelay_ms = 0; #endif -// did the last packet contain a valid time? -bool hasValidTime = false; - // initialize and configure GPS int gps_init(void) { @@ -163,16 +160,11 @@ void gps_loop(void *pvParameters) { } #endif -#if !TIME_SYNC_LORASERVER && !TIME_SYNC_LORAWAN - if (!hasValidTime) { - if (gpstime.isUpdated() && gpstime.isValid()) { - hasValidTime = true; - if (timeSource == _unsynced) { - calibrateTime(); - } - } + // if time hasn't been synchronised yet, and we have a valid GPS time, + // update time from GPS. + if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid()) { + calibrateTime(); } -#endif } // if diff --git a/src/main.cpp b/src/main.cpp index e7b497c7..175e78f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -488,11 +488,6 @@ void setup() { #warning you did not specify a time source, time will not be synched #endif -// initialize gps time -#if (HAS_GPS) - get_gpstime(); -#endif - #if (defined HAS_IF482 || defined HAS_DCF77) ESP_LOGI(TAG, "Starting Clock Controller..."); clock_init(); diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 01777be7..0dba7caa 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -32,7 +32,7 @@ void calibrateTime(void) { uint16_t t_msec = 0; // kick off asychronous lora timesync if we have -#if (HAS_LORA) && (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) +#if (HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN)) timesync_request(); #endif @@ -44,19 +44,17 @@ void calibrateTime(void) { // has RTC -> fallback to RTC time #ifdef HAS_RTC t = get_rtctime(); - timeSource = _rtc; + // set time from RTC + setMyTime((uint32_t)t, t_msec, _rtc); #endif // no RTC -> fallback to GPS time #if (HAS_GPS) t = get_gpstime(&t_msec); - if (t) { - timeSource = _gps; - } + // set time from GPS - method will check if time is valid + setMyTime((uint32_t)t, t_msec, _gps); #endif - setMyTime((uint32_t)t, t_msec, timeSource); // set time - } // fallback else From 0d4cc0372db2265d20e4bbba2cfe1e5ca83422c6 Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Tue, 29 Sep 2020 08:00:22 +0200 Subject: [PATCH 14/21] Update loarconf_sample_h --- src/loarconf_sample_h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loarconf_sample_h b/src/loarconf_sample_h index d3dfb08c..3b7d9cb2 100644 --- a/src/loarconf_sample_h +++ b/src/loarconf_sample_h @@ -85,4 +85,4 @@ void setABPParameters(); #endif // HAS_LORA -#endif // __LORACONF_H__ \ No newline at end of file +#endif // __LORACONF_H__ From 50b0e8cb0dc475addcb0f559d754152a5ff8bcac Mon Sep 17 00:00:00 2001 From: Christoph Schultz Date: Tue, 29 Sep 2020 08:05:41 +0200 Subject: [PATCH 15/21] Rename loarconf_sample_h to loarconf_sample.h --- src/{loarconf_sample_h => loarconf_sample.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{loarconf_sample_h => loarconf_sample.h} (100%) diff --git a/src/loarconf_sample_h b/src/loarconf_sample.h similarity index 100% rename from src/loarconf_sample_h rename to src/loarconf_sample.h From c1c7ae4de885d611387563e456225726ff40bf63 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 17:27:30 +0200 Subject: [PATCH 16/21] readme.md corrections --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef460b2a..58d59d7d 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ By default bluetooth sniffing not installed (#define *BLECOUNTER* 0 in paxcounte Compile time configuration is spread across several files. Before compiling the code, edit or create the following files: ## platformio_orig.ini -Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections board. Rename to `platformio.ini` +Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections board. Copy or rename to `platformio.ini`. ## src/paxcounter_orig.conf -Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Rename to `paxcounter.conf` +Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Copy or rename to `paxcounter.conf`. If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in `paxcounter.conf`. @@ -97,11 +97,10 @@ If your device has a **real time clock** it can be updated bei either LoRaWAN ne Edit `src/lmic_config.h` and tailor settings in this file according to your country and device hardware. Please take care of national regulations when selecting the frequency band for LoRaWAN. ## src/loraconf.h -Create file `src/loraconf.h` using the template [src/loraconf.sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf.sample.h) and modify it, to use your personal values. -To join the network and activate your paxcounter, you have to configure either the preferred OTAA method or the ABP method. You should use OTAA, whenever possible. To understand the differences of the two methods, [this article](https://www.thethingsnetwork.org/docs/devices/registration.html) may be useful. +Create file `src/loraconf.h` using the template [src/loraconf_sample.h](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/loraconf_sample.h) and adjust settings to use your personal values. To join the network and activate your paxcounter, you must configure either OTAA or ABP join method. You should use OTAA, whenever possible. To understand the differences of the two methods, [this article](https://www.thethingsnetwork.org/docs/devices/registration.html) may be useful. To configure OTAA, leave `#define LORA_ABP` deactivated (commented). To use ABP, activate (uncomment) `#define LORA_ABP` in the file `src/loraconf.h`. -The file `src/loraconf.h.sample` contains more information about the values to provide. +The file `src/loraconf_sample.h` contains more information about the values to provide. ## src/ota.conf Create file `src/ota.conf` using the template [src/ota.sample.conf](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/src/ota.sample.conf) and enter your WIFI network&key. These settings are used for downloading updates. If you want to push own OTA updates you need a Bintray account. Enter your Bintray user account data in ota.conf. If you don't need wireless firmware updates just rename ota.sample.conf to ota.conf. From 73104cafeb55f4bce48d63d32906c19659079e47 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 17:27:52 +0200 Subject: [PATCH 17/21] gpsread.cpp: comments edited --- src/gpsread.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 78683b7a..5589f4b2 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -6,8 +6,11 @@ // Local logging tag static const char TAG[] = __FILE__; -// we use NMEA $GPZDA sentence field 1 for time synchronization -// $GPZDA gives time for preceding pps pulse, but does not has a constant offset +// we use NMEA ZDA sentence field 1 for time synchronization +// ZDA gives time for preceding pps pulse +// downsight is that it does not have a constant offset +// thus precision is only +/- 1 second + TinyGPSPlus gps; TinyGPSCustom gpstime(gps, "GPZDA", 1); // field 1 = UTC time static const String ZDA_Request = "$EIGPQ,ZDA*39\r\n"; @@ -95,7 +98,7 @@ time_t get_gpstime(uint16_t *msec) { time_t time_sec = 0; - // poll NMEA $GPZDA sentence + // poll NMEA ZDA sentence #ifdef GPS_SERIAL GPS_Serial.print(ZDA_Request); // wait for gps NMEA answer From 8a8d3a8f1ab6ec54a94f472811b471c6dbb9018d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 17:28:10 +0200 Subject: [PATCH 18/21] rename loraconf_sample.h --- src/{loarconf_sample.h => loraconf_sample.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{loarconf_sample.h => loraconf_sample.h} (100%) diff --git a/src/loarconf_sample.h b/src/loraconf_sample.h similarity index 100% rename from src/loarconf_sample.h rename to src/loraconf_sample.h From 3b66add7d1a42af908045b9e00a2326fd49f2776 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 17:28:27 +0200 Subject: [PATCH 19/21] timekeeper.cpp: comments edited --- src/timekeeper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 0dba7caa..21513a05 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -44,7 +44,7 @@ void calibrateTime(void) { // has RTC -> fallback to RTC time #ifdef HAS_RTC t = get_rtctime(); - // set time from RTC + // set time from RTC - method will check if time is valid setMyTime((uint32_t)t, t_msec, _rtc); #endif From 026a243fb0c93345189949fb1ca13d923681ed17 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 17:36:49 +0200 Subject: [PATCH 20/21] v2.0.15 --- README.md | 2 +- platformio_orig.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58d59d7d..93b11a8d 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Compile time configuration is spread across several files. Before compiling the Edit `platformio_orig.ini` and select desired hardware target in section boards. To add a new board, create an appropriate hardware abstraction layer file in hal subdirectory, and add a pointer to this file in sections board. Copy or rename to `platformio.ini`. ## src/paxcounter_orig.conf -Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Copy or rename to `paxcounter.conf`. +Edit `src/paxcounter_orig.conf` and tailor settings in this file according to your needs and use case. Please take care of the duty cycle regulations of the LoRaWAN network you're going to use. Copy or rename to `src/paxcounter.conf`. If your device has a **real time clock** it can be updated bei either LoRaWAN network or GPS time, according to settings *TIME_SYNC_INTERVAL* and *TIME_SYNC_LORAWAN* in `paxcounter.conf`. diff --git a/platformio_orig.ini b/platformio_orig.ini index 695b6435..0edbc702 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -46,7 +46,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 2.0.12 +release_version = 2.0.15 ; 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 = 3 From 25ef6a5eca0c5675e013f99c66c064aeea70a0ef Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Sep 2020 22:06:31 +0200 Subject: [PATCH 21/21] paxcounter_orig.conf indents corrected --- src/paxcounter_orig.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index 653893ed..a174d819 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -25,11 +25,11 @@ #define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle // Corona Exposure Notification Service(ENS) counter -#define COUNT_ENS 0 // count found number of devices which advertise Exposure Notification Service +#define COUNT_ENS 0 // count found number of devices which advertise Exposure Notification Service // set to 0 if you do not want to enable this function // for additional sensors (added by some user) -#define HAS_SENSOR_1 0 // set to 1 if you want to transmit CWA counter +#define HAS_SENSOR_1 0 // set to 1 if you want to transmit CWA counter #define HAS_SENSOR_2 0 // not used #define HAS_SENSOR_3 0 // not used #define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) // to simplify things