Skip to content

Instantly share code, notes, and snippets.

@pfeerick
Created December 13, 2018 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfeerick/bef13f437b16e11b427bbb27416e4194 to your computer and use it in GitHub Desktop.
Save pfeerick/bef13f437b16e11b427bbb27416e4194 to your computer and use it in GitHub Desktop.
Modified version of the BasicOTA sketch included with the ESP8266 Arduino core to check if MDNS is an issue
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#define WIFI_SSID "YOUR_SSID"
#define WIFI_PWD "YOUR_SSID_PASSWORD"
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(F("Booting..."));
Serial.print("Compiled: " __DATE__ ", " __TIME__ ", Arduino IDE v"); Serial.println(ARDUINO, DEC);
Serial.print(F("Core version: ")); Serial.println(ESP.getCoreVersion());
Serial.print(F("SDK version: ")); Serial.println(ESP.getSdkVersion());
//WiFi
Serial.println(F("Connecting to WiFi..."));
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PWD);
while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
//OTA
ArduinoOTA.setHostname("OTA Test");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_SPIFFS
type = "filesystem";
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
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(F("Auth Failed"));
} else if (error == OTA_BEGIN_ERROR) {
Serial.println(F("Begin Failed"));
} else if (error == OTA_CONNECT_ERROR) {
Serial.println(F("Connect Failed"));
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println(F("Receive Failed"));
} else if (error == OTA_END_ERROR) {
Serial.println(F("End Failed"));
}
});
ArduinoOTA.begin();
Serial.println(F("Ready!"));
Serial.print(F("IP address: "));
Serial.println(WiFi.localIP());
}
void loop()
{
MDNS.update();
ArduinoOTA.handle();
// report heap free every 5 seconds
static unsigned long last = millis();
if (millis() - last > 5000)
{
last = millis();
Serial.printf("[LOOP] Free heap: %d bytes\n", ESP.getFreeHeap());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment