OTA port not showing in IDE

I have a problem with the OTA network port not showing up in the Arduino IDE. I am working with an ESP8266 and the webserver on IP address 192.168.1.22 is working just fine. I have added OTA by following the BasicOTA example:

#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void setup(){
  updateOTA();
}
void loop(){
  ArduinoOTA.handle();
}
void updateOTA() {

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

  // Hostname defaults to esp8266-[ChipID]
  ArduinoOTA.setHostname("fancontrol");

  // 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_FS
      type = "filesystem";
    }

    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  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();
  Serial.println("OTA update handler ready");
}

For most part my code is exactly the same as in the example except that I have set a password and put the code to start the OTA processin its own function.

The esp8266 IP address does not show up in the Network port section of Tools->Port. When it does show up occasionally it usually has the wrong address: 192.168.244.1. No idea where it gets this from as its not an address on my network.

Updating via USB continues to work OK, so using that at the moment, but at some point I will need to rely on OTA updates.

mDNS appears to be working as I can ping “fancontrol.local”.

I am working on Mint Linux 19.3.

Are you using a VPN ?

VPN? No.

Just USB wifi stick plugged into PC + ESP8266 operating in AP mode.

ESP8266 operating in AP mode.

ESP should be in STA mode connected to your router, then you can find it on the network. But please Check this link and look under Arduino IDE (about a third along) and you will find

Before you begin, please make sure that you have the following software installed:

Arduino IDE 1.6.7 or newer - https://www.arduino.cc/en/Main/Software

esp8266/Arduino platform package 2.0.0 or newer - for instructions follow GitHub - esp8266/Arduino: ESP8266 core for Arduino

Python 3.x - https://www.python.org/

Note: Windows users should select “Add python.exe to Path” (see below – this option is not selected by default).

Thank you for the information. Just to confirm, the IDE version is 1.8.12. The ESP library version is at the latest and python3 is installed. The fact is that it has worked initially even with password authentication, but now a few days later and without me changing anything it no longer does. The docs say that PC and ESP must be on the same networkwhich makes sense, and once the PC is connected to the AP they are and The PC gets a DHCP address. Are you saying that OTA works only in STA mode?

Are you saying that OTA works only in STA mode?

I am saying that as far as i got it to work, using the IDE, it was always in STA mode.( tbh i never even tried in AP mode, the examples are in STA mode and my sketches are always using both modes, so why should i switch my laptop to a different network ? ) Using the httpUpdater i have had it working in both modes.
I am not saying that it doesn't work in AP mode (i think it should, but then the ip should show up as 192,168.4.1 i think)

Deva_Rishi:
I am not saying that it doesn't work in AP mode (i think it should, but then the ip should show up as 192,168.4.1 i think)

Ok, I can bring in a router and try in STA mode it as you suggest. The example does, after all, run in STA mode. I just didn't expect to run into a problem because of using AP mode though.

Can I ask though, why would it show up as IP address 192.168.4.1 (or 192.168.244.1 for that matter)? Is that a default or something? The AP is set a static address of 192.168.1.22 before the function containing the OTA stuff is called? (Not questioning your information, just trying to understand the behaviour).

UPDATE: as if by magic its all working perfectly again this morning! The only difference I guess is that the PC has been rebooted. Still intend to try the STA mode though. I need this to be stable.

The only difference I guess is that the PC has been rebooted.

That would be your Windows machine ! Look i start my laptop in the morning and i (sometimes) get a limited wifi connection until i reboot, or switch the wifi on and off (that works sometimes) just disconnect and re-connect (also sometimes) and on occasion reset the router.

why would it show up as IP address 192.168.4.1 (or 192.168.244.1 for that matter)? Is that a default or something?

Yes the 192.168.4.1 is the default address. In fact if you connect your ESP to a router and it gets a new IP address, but have both AP & STA mode running, then you can access the server through both the 'new' IP-address, and the default (the machine's own) address when you connect to it's AP mode. If you connect to an AP with another device the ESP will assign that device an IP-address (most likely 192.168.4.2 (or 3 and so on) The same way that a router does.

Deva, I am not using Windows, but I guess something may have got messed up in the network stack on my machine.

Thanks for clarifying that 192.168.4.1 is a default address. So where is the 192.168.244.x address coming from? Would it be a different default for this NodeMCU module perhaps? Well, whatever the case, it seems the problem was down to a network glitch of some sort so I'm not going to worry about it too much.

I have tried the router approach BTW but ran into another problem. My office/dev machine and switch are connected to the WiFi router by an old router running DD-WRT and functioning as a WiFi client. The office is therefore effectively on a separate sub-network to the main house WiFi. I hadn't considered that but unfortunately this means that mDNS does not work. The DD-WRT firmware has the option to creat a bridged network, but that is another subject entirely.

So where is the 192.168.244.x address coming from?

no idea, maybe that is the address that the OTA is using...

Would it be a different default for this NodeMCU module perhaps?

i doubt that.

The office is therefore effectively on a separate sub-network to the main house WiFi. I hadn't considered that but unfortunately this means that mDNS does not work.

Life was complicated, and then they invented WiFi !