Advertisement
Laggger164

OTA no workie

Aug 30th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WiFi.h>
  2. #include <ESPmDNS.h>
  3. #include <WiFiUdp.h>
  4. #include <ArduinoOTA.h>
  5.  
  6. const char* ssid = "Josai-obyvacka";
  7. const char* password = "12345678";
  8.  
  9. void setup() {
  10.   Serial.begin(115200);
  11.   Serial.println("Booting");
  12.   WiFi.mode(WIFI_STA);
  13.   WiFi.begin(ssid, password);
  14.   while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  15.     //Serial.println("Connection Failed! Rebooting...");
  16.     //delay(5000);
  17.     //ESP.restart();
  18.     Serial.print(".");
  19.     //delay(5);
  20.   }
  21.  
  22.   // Port defaults to 3232
  23.   // ArduinoOTA.setPort(3232);
  24.  
  25.   // Hostname defaults to esp3232-[MAC]
  26.    ArduinoOTA.setHostname("myesp32");
  27.  
  28.   // No authentication by default
  29.   // ArduinoOTA.setPassword("admin");
  30.  
  31.   // Password can be set with it's md5 value as well
  32.   // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  33.   // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
  34.  
  35.   ArduinoOTA
  36.     .onStart([]() {
  37.       String type;
  38.       if (ArduinoOTA.getCommand() == U_FLASH)
  39.         type = "sketch";
  40.       else // U_SPIFFS
  41.         type = "filesystem";
  42.  
  43.       // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  44.       Serial.println("Start updating " + type);
  45.     })
  46.     .onEnd([]() {
  47.       Serial.println("\nEnd");
  48.     })
  49.     .onProgress([](unsigned int progress, unsigned int total) {
  50.       Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  51.     })
  52.     .onError([](ota_error_t error) {
  53.       Serial.printf("Error[%u]: ", error);
  54.       if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  55.       else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  56.       else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  57.       else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  58.       else if (error == OTA_END_ERROR) Serial.println("End Failed");
  59.     });
  60.  
  61.   ArduinoOTA.begin();
  62.  
  63.   Serial.println("Ready");
  64.   Serial.print("IP address: ");
  65.   Serial.println(WiFi.localIP());
  66. }
  67.  
  68. void loop() {
  69.   Serial.println(WiFi.status());
  70.   ArduinoOTA.handle();
  71.   delay(20);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement