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

+2
View File
@@ -21,6 +21,8 @@ install:
- git clone https://github.com/ekstrand/ESP8266wifi /usr/local/share/arduino/libraries/ESP8266wifi
- git clone https://github.com/knolleary/pubsubclient /usr/local/share/arduino/libraries/pubsubclient
- git clone https://github.com/sui77/rc-switch /usr/local/share/arduino/libraries/rc-switch
- git clone https://github.com/arduino/arduinoOTA.git /usr/local/share/arduino/libraries/ArduinoOTA
- git clone https://github.com/mrdunk/esp8266_mdns.git /usr/local/share/arduino/libraries/ESP8266mDNS
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
- arduino --install-boards esp8266:esp8266
- arduino --board $BD --save-prefs
+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
+5
View File
@@ -58,6 +58,11 @@ const byte gateway[] = { 192, 168, 1, 1 }; //ip adress
const byte Dns[] = { 192, 168, 1, 1 }; //ip adress
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
/*-------------DEFINE YOUR OTA PARAMETERS BELOW----------------*/
#define ota_hostname "OTAHOSTNAME"
#define ota_password "OTAPASSWORD"
#define ota_port 8266
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
//Addons and module management, comment the line if you don't use
//#define ZsensorDHT