implement ota updater plus minor fixes
This commit is contained in:
@@ -29,13 +29,13 @@ void wifi_associate() {
|
|||||||
WifiManager.setConfigPortalTimeout(300); // If no configuration is done in 5 mins, exit/restart quietly
|
WifiManager.setConfigPortalTimeout(300); // If no configuration is done in 5 mins, exit/restart quietly
|
||||||
if (WifiManager.autoConnect(apname)) { // @@@FIXME@@@ we should really set a PSK for the AP (but in my brief testing it crashed the ESP, so what's up with that)
|
if (WifiManager.autoConnect(apname)) { // @@@FIXME@@@ we should really set a PSK for the AP (but in my brief testing it crashed the ESP, so what's up with that)
|
||||||
settings.ip = WiFi.localIP().toString();
|
settings.ip = WiFi.localIP().toString();
|
||||||
PRINTLN_SERIAL("Figured out my network \O/");
|
PRINTLN_SERIAL("Figured out my network \\O/");
|
||||||
|
|
||||||
//wificlient.setFingerprint(WTR_SHA1);
|
//wificlient.setFingerprint(WTR_SHA1);
|
||||||
net.setInsecure(); // Do not check fingerprint
|
net.setInsecure(); // Do not check fingerprint
|
||||||
net.setTimeout(15000); // 15 Seconds
|
net.setTimeout(15000); // 15 Seconds
|
||||||
|
|
||||||
PRINT_SERIAL("Setting time using SNTP");
|
/* PRINT_SERIAL("Setting time using SNTP");
|
||||||
configTime(-5 * 3600, 0, "pool.ntp.org", "time.nist.gov");
|
configTime(-5 * 3600, 0, "pool.ntp.org", "time.nist.gov");
|
||||||
now = time(nullptr);
|
now = time(nullptr);
|
||||||
while (now < 1510592825) {
|
while (now < 1510592825) {
|
||||||
@@ -47,7 +47,7 @@ void wifi_associate() {
|
|||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
gmtime_r(&now, &timeinfo);
|
gmtime_r(&now, &timeinfo);
|
||||||
PRINT_SERIAL("Current time: ");
|
PRINT_SERIAL("Current time: ");
|
||||||
APPENDLN_SERIAL(asctime(&timeinfo));
|
APPENDLN_SERIAL(asctime(&timeinfo)); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,22 +66,27 @@ void wifi_loop() {
|
|||||||
unsigned long ota_check = millis()/1000;
|
unsigned long ota_check = millis()/1000;
|
||||||
if((ota_lastcheck == 0) || ((ota_check - ota_lastcheck) > OTA_UPDATE_INTERVAL)) {
|
if((ota_lastcheck == 0) || ((ota_check - ota_lastcheck) > OTA_UPDATE_INTERVAL)) {
|
||||||
PRINTLN_SERIAL("Checking for OTA update");
|
PRINTLN_SERIAL("Checking for OTA update");
|
||||||
/*
|
|
||||||
// Check for firmware upgrades
|
// Check for firmware upgrades
|
||||||
t_httpUpdate_return ret = ESPhttpUpdate.update(wificlient, WTR_SERVER, WTR_SRVPORT, "/fw/", nodeversion);
|
String version = settings.name;
|
||||||
|
version.concat("-v");
|
||||||
|
version.concat(FW_VERSION);
|
||||||
|
t_httpUpdate_return ret = ESPhttpUpdate.update(net, OTA_SERVER, OTA_PORT, OTA_URI, version);
|
||||||
switch(ret) {
|
switch(ret) {
|
||||||
case HTTP_UPDATE_FAILED: // HTTP 403, 404
|
case HTTP_UPDATE_FAILED: // HTTP 403, 404
|
||||||
Serial.printf("Firmware upgrade available, but update failed (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
|
PRINT_SERIAL("Firmware upgrade available, but update failed ");
|
||||||
|
APPEND_SERIAL(" (ERR ");
|
||||||
|
APPEND_SERIAL(String(ESPhttpUpdate.getLastError()));
|
||||||
|
APPEND_SERIAL(") ");
|
||||||
|
APPENDLN_SERIAL(ESPhttpUpdate.getLastErrorString().c_str());
|
||||||
break;
|
break;
|
||||||
case HTTP_UPDATE_NO_UPDATES: // HTTP 304
|
case HTTP_UPDATE_NO_UPDATES: // HTTP 304
|
||||||
Serial.println("No firmware upgrade available");
|
PRINTLN_SERIAL("No firmware upgrade available");
|
||||||
break;
|
break;
|
||||||
case HTTP_UPDATE_OK: // HTTP 200
|
case HTTP_UPDATE_OK: // HTTP 200
|
||||||
Serial.println("Firmware upgrade available, upgraded ok."); // may not called we reboot the ESP
|
PRINTLN_SERIAL("Firmware upgrade available, upgraded ok."); // may not called we reboot the ESP
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
ota_lastcheck = ota_check;
|
ota_lastcheck = ota_check;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void setup() {
|
|||||||
// If we run in to trouble, this can painlessly be removed and the resulting device name will just be longer
|
// If we run in to trouble, this can painlessly be removed and the resulting device name will just be longer
|
||||||
settings.name.remove(devlen+1, 6);
|
settings.name.remove(devlen+1, 6);
|
||||||
|
|
||||||
PRINTLN_SERIAL("Figured out who I am \O/");
|
PRINTLN_SERIAL("Figured out who I am \\O/");
|
||||||
|
|
||||||
wifi_setup();
|
wifi_setup();
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ void setup() {
|
|||||||
moon_setup();
|
moon_setup();
|
||||||
#endif
|
#endif
|
||||||
// Start the cooperative scheduler loops
|
// Start the cooperative scheduler loops
|
||||||
PRINTLN_SERIAL("Done setting up, ready for main loop \O/");
|
PRINTLN_SERIAL("Done setting up, ready for main loop \\O/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// Implement versioning so that new firmware can be done OTA
|
// Implement versioning so that new firmware can be done OTA
|
||||||
|
|
||||||
// Todo:
|
// Todo:
|
||||||
// Split the wifi and mqtt code in order to support http interface
|
// maybe: loading settings on SPIFFS or similar so we can create more generic firmware? https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout
|
||||||
// Stay on the lookout for watchdog crashes, see also https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html#ESP8266_WDT_RECOV
|
// Stay on the lookout for watchdog crashes, see also https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html#ESP8266_WDT_RECOV
|
||||||
// Keeps crashing after a few days. Dunno why. https://www.pieterverhees.nl/sparklesagarbage/esp8266/130-difference-between-esp-reset-and-esp-restart
|
// Keeps crashing after a few days. Dunno why. https://www.pieterverhees.nl/sparklesagarbage/esp8266/130-difference-between-esp-reset-and-esp-restart
|
||||||
// More on this subject https://github.com/esp8266/Arduino/issues/1017
|
// More on this subject https://github.com/esp8266/Arduino/issues/1017
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
// v12: Refactored inbound commands to hook in to the modules (module_message function), completed assimilation of (never-published) Moon_Connected sketch
|
// v12: Refactored inbound commands to hook in to the modules (module_message function), completed assimilation of (never-published) Moon_Connected sketch
|
||||||
// v11: Simplified scheduler, back to cooperative looping
|
// v11: Simplified scheduler, back to cooperative looping
|
||||||
// v10: First 'production' run. MQTT over TLS, but no OTA support.
|
// v10: First 'production' run. MQTT over TLS, but no OTA support.
|
||||||
const int FW_VERSION = 13;
|
const int FW_VERSION = 14;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Configuration settings
|
// Configuration settings
|
||||||
|
|||||||
Reference in New Issue
Block a user