From 4a67d731f19d669eb111c3f07e9a9caee40e5c4a Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 16 Jan 2019 21:53:06 +0300 Subject: [PATCH] [ota] Implemented ArduinoOTA --- .../anavi-light-controller-sw.ino | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/anavi-light-controller-sw/anavi-light-controller-sw.ino b/anavi-light-controller-sw/anavi-light-controller-sw.ino index 0a13900..7f3253a 100644 --- a/anavi-light-controller-sw/anavi-light-controller-sw.ino +++ b/anavi-light-controller-sw/anavi-light-controller-sw.ino @@ -1,6 +1,7 @@ #include //this needs to be first, or it all crashes and burns... #include //https://github.com/esp8266/Arduino +#include //needed for library #include @@ -86,6 +87,43 @@ void saveConfigCallback () shouldSaveConfig = true; } +void otaStarted() +{ + Serial.println("OTA update started!"); +} + +void otaFinished() +{ + Serial.println("OTA update finished!"); +} + +void otaProgress(unsigned int progress, unsigned int total) +{ + Serial.printf("OTA progress: %u%%\r", (progress / (total / 100))); +} + +void otaError(ota_error_t error) +{ + Serial.printf("Error [%u]: ", error); + switch (error) + { + case OTA_AUTH_ERROR: + Serial.println("auth failed!"); + break; + case OTA_BEGIN_ERROR: + Serial.println("begin failed!"); + break; + case OTA_CONNECT_ERROR: + Serial.println("connect failed!"); + break; + case OTA_RECEIVE_ERROR: + Serial.println("receive failed!"); + break; + case OTA_END_ERROR: + Serial.println("end failed!"); + break; + } +} void setup() { @@ -256,6 +294,12 @@ void setup() Serial.println("local ip"); Serial.println(WiFi.localIP()); + ArduinoOTA.onStart(otaStarted); + ArduinoOTA.onEnd(otaFinished); + ArduinoOTA.onProgress(otaProgress); + ArduinoOTA.onError(otaError); + ArduinoOTA.begin(); + // Sensors htu.begin(); @@ -637,6 +681,8 @@ void handleSensors() void loop() { // put your main code here, to run repeatedly: + ArduinoOTA.handle(); + mqttClient.loop(); // Reconnect if there is an issue with the MQTT connection