I want to update the Raspberry Pi with new codes using ArduinoOTA. Previously, I downloaded the Raspberry Pi Pico Arduino core. The Pico connects to the WiFi without any issues, but when I try to upload a new code (in this case, a simple blink code), it attempts to upload but fails. I don't know what the problem is since the BasicOTA code also does not work over WiFi.
I have enabled the TCP port 2040 (default) on my router and in my firmware and I can successfully ping the Pico's IP address.
My goal is to wirelessly update the Pico W with new codes using Arduino. I have only come across the OTA method in Arduino
#include <ArduinoOTA.h>
#include <LEAmDNS.h>
#include <WiFiUdp.h>
#include <WiFi.h>
#include <LittleFS.h>
#include "secret.h"
const char* ssid = SSID;
const char* password = PW;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
connectToWiFi();
if (!LittleFS.begin()) {
Serial.println("LittleFS could not be mounted. Please check the configuration.");
} else {
Serial.println("LittleFS successfully initialized.");
}
// ArduinoOTA.setPort(2040);
// OTA Setup
ArduinoOTA.setHostname("xxx");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else {
type = "filesystem"; // LittleFS Filesystem OTA Command
}
Serial.println("Starting OTA update: " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nOTA update completed");
});
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();
}
void loop() {
ArduinoOTA.handle();
delay(10);
// blink();
}
Output after the first upload via USB
WiFi connected
Assigned IP address: 192.168.1xx.xx
LittleFS successfully initialized.
OTA server at: xxx.local:2040
Output after the upload over WiFi with the "blink();" function
Uploading . . . . . . . . . . . . . . . . . . . . . . . .
[ERROR]: Error Uploading
Failed uploading: uploading error: exit status 1