make OTA selectable

This commit is contained in:
Klaus K Wilting committed 2018-09-24 16:36:11 +02:00
1 parent c713b0a0e0
commit c7445f0a1e
7 files changed
+24 -10

No files matched your search

+3
View File
@@ -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
+7 -5
View File
@@ -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
+5 -1
View File
@@ -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
+1
View File
@@ -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]
+6 -1
View File
@@ -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)");
}