Skip to content

Commit

Permalink
Merge pull request #9 from CODeRUS/ota
Browse files Browse the repository at this point in the history
[ota] Implemented ArduinoOTA
  • Loading branch information
leon-anavi authored Jan 17, 2019
2 parents 4ee6268 + 4a67d73 commit eaff6d6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions anavi-light-controller-sw/anavi-light-controller-sw.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <FS.h> //this needs to be first, or it all crashes and burns...

#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <ArduinoOTA.h>

//needed for library
#include <DNSServer.h>
Expand Down Expand Up @@ -93,6 +94,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()
{
Expand Down Expand Up @@ -263,6 +301,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();

Expand Down Expand Up @@ -840,6 +884,8 @@ void handleSensors()
void loop()
{
// put your main code here, to run repeatedly:
ArduinoOTA.handle();

mqttClient.loop();

const unsigned long effectMillis = millis();
Expand Down

0 comments on commit eaff6d6

Please sign in to comment.