related to #52 (#59)

* Added OTA-Support for ESP8266

#52 thanks!
This commit is contained in:
Patrick Wilhelm authored and Florian committed 2017-06-09 22:02:05 +02:00
1 parent 847a9518ef
commit 89e1d6fbd8
3 files changed
+40

No files matched your search

+33
View File
@@ -56,6 +56,9 @@ void callback(char*topic, byte* payload,unsigned int length);
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
WiFiClient eClient;
#else
#include <Ethernet.h>
@@ -121,6 +124,33 @@ void setup()
#ifdef ESP8266
//Begining wifi connection in case of ESP8266
setup_wifi();
// Port defaults to 8266
ArduinoOTA.setPort(ota_port);
// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname(ota_hostname);
// No authentication by default
ArduinoOTA.setPassword(ota_password);
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();
#else
//Begining ethernet connection in case of Arduino + W5100
setup_ethernet();
@@ -189,6 +219,9 @@ void loop()
} else { //connected
// MQTT loop
client.loop();
#ifdef ESP8266
ArduinoOTA.handle();
#endif
#ifdef ZsensorDHT
MeasureTempAndHum(); //Addon to measure the temperature with a DHT