I have uploaded some code using OTA using platformIO and the code works as intended. However, I was only able to upload the code by directly typing the IP address of the ESP32 only. I checked if the mDNS service is running on the computer and I can actually see the ESP32 device on it.
However, the network port doesn’t appear on the upload ports of the PlatformIO IDE since I can only see the USB connections. Below is the code attached:
#include <Arduino.h>
#include <WiFi.h>
#include <ArduinoOTA.h>
#define BOARD_LED 2
const char* ssid = "xxxx";
const char* password = "xxxx";
void setup() {
pinMode(BOARD_LED, OUTPUT);
Serial.begin(9600);
delay(10000);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println(WiFi.status());
}
Serial.println("\nWiFi connected");
// OTA setup
ArduinoOTA.setHostname("esp32-otav2");
ArduinoOTA.begin();
delay(1000);
}
void loop() {
ArduinoOTA.handle(); // Handle OTA updates
digitalWrite(BOARD_LED, HIGH);
delay(2000);
Serial.println("new program");
Serial.println("WiFi.localIP(): " + WiFi.localIP().toString());
digitalWrite(BOARD_LED, LOW);
delay(2000);
}