2

im trying to upload my code to my esp32 through OTA iam able to discover the network port but my code is always failing to upload i donno the reason behind it

#include <WiFi.h>
#include <ArduinoOTA.h>

const char* ssid = "Redmi";
const char* password = "12345678s";
const char* OTA_password = "1234"; // set your own OTA password

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Print IP address
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Start OTA update server with authentication
  ArduinoOTA.setHostname("my-esp32");
  ArduinoOTA.setPassword(OTA_password); // set OTA password
  ArduinoOTA.onStart([]() {
    // Disable other tasks that may interfere with OTA update
    Serial.println("OTA update started");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nOTA update finished");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("OTA update progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("OTA update error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) {
      Serial.println("OTA authentication failed");
    } else if (error == OTA_BEGIN_ERROR) {
      Serial.println("OTA begin failed");
    } else if (error == OTA_CONNECT_ERROR) {
      Serial.println("OTA connect failed");
    } else if (error == OTA_RECEIVE_ERROR) {
      Serial.println("OTA receive failed");
    } else if (error == OTA_END_ERROR) {
      Serial.println("OTA end failed");
    }
  });
  ArduinoOTA.begin();
}

void loop() {
  ArduinoOTA.handle();
  // Your other code here
}

above is the code i uploaded to create OTA server

#include <WiFi.h>
#include <ArduinoOTA.h>

const char* ssid = "Redmi";
const char* password = "12345678s";

#define LEDPIN 4

void setup() {
  Serial.begin(115200);

  // Connect to Wi-Fi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("");

  // Start OTA update server
  ArduinoOTA.begin();
  Serial.println("OTA server started");

  // Initialize LED pin as output
  pinMode(LEDPIN, OUTPUT);
}

void loop() {
  ArduinoOTA.handle();

  // Blink LED every second
  digitalWrite(LEDPIN, HIGH);
  delay(1000);
  digitalWrite(LEDPIN, LOW);
  delay(1000);
}

and im trying to upload above blink program through OTA getting stucked and i have to restart the software everytime to test it and above is the error im getting it getting stucked and i have to restart the software everytime to test it. I appreciate if anybody care to explain and help me

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.