add draft for esp8266 with Arduino OTA
This commit is contained in:
parent
7ebc024d54
commit
5039a36741
54
esp_gateway/esp_gateway.ino
Normal file
54
esp_gateway/esp_gateway.ino
Normal file
@ -0,0 +1,54 @@
|
||||
#include "Arduino.h"
|
||||
#include <WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
const char* ssid = "vulturul";
|
||||
const char* password = "***REMOVED***";
|
||||
|
||||
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());
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user