From cb2cc8c0072126b3b64682968f907dbbe9f6682e Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 29 Jun 2019 17:16:16 +0200 Subject: [PATCH 1/6] Update platformio.ini --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9a7570bb..30c7cf3f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -90,12 +90,12 @@ upload_speed = 921600 [platformio] ; upload firmware to board with usb cable -;default_envs = usb +default_envs = usb ; upload firmware to a jfrog bintray repository ;default_envs = ota -default_envs = dev +;default_envs = dev build_cache_dir = /tmp/platformio-shared-cache description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. From 20adc016b81c2c99ff31cf688f79460be358bec7 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 29 Jun 2019 19:02:54 +0200 Subject: [PATCH 2/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d6cda4ba..f695b74f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Tutorial (in german language): https://www.heise.de/select/make/2019/1/1551099236518668 +**IMPORTANT: MUST USE PLATFORMIO V4 (not v3.x)** + From 197e2d0e8066fd8c2fd068c23ea310fa86536cdd Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 30 Jun 2019 17:48:24 +0200 Subject: [PATCH 3/6] new hal file selection concept --- build.py | 16 +++++- platformio.ini | 109 +++++++++----------------------------- src/hal/ebox.h | 2 + src/hal/eboxtube.h | 3 ++ src/hal/ecopower.h | 2 + src/hal/fipy.h | 2 + src/hal/generic.h | 2 + src/hal/heltec.h | 3 +- src/hal/heltecv2.h | 2 + src/hal/lolin32lite.h | 2 + src/hal/lolin32litelora.h | 2 + src/hal/lolin32lora.h | 2 + src/hal/lopy.h | 2 + src/hal/lopy4.h | 2 + src/hal/octopus32.h | 2 + src/hal/ttgobeam.h | 2 + src/hal/ttgofox.h | 2 + src/hal/ttgov1.h | 2 + src/hal/ttgov2.h | 2 + src/hal/ttgov21new.h | 2 + src/hal/ttgov21old.h | 2 + src/hal/wemos32oled.h | 2 + 22 files changed, 81 insertions(+), 86 deletions(-) diff --git a/build.py b/build.py index cbe14c37..4235c8d7 100644 --- a/build.py +++ b/build.py @@ -1,5 +1,5 @@ # build.py -# pre-build script, setting up build environment +# pre-build script, setting up build environment and fetch hal file for user's board import sys import os @@ -55,8 +55,20 @@ if os.path.isfile(otakeyfile) and os.access(otakeyfile, os.R_OK): else: sys.exit("Missing file " + otakeyfile + ", please create it! Aborting.") -# parse ota key file +# parse hal file mykeys = {} +with open(halconfigfile) as myfile: + for line in myfile: + line2 = line.strip("// ") + key, value = line2.partition(" ")[::2] + mykeys[key.strip()] = str(value).strip() +myboard = mykeys["board"] +myuploadspeed = mykeys["upload_speed"] +env.Replace(BOARD=myboard) +env.Replace(UPLOAD_SPEED=myuploadspeed) +print '\033[94m' + "TARGET BOARD: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m' + +# parse ota key file with open(otakeyfile) as myfile: for line in myfile: key, value = line.partition("=")[::2] diff --git a/platformio.ini b/platformio.ini index 30c7cf3f..cddea030 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,88 +5,28 @@ ; http://docs.platformio.org/page/projectconf.html -; ---> SELECT TARGET PLATFORM HERE! <--- +; ---> SELECT THE TARGET PLATFORM HERE! <--- [board] -;halfile = ebox.h -;board = esp32dev -;upload_speed = 115200 - -;halfile = eboxtube.h -;board = esp32dev -;upload_speed = 115200 - -;halfile = ecopower.h -;board = esp32dev -;upload_speed = 921600 - -;halfile = heltec.h -;board = heltec_wifi_lora_32 -;upload_speed = 921600 - -;halfile = heltecv2.h -;board = heltec_wifi_lora_32_V2 -;upload_speed = 921600 - -;halfile = ttgov1.h -;board = ttgo-lora32-v1 -;upload_speed = 115200 - -;halfile = ttgov2.h -;board = ttgo-lora32-v1 -;upload_speed = 921600 - -;halfile = ttgov21old.h -;board = esp32dev -;upload_speed = 921600 - -;halfile = ttgov21new.h -;board = esp32dev -;upload_speed = 921600 - -;halfile = ttgofox.h -;board = esp32dev -;upload_speed = 921600 - -halfile = ttgobeam.h -board = ttgo-t-beam -upload_speed = 921600 - -;halfile = fipy.h -;board = esp32dev -;upload_speed = 921600 - -;halfile = lopy.h -;board = lopy -;upload_speed = 921600 - -;halfile = lopy4.h -;board = lopy4 -;upload_speed = 921600 - -;halfile = lolin32litelora.h -;board = lolin32 -;upload_speed = 921600 - -;halfile = lolin32lora.h -;board = lolin32 -;upload_speed = 921600 - -;halfile = lolin32lite.h -;board = lolin32 -;upload_speed = 921600 - -;halfile = wemos32oled.h -;board = lolin32 -;upload_speed = 921600 - -;halfile = octopus32.h -;board = featheresp32 -;upload_speed = 921600 - ;halfile = generic.h -;board = esp32dev -;upload_speed = 115200 - +;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 = fipy.h +;halfile = lopy.h +;halfile = lopy4.h +;halfile = lolin32litelora.h +;halfile = lolin32lora.h +;halfile = lolin32lite.h +;halfile = wemos32oled.h +;halfile = octopus32.h [platformio] ; upload firmware to board with usb cable @@ -97,7 +37,7 @@ default_envs = usb ;default_envs = dev build_cache_dir = /tmp/platformio-shared-cache -description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. +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" @@ -111,7 +51,9 @@ lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h platform_espressif32 = espressif32@1.9.0 board_build.partitions = min_spiffs.csv +board = esp32dev monitor_speed = 115200 +upload_speed = 115200 lib_deps_lora = ;MCCI LoRaWAN LMIC library@2.3.2 https://github.com/mcci-catena/arduino-lmic.git @@ -154,8 +96,8 @@ build_flags_all = -mfix-esp32-psram-cache-issue [env] -board = ${board.board} -upload_speed = ${board.upload_speed} +board = ${common.board} +upload_speed = ${common.upload_speed} platform = ${common.platform_espressif32} framework = arduino board_build.partitions = ${common.board_build.partitions} @@ -173,6 +115,7 @@ upload_protocol = esptool [env:dev] upload_protocol = esptool +build_type = debug platform = https://github.com/platformio/platform-espressif32.git#develop platform_packages = ; use upstream Git version diff --git a/src/hal/ebox.h b/src/hal/ebox.h index 6ebb93fc..ebd70136 100644 --- a/src/hal/ebox.h +++ b/src/hal/ebox.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 115200 +// board esp32dev #ifndef _EBOX_H #define _EBOX_H diff --git a/src/hal/eboxtube.h b/src/hal/eboxtube.h index 628e1a94..9278f0a6 100644 --- a/src/hal/eboxtube.h +++ b/src/hal/eboxtube.h @@ -1,4 +1,7 @@ // clang-format off +// upload_speed 115200 +// board esp32dev + #ifndef _EBOXTUBE_H #define _EBOXTUBE_H diff --git a/src/hal/ecopower.h b/src/hal/ecopower.h index 0a9d30af..4f4b303a 100644 --- a/src/hal/ecopower.h +++ b/src/hal/ecopower.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board esp32dev #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/fipy.h b/src/hal/fipy.h index 03ce818b..c59dff59 100644 --- a/src/hal/fipy.h +++ b/src/hal/fipy.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board esp32dev #ifndef _FIPY_H #define _FIPY_H diff --git a/src/hal/generic.h b/src/hal/generic.h index ae0c90bf..280a68ad 100644 --- a/src/hal/generic.h +++ b/src/hal/generic.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 115200 +// board esp32dev #ifndef _GENERIC_H #define _GENERIC_H diff --git a/src/hal/heltec.h b/src/hal/heltec.h index 6ec1a068..465793a1 100644 --- a/src/hal/heltec.h +++ b/src/hal/heltec.h @@ -1,5 +1,6 @@ - // clang-format off +// upload_speed 921600 +// board heltec_wifi_lora_32 #ifndef _HELTEC_H #define _HELTEC_H diff --git a/src/hal/heltecv2.h b/src/hal/heltecv2.h index 6a8dd36e..3f6bf743 100644 --- a/src/hal/heltecv2.h +++ b/src/hal/heltecv2.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board heltec_wifi_lora_32_V2 #ifndef _HELTECV2_H #define _HELTECV2_H diff --git a/src/hal/lolin32lite.h b/src/hal/lolin32lite.h index 3c3942e8..320372d8 100644 --- a/src/hal/lolin32lite.h +++ b/src/hal/lolin32lite.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lolin32 #ifndef _LOLINLITE_H #define _LOLINLITE_H diff --git a/src/hal/lolin32litelora.h b/src/hal/lolin32litelora.h index 8a13aa9c..79f9bb6b 100644 --- a/src/hal/lolin32litelora.h +++ b/src/hal/lolin32litelora.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lolin32 #ifndef _LOLINLITELORA_H #define _LOLINLITELORA_H diff --git a/src/hal/lolin32lora.h b/src/hal/lolin32lora.h index 4fb279e9..a6fa2f37 100644 --- a/src/hal/lolin32lora.h +++ b/src/hal/lolin32lora.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lolin32 #ifndef _LOLINLORA_H #define _LOLINLORA_H diff --git a/src/hal/lopy.h b/src/hal/lopy.h index 2cb99261..4bf50781 100644 --- a/src/hal/lopy.h +++ b/src/hal/lopy.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lopy #ifndef _LOPY_H #define _LOPY_H diff --git a/src/hal/lopy4.h b/src/hal/lopy4.h index a2be705c..321244e4 100644 --- a/src/hal/lopy4.h +++ b/src/hal/lopy4.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lopy4 #ifndef _LOPY4_H #define _LOPY4_H diff --git a/src/hal/octopus32.h b/src/hal/octopus32.h index ad4fbb07..c2bf3735 100644 --- a/src/hal/octopus32.h +++ b/src/hal/octopus32.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board featheresp32 #ifndef _OCTOPUS_H #define _OCTOPUS_H diff --git a/src/hal/ttgobeam.h b/src/hal/ttgobeam.h index 4fc218e1..d67a1db4 100644 --- a/src/hal/ttgobeam.h +++ b/src/hal/ttgobeam.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board ttgo-t-beam #ifndef _TTGOBEAM_H #define _TTGOBEAM_H diff --git a/src/hal/ttgofox.h b/src/hal/ttgofox.h index 133c5d04..94b2b60f 100644 --- a/src/hal/ttgofox.h +++ b/src/hal/ttgofox.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board esp32dev #ifndef _TTGOFOX_H #define _TTGOFOX_H diff --git a/src/hal/ttgov1.h b/src/hal/ttgov1.h index 176d0b19..fddc3ef5 100644 --- a/src/hal/ttgov1.h +++ b/src/hal/ttgov1.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 115200 +// board ttgo-lora32-v1 #ifndef _TTGOV1_H #define _TTGOV1_H diff --git a/src/hal/ttgov2.h b/src/hal/ttgov2.h index 35c98485..54f1657a 100644 --- a/src/hal/ttgov2.h +++ b/src/hal/ttgov2.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board ttgo-lora32-v1 #ifndef _TTGOV2_H #define _TTGOV2_H diff --git a/src/hal/ttgov21new.h b/src/hal/ttgov21new.h index 97967187..c50869b2 100644 --- a/src/hal/ttgov21new.h +++ b/src/hal/ttgov21new.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board esp32dev #ifndef _TTGOV21NEW_H #define _TTGOV21NEW_H diff --git a/src/hal/ttgov21old.h b/src/hal/ttgov21old.h index 3541dc76..0a7c386c 100644 --- a/src/hal/ttgov21old.h +++ b/src/hal/ttgov21old.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board esp32dev #ifndef _TTGOV21OLD_H #define _TTGOV21OLD_H diff --git a/src/hal/wemos32oled.h b/src/hal/wemos32oled.h index 3917dfea..49911a37 100644 --- a/src/hal/wemos32oled.h +++ b/src/hal/wemos32oled.h @@ -1,4 +1,6 @@ // clang-format off +// upload_speed 921600 +// board lolin32 #ifndef _WEMOS32OLED_H #define _WEMOS32OLED_H From f75d31fec19ff38eda560bfd1d5865816d6b83d3 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 6 Jul 2019 14:44:09 +0200 Subject: [PATCH 4/6] bugfix README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f695b74f..e46e991c 100644 --- a/README.md +++ b/README.md @@ -412,8 +412,8 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. bits 4..7 time status 0x00 = timeNotSet (never synched) - 0x10 = timeNeedsSync (last sync failed) - 0x20 = timeSet (synched) + 0x01 = timeNeedsSync (last sync failed) + 0x02 = timeSet (synched) 0x87 set time/date From 194ee9d81339219255465f34366949381fd85852 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 6 Jul 2019 15:52:11 +0200 Subject: [PATCH 5/6] platformio.ini updated --- platformio.ini | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index cddea030..31bf4769 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 @@ -18,7 +18,7 @@ ;halfile = ttgov21old.h ;halfile = ttgov21new.h ;halfile = ttgofox.h -halfile = ttgobeam.h +;halfile = ttgobeam.h ;halfile = fipy.h ;halfile = lopy.h ;halfile = lopy4.h @@ -66,12 +66,12 @@ lib_deps_rgbled = lib_deps_gps = 1655@>=1.0.2 ;TinyGPSPlus by Mikal Hart lib_deps_sensors = - Adafruit Unified Sensor@^1.0.3 - Adafruit BME280 Library@1.0.8 + Adafruit Unified Sensor@>=1.0.3 + Adafruit BME280 Library@>=1.0.9 lib_deps_basic = ArduinoJson@^5.13.1 - 76@^1.2.2 ;Timezone by Jack Christensen - 274@^2.3.3 ;RTC by Michael Miller + 76@>=1.2.2 ;Timezone by Jack Christensen + 274@>=2.3.3 ;RTC by Michael Miller SimpleButton lib_deps_all = ${common.lib_deps_basic} @@ -79,6 +79,7 @@ lib_deps_all = ${common.lib_deps_display} ${common.lib_deps_rgbled} ${common.lib_deps_gps} + ${common.lib_deps_sensors} ${common.lib_deps_matrix_display} build_flags_basic = -include "src/hal/${board.halfile}" From fbe0cf3b2ee4627bd1d0f1717426b7d5d80717b1 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 7 Jul 2019 16:00:48 +0200 Subject: [PATCH 6/6] bugfix no GPS time sync after cold start (#376) --- platformio.ini | 2 +- src/gpsread.cpp | 27 ++++++++++++++++----------- src/timekeeper.cpp | 6 ++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/platformio.ini b/platformio.ini index 31bf4769..ad4f16a7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,7 +41,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 = 1.7.71 +release_version = 1.7.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 = 3 diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 62aa2da2..142eef08 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -77,16 +77,24 @@ void gps_storelocation(gpsStatus_t &gps_store) { // store current GPS timedate in struct void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) { - gps_store.time_age = gps.time.age(); + if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) { - if (gps.time.isValid() && gps.date.isValid() && (gps_store.time_age < 1000)) { + /* nmea telegram serial delay compensation; not sure if we need this? + + if (gps.time.age() > nmea_txDelay_ms) + gps_store.timedate.Second = gps.time.second() + 1; + else + gps_store.timedate.Second = gps.time.second(); + */ + + gps_store.timedate.Second = gps.time.second(); + gps_store.timedate.Minute = gps.time.minute(); + gps_store.timedate.Hour = gps.time.hour(); + gps_store.timedate.Day = gps.date.day(); + gps_store.timedate.Month = gps.date.month(); gps_store.timedate.Year = CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h - gps_store.timedate.Month = gps.date.month(); - gps_store.timedate.Day = gps.date.day(); - gps_store.timedate.Hour = gps.time.hour(); - gps_store.timedate.Minute = gps.time.minute(); - gps_store.timedate.Second = gps.time.second(); + } else gps_store.timedate = {0}; } @@ -96,11 +104,8 @@ time_t get_gpstime(gpsStatus_t value) { time_t t = timeIsValid(makeTime(value.timedate)); - // if (t) - // t = value.time_age > nmea_txDelay_ms ? t : t - 1; - // show NMEA data in verbose mode, useful for debugging GPS - ESP_LOGV( + ESP_LOGD( TAG, "GPS time: %d | GPS NMEA data: passed %d / failed: %d / with fix: %d", t, gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix()); diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 99c72a4f..049e80aa 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -31,7 +31,7 @@ time_t timeProvider(void) { time_t t = 0; #if (HAS_GPS) - // fetch recent time from last NEMA record + // fetch recent time from last NMEA record t = get_gpstime(gps_pps_status); if (t) { #ifdef HAS_RTC @@ -140,9 +140,11 @@ void IRAM_ATTR CLOCKIRQ(void) { SyncToPPS(); // advance systime, see microTime.h - // store recent gps time, if we have gps + // store recent gps time, and try to get gps time if time is not synced #if (HAS_GPS) gps_storetime(gps_pps_status); + if (timeSource == _unsynced) + timeSync(); #endif // advance wall clock, if we have