diff --git a/README.md b/README.md
index d6cda4ba..e46e991c 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)**
+
@@ -410,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
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 9a7570bb..ad4f16a7 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -5,103 +5,43 @@
; http://docs.platformio.org/page/projectconf.html
-; ---> SELECT TARGET PLATFORM HERE! <---
+; ---> SELECT THE TARGET PLATFORM HERE! <---
[board]
+halfile = generic.h
;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 = ttgobeam.h
;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
-
[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.
+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 = 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
@@ -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
@@ -124,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}
@@ -137,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}"
@@ -154,8 +97,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 +116,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/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/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
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