From 8458fa1d7baebb839c1c61ded618529dd04560d0 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 25 Sep 2020 19:40:24 +0200 Subject: [PATCH] add draft for esp8266 with Arduino OTA --- esp_gateway/esp_gateway.ino | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 esp_gateway/esp_gateway.ino diff --git a/esp_gateway/esp_gateway.ino b/esp_gateway/esp_gateway.ino new file mode 100644 index 0000000..6c3da6c --- /dev/null +++ b/esp_gateway/esp_gateway.ino @@ -0,0 +1,54 @@ +#include "Arduino.h" +#include +#include +#include +#include + +const char* ssid = "vulturul"; +const char* password = "parolatplink"; + +void setup() +{ + Serial.begin(9600); // Start the serial console + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + + Serial.println("Connecting to WiFi netowrk."); + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.println("Establishing connection to WiFi.."); + } + Serial.println("Connected to network"); + + setupOTA(); + +} + +void loop() +{ + ArduinoOTA.handle(); +} + +void setupOTA() { + ArduinoOTA.onStart([]() { + Serial.println("Start"); + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nEnd"); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }); + ArduinoOTA.onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); + 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"); + }); + ArduinoOTA.begin(); + Serial.println("Ready"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); +}