diff --git a/.travis.yml b/.travis.yml index 1e0069f..e3deef2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index c90f9d3..5241e93 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -56,6 +56,9 @@ void callback(char*topic, byte* payload,unsigned int length); #ifdef ESP8266 #include + #include + #include + #include WiFiClient eClient; #else #include @@ -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 diff --git a/User_config.h b/User_config.h index 187864b..be1f656 100644 --- a/User_config.h +++ b/User_config.h @@ -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