make OTA selectable
This commit is contained in:
parent
c713b0a0e0
commit
c7445f0a1e
3
build.py
3
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
|
||||
)
|
||||
UPLOADCMD=publish_bintray)
|
@ -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
|
||||
|
@ -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
|
||||
|
12
src/ota.cpp
12
src/ota.cpp
@ -1,3 +1,5 @@
|
||||
#ifdef USE_OTA
|
||||
|
||||
/*
|
||||
Parts of this code:
|
||||
Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
@ -17,7 +19,6 @@
|
||||
|
||||
#include "ota.h"
|
||||
|
||||
#include <string>
|
||||
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
|
@ -1,6 +1,8 @@
|
||||
#ifndef OTA_H
|
||||
#define OTA_H
|
||||
|
||||
#ifdef USE_OTA
|
||||
|
||||
#include "globals.h"
|
||||
#include "update.h"
|
||||
#include <WiFi.h>
|
||||
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user