From ada58df4685790572184bc47dbf740344cb3b56b Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 12 Mar 2021 23:42:46 +0100 Subject: [PATCH 1/6] readme.md update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a7f38b5..4ec9bdf7 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ The original Pycom firmware is not needed, so there is no need to update it befo After the ESP32 board is initially flashed and has joined a LoRaWAN network, the firmware can update itself by OTA. This process is kicked off by sending a remote control command (see below) via LoRaWAN to the board. The board then tries to connect via WiFi to a cloud service (JFrog Bintray), checks for update, and if available downloads the binary and reboots with it. If something goes wrong during this process, the board reboots back to the current version. Prerequisites for OTA are: 1. You own a Bintray repository, 2. you pushed the update binary to the Bintray repository, 3. internet access via encrypted (WPA2) WiFi is present at the board's site, 4. WiFi credentials were set in ota.conf and initially flashed to the board. Step 2 runs automated, just enter the credentials in ota.conf and set `upload_protocol = custom` in platformio.ini. Then press build and lean back watching platformio doing build and upload. - **over the air (OTA), upload via WiFi:** -If option *BOOTMENU* is defined in `paxcounter.conf`, the ESP32 board will try to connect to a known WiFi access point each time cold starting (after a power cycle or a reset), using the WiFi credentials given in `ota.conf`. Once connected to the WiFi it will fire up a simple webserver, providing a bootstrap menu waiting for a user interaction (pressing "START" button in menu). This process will be aborted by ESP32 hardware watchdog after *BOOTDELAY* seconds, ensuring booting the device to runmode. Once a user interaction in bootstrap menu was detected, the watchdog time will be extended to *BOOTTIMEOUT* seconds. During this time a firmware upload can be performed manually by user, e.g. using a smartphone in tethering mode providing the firmware upload file. +If option *BOOTMENU* is defined in `paxcounter.conf`, the ESP32 board will try to connect to a known WiFi access point each time cold starting (after a power cycle or a reset), using the WiFi credentials given in `ota.conf`. Once connected to the WiFi it will fire up a simple webserver, providing a bootstrap menu waiting for a user interaction (pressing "START" button in menu). This process will time out after *BOOTDELAY* seconds, ensuring booting the device to runmode. Once a user interaction in bootstrap menu was detected, the timeout will be extended to *BOOTTIMEOUT* seconds. During this time a firmware upload can be performed manually by user, e.g. using a smartphone in tethering mode providing the firmware upload file. # Legal note From 2e7e8e4ea7961a7a6bd2c357d817276e22d74ee0 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 17 Mar 2021 22:19:29 +0100 Subject: [PATCH 2/6] Update README.md issue #758 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4ec9bdf7..2d2ce588 100644 --- a/README.md +++ b/README.md @@ -532,14 +532,14 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat 0 ... 255 device sleep cycle in seconds/2 e.g. 120 -> device sleeps 240 seconds after each send cycle [default = 0] -0x20 store device configuration - - Current device runtime configuration is stored in NVRAM, will be reloaded after restart - -0x21 load device configuration +0x20 load device configuration Current device runtime configuration will be loaded from NVRAM, replacing current settings immediately (use with care!) +0x21 store device configuration + + Current device runtime configuration is stored in NVRAM, will be reloaded after restart + 0x80 get device configuration Device answers with it's current configuration on Port 3. From 7e4ddbeedd2aa240b618e0e1cfbfbce50731e5d0 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Mar 2021 11:41:15 +0100 Subject: [PATCH 3/6] upgrade platformio-esp32 (v3.1.1) --- platformio_orig.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index 9579ed46..3c55b8bb 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -57,8 +57,7 @@ extra_scripts = pre:build.py otakeyfile = ota.conf lorakeyfile = loraconf.h lmicconfigfile = lmic_config.h -;platform_espressif32 = espressif32@3.0.0 -platform_espressif32 = https://github.com/platformio/platform-espressif32.git#abc2bb9 +platform_espressif32 = espressif32@3.1.1 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 From 4bb8cdf2ca4e6781ae438d2447958fa1ee3e34df Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 19 Mar 2021 18:13:28 +0100 Subject: [PATCH 4/6] comment edit in paxcounter_orig.conf --- src/paxcounter_orig.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index 6fb52263..3440d8fc 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -126,7 +126,7 @@ #define CAYENNE_SENSORENABLE 14 // sensor enable configuration // MQTT settings, only needed if MQTT is used (#define HAS_MQTT in board hal file) -#define MQTT_ETHERNET 0 // select PHY: set 0 for Wifi, 1 for ethernet +#define MQTT_ETHERNET 1 // select PHY: set 0 for Wifi, 1 for ethernet (Wifi not yet implemented!) #define MQTT_INTOPIC "paxin" #define MQTT_OUTTOPIC "paxout" #define MQTT_PORT 1883 From 79b96a75c72022e3035df8e3500de74d62a05f2c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 20 Mar 2021 20:13:34 +0100 Subject: [PATCH 5/6] bugfix reset loop after OTA update --- src/reset.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/reset.cpp b/src/reset.cpp index 167af2f1..be940fe4 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -8,10 +8,13 @@ static const char TAG[] = __FILE__; // Conversion factor for micro seconds to seconds #define uS_TO_S_FACTOR 1000000ULL -// variables keep its values after a wakeup from sleep -RTC_NOINIT_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE; +// RTC_NOINIT_ATTR -> keep value after a software restart or system crash +RTC_NOINIT_ATTR runmode_t RTC_runmode; + +// RTC_DATA_ATTR -> keep values after a wakeup from sleep RTC_DATA_ATTR struct timeval RTC_sleep_start_time; RTC_DATA_ATTR unsigned long long RTC_millis = 0; + timeval sleep_stop_time; const char *runmode[6] = {"powercycle", "normal", "wakeup", @@ -46,8 +49,10 @@ void do_after_reset(void) { break; case SW_CPU_RESET: // 0x0c Software reset CPU - // keep previous runmode - // (i.e. RUNMODE_UPDATE or RUNMODE_MAINTENANCE) + // keep previous runmode, if RTC_runmode has valid value + // sets runmode, if RTC_runmode is invalid (i.e. not initialized) + if ((RTC_runmode != RUNMODE_UPDATE) && (RTC_runmode != RUNMODE_NORMAL)) + RTC_runmode = RUNMODE_POWERCYCLE; break; case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core From 9060ba2f4ce6c9b93b5ccafa7bbd76d6f186af8c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 20 Mar 2021 21:31:04 +0100 Subject: [PATCH 6/6] reset.h: RTC_runmode code sanitization --- include/boot.h | 1 + include/cyclic.h | 1 + include/globals.h | 1 - include/reset.h | 2 ++ 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/boot.h b/include/boot.h index 8aaf0d2a..128932c7 100644 --- a/include/boot.h +++ b/include/boot.h @@ -3,6 +3,7 @@ #include "globals.h" #include "hash.h" +#include "reset.h" #include #include diff --git a/include/cyclic.h b/include/cyclic.h index d40891af..8b16046c 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -11,6 +11,7 @@ #include "sds011read.h" #include "sdcard.h" #include "macsniff.h" +#include "reset.h" extern Ticker cyclicTimer; diff --git a/include/globals.h b/include/globals.h index fa958e4b..1930a3f5 100644 --- a/include/globals.h +++ b/include/globals.h @@ -148,6 +148,5 @@ extern SemaphoreHandle_t I2Caccess; extern TaskHandle_t irqHandlerTask, ClockTask, macProcessTask; extern TimerHandle_t WifiChanTimer; extern Timezone myTZ; -extern RTC_NOINIT_ATTR runmode_t RTC_runmode; #endif diff --git a/include/reset.h b/include/reset.h index ddf3dfcb..653164c0 100644 --- a/include/reset.h +++ b/include/reset.h @@ -15,4 +15,6 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, const gpio_num_t wakeup_gpio = GPIO_NUM_MAX); unsigned long long uptime(void); +extern RTC_NOINIT_ATTR runmode_t RTC_runmode; + #endif // _RESET_H \ No newline at end of file