From c7445f0a1ef0c67bc2268b1b2b3fade39e4b8666 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 24 Sep 2018 16:36:11 +0200 Subject: [PATCH] make OTA selectable --- build.py | 3 +-- platformio.ini | 2 +- src/main.cpp | 3 +++ src/ota.cpp | 12 +++++++----- src/ota.h | 6 +++++- src/paxcounter.conf | 1 + src/rcommand.cpp | 7 ++++++- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/build.py b/build.py index ed222a04..7f2c3a28 100644 --- a/build.py +++ b/build.py @@ -90,5 +90,4 @@ def publish_bintray(source, target, env): # put build file name and upload command to platformio environment env.Replace( PROGNAME="firmware_" + package + "_v%s" % version, - UPLOADCMD=publish_bintray -) \ No newline at end of file + UPLOADCMD=publish_bintray) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 6712dd22..b795bf33 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.5.5 +release_version = 1.5.6 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 0 diff --git a/src/main.cpp b/src/main.cpp index 3022f63c..26ba304b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,12 +143,15 @@ void setup() { batt_voltage = read_voltage(); #endif +#ifdef USE_OTA + strcat_P(features, " OTA"); // reboot to firmware update mode if ota trigger switch is set if (cfg.runmode == 1) { cfg.runmode = 0; saveConfig(); start_ota_update(); } +#endif // initialize button #ifdef HAS_BUTTON diff --git a/src/ota.cpp b/src/ota.cpp index 6c0a9471..15ef87b5 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -1,3 +1,5 @@ +#ifdef USE_OTA + /* Parts of this code: Copyright (c) 2014-present PlatformIO @@ -17,7 +19,6 @@ #include "ota.h" -#include using namespace std; const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE); @@ -250,10 +251,10 @@ void do_ota_update() { size_t written, current, size; if (Update.begin(contentLength)) { - +#ifdef HAS_DISPLAY // register callback function for showing progress while streaming data Update.onProgress(&show_progress); - +#endif int i = FLASH_MAX_TRY; while ((i--) && (written != contentLength)) { @@ -311,7 +312,7 @@ void do_ota_update() { client.stop(); } // do_ota_update -void display(const uint8_t row, std::string status, std::string msg) { +void display(const uint8_t row, const std::string status, const std::string msg) { #ifdef HAS_DISPLAY u8x8.setCursor(14, row); u8x8.print((status.substr(0, 2)).c_str()); @@ -320,7 +321,6 @@ void display(const uint8_t row, std::string status, std::string msg) { u8x8.setCursor(0, 7); u8x8.print(msg.substr(0, 16).c_str()); } -#endif } // callback function to show download progress while streaming data @@ -328,6 +328,7 @@ void show_progress(size_t current, size_t size) { char buf[17]; snprintf(buf, 17, "%-9lu (%3lu%%)", current, current * 100 / size); display(4, "**", buf); +#endif } // helper function to compare two versions. Returns 1 if v2 is @@ -364,3 +365,4 @@ int version_compare(const String v1, const String v2) { } return 0; } +#endif // USE_OTA \ No newline at end of file diff --git a/src/ota.h b/src/ota.h index e426bb15..59c1e464 100644 --- a/src/ota.h +++ b/src/ota.h @@ -1,6 +1,8 @@ #ifndef OTA_H #define OTA_H +#ifdef USE_OTA + #include "globals.h" #include "update.h" #include @@ -12,6 +14,8 @@ void do_ota_update(); void start_ota_update(); int version_compare(const String v1, const String v2); void show_progress(size_t current, size_t size); -void display(const uint8_t row, std::string status, std::string msg); +void display(const uint8_t row, const std::string status, const std::string msg); + +#endif // USE_OTA #endif // OTA_H diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 7e8f5a5e..28264cb8 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -66,6 +66,7 @@ #define HOMECYCLE 30 // house keeping cycle in seconds [default = 30 secs] // OTA settings +#define USE_OTA 1 // Comment out to disable OTA update #define WIFI_MAX_TRY 20 // maximum number of wifi connect attempts for OTA update [default = 20] #define FLASH_MAX_TRY 3 // maximum number of attempts for writing update binary to flash [default = 3] #define OTA_MIN_BATT 3700 // minimum battery level vor OTA [millivolt] diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 994b0f44..42e855a9 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -18,7 +18,7 @@ void set_reset(uint8_t val[]) { case 1: // reset MAC counter ESP_LOGI(TAG, "Remote command: reset MAC counter"); reset_counters(); // clear macs - get_salt(); // get new salt + get_salt(); // get new salt sprintf(display_line6, "Reset counter"); break; case 2: // reset device to factory settings @@ -33,9 +33,14 @@ void set_reset(uint8_t val[]) { break; case 9: // reset and ask for software update via Wifi OTA ESP_LOGI(TAG, "Remote command: software update via Wifi"); +#ifdef USE_OTA sprintf(display_line6, "Software update"); cfg.runmode = 1; +#else + sprintf(display_line6, "Software update not implemented"); +#endif // USE_OTA break; + default: ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)"); }