Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266mDNS.h>
  3. #include <WiFiUdp.h>
  4. #include <ArduinoOTA.h>
  5. const char* ssid = "..........";
  6. const char* password = "..........";
  7. void setup() {
  8. Serial.begin(115200);
  9. Serial.println("Booting");
  10. WiFi.mode(WIFI_STA);
  11. WiFi.begin(ssid, password);
  12. while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  13. Serial.println("Connection Failed! Rebooting...");
  14. delay(5000);
  15. ESP.restart();
  16. }
  17. // Port defaults to 8266
  18. // ArduinoOTA.setPort(8266);
  19. // Hostname defaults to esp8266-[ChipID]
  20. // ArduinoOTA.setHostname("myesp8266");
  21. // No authentication by default
  22. // ArduinoOTA.setPassword((const char *)"123");
  23. ArduinoOTA.onStart([]() {
  24. Serial.println("Start");
  25. });
  26. ArduinoOTA.onEnd([]() {
  27. Serial.println("\nEnd");
  28. });
  29. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  30. Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  31. });
  32. ArduinoOTA.onError([](ota_error_t error) {
  33. Serial.printf("Error[%u]: ", error);
  34. if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  35. else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  36. else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  37. else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  38. else if (error == OTA_END_ERROR) Serial.println("End Failed");
  39. });
  40. ArduinoOTA.begin();
  41. Serial.println("Ready");
  42. Serial.print("IP address: ");
  43. Serial.println(WiFi.localIP());
  44. }
  45. void loop() {
  46. ArduinoOTA.handle();
  47. }