Browse Source

basic OTA on ticker

Etienne Landon 9 years ago
parent
commit
960bd90e5d
3 changed files with 25 additions and 23 deletions
  1. 2 2
      ESP_UKI.ino
  2. 1 1
      includes.h
  3. 22 20
      ota.h

+ 2 - 2
ESP_UKI.ino

@@ -21,7 +21,7 @@
 
 
 
-Ticker tkOTA;  // periodic check if OTA available
+
 Ticker tkUKI;  // periodic send ADC to UDP
 
 
@@ -33,7 +33,7 @@ void setup ( void ) {
   Serial.println("Starting ESP8266");
   setupLeds();
   //setupWifi();
-  //setupOTA();
+  setupOTA();
   
   delay(200);
   Serial.println("Ready");

+ 1 - 1
includes.h

@@ -32,7 +32,7 @@ WiFiUDP UKI_UDP;
 #include "eeprom.h"   //config and functions relative to config permanent storage
 #include "global.h"   //config and functions relative to wifi and access point configuration
 //#include "web.h"      //config and functions relative to configuration web server
-//#include "ota.h"      //config and functions relative to ota firmware updates
+#include "ota.h"      //config and functions relative to ota firmware updates
 
 
 

+ 22 - 20
ota.h

@@ -1,23 +1,31 @@
+Ticker tkOTA;  // periodic check if OTA available
+int OTA_check_ms = 100;
+
+void loopOTA(){
+  
+    ArduinoOTA.handle();
+    //Serial.println("OTA check");
+}
+
+
+
 void setupOTA(){
   ArduinoOTA.onStart([]() {
-    Serial.println("Start");
-    digitalWrite(Red_Led, HIGH);
-    digitalWrite(Blue_Led, LOW);
-    delay(1000);
-    digitalWrite(Blue_Led, HIGH);
-    delay(500);
+    Serial.println("Starting firmware update");
+    redLedState(-1,100); // fast red blink
   });
   ArduinoOTA.onEnd([]() {
-    Serial.println("End");
-    digitalWrite(Blue_Led, HIGH);
-    delay(1000);
+    Serial.println("update done !");
+    redLedState(0, 500);
+    blueLedState(-1, 100); // 5 fast blue blink on end
+    delay(500);
+    blueLedState(0,100);
     //ledBlink(Blue_Led, 3, 100);
 
   });
   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
     Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
-    digitalWrite(Blue_Led, Blue_Led_State);
-    Blue_Led_State = !Blue_Led_State;
+    blueLedState(-1,500); //slow blue blink during progress
 
   });
   ArduinoOTA.onError([](ota_error_t error) {
@@ -27,19 +35,13 @@ void setupOTA(){
     else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
     else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
     else if (error == OTA_END_ERROR) Serial.println("End Failed");
-    digitalWrite(Blue_Led, HIGH);
+    redLedState(-1, 250);
+    blueLedState(-1,250);
   });
   ArduinoOTA.begin();
   Serial.println("OTA started");
+  tkOTA.attach_ms(OTA_check_ms, loopOTA); 
 }
 
-void loopOTA(){
-  
-  if (loop_counter == 5)  {
-    ArduinoOTA.handle();
-    delay(10);
-    }
-
 
-}