SOLVED - ESP32 Over-The-Air network port wont appear

Hi all..

I ve been battling with the OTA functionality for more than a month but all my trials are inconclusive.
Firstly the environment:
Arduino IDE 2.3.4
ESP32 Wrover Module - home brew PCB with ESP32-WROOM-32U

Problem:
Loading the example sketch BasicOTA works first time with no other adjustments (ie firewall etc) necessary.
Problems begin when I try adding more code to the above sketch. At a certain point the network port disappears from the list. The strange thing is that i am not able to isolate which part of the extra code causes this issue.
To add to the confusion, I have a sketch working 24/7 for a few months now and the associated network port is constantly available. When I try to burn the same sketch to a second identical module, the new network port appears intermittently ! In some cases, the network port is available but by the time the sketch is complied and ready for upload, the port disappears!

Going one step further and trying to sniff the traffic with Bonjour Browser, confirms that indeed the mdns packets are sometimes present from the device in question and sometimes disappear.

Searching online, it appears that other people have faced similar problem but I havent seen a solution yet, unless of course I missed it.

Does anyone have any idea whats really going on?

SOLVED!
In case someone is reading this in the future, a bug was found in the subnet mask stored.
I use static IP settings and the subnet mask was saved as 255.255.255.255 instead of 255.255.255.0

could you indicate the procedure to correct the problem please ?
I am also using WM.
Thanks

As mentioned earlier, in my case the problem was wrong setting for the subnet mask.
Correcting this, solved the problem.
In your case, it might be something else..

Thanks for the reply,
How could i set tehe correct subnet mask using WM please ?
Thanks

Try the included OTA example sketch that leaves all IP settings to dynamic, including subnet

Thanks Watcher,
I am not so skilled on those items: I think you refer to example\advanced .
Could you please spend few more words on this configuration please ? How to set them for proper operation ?
Thanks again for the assistance
regards,
Ambro

Can you please explain exactly what you are trying to do ?

Watcher:
I would like to solve the problem relevant to the network port not shown in the IDE.
My sketch is using WiFi Manager to connect my home network . As told everything is working well except for the port NOT shown. You suggest to see the Examples: I think it is the advanced examples . I am not skilled on this item. COULD you please indicate to me the line of code to be changed for proper operation ? Thanks

If you are using IDE 2.3.4 and having selected your ESP board go under File-Examples-ArduinoOTA.

Here is the example anyway:

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

const char *ssid = "..........";
const char *password = "..........";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 3232
  // ArduinoOTA.setPort(3232);

  // Hostname defaults to esp3232-[MAC]
  // ArduinoOTA.setHostname("myesp32");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  ArduinoOTA
    .onStart([]() {
      String type;
      if (ArduinoOTA.getCommand() == U_FLASH) {
        type = "sketch";
      } else {  // U_SPIFFS
        type = "filesystem";
      }

      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
      Serial.println("Start updating " + type);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .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();

  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ArduinoOTA.handle();
}

Before uploading, change the SSID and Password according to your own network setup.

This should work as is. The network port should appear under the programming ports.

Anyhow, this is a different issue than the original post and if you still have problems, better start a new thread to get help.

Thanks Watcher,
The sketch suggested by you works well as expected. The point is that the network port is randomly shown by the IDE. When shown, I am able to upload sketches correctly. Again, the point is that IDE sometime shows the net port and sometime it does not show the net port. Sometime closing the IDE and then open the IDE again solvs the problem.
regards

Please show the actual sketch you used along with the network settings.

the sketch is the one you posted above .

I just changed the following:
const char *ssid = "..........";
const char *password = "..........";
nothing else.

In that case I cant think of a reason why the network port disappears sporadically .
You might wish to check your firewall settings but i doubt that is the problem.