OTA defaults to 192.168.1.20

Hi all,
I have OTA coded using ArduinoOTA.h
The IP address used for the port is 192.168.1.20 -
which I not coded anywhere, and OTA wont work as it is trying to speak to the wrong IP address.
EG Tools -> Port: "esp8266-cbd880 at 192.168.1.20

Anyone know why it does this?

Welcome to the forum

Which board are you using ?

I have been using OTA for a few days for the first time and have had no problems with using the IP address. I currently have 3 devices using OTA, 1 ESP32 and 2 ESP8266. All of them work fine with the IP address allocated to them automatically

What makes you think that OTA is trying to "speak" to the wrong address ?

Thanks for the reply.
I am using a WEMOS D1 mini.
I think that OTA is trying to "speak" to the wrong address as when I go to Tools - Port in the Arduino IDO the option is "esp8266-dbc080 at 192.168.1.20"

What do you think the IP address should be ?

I would think 192.168.1.32, which is the IP address of the ESP8266

IPAddress local_IP(192, 168, 1, 32);

// Code written in C++ for Aruduino. GreyThree1
// Poll an ultrasonic sensor module JSN-SR04T and send the distance read to an MQTT broker at 192.168.1.30
// ctl-shift M to open console
//GreyOrchard
//GreyLowEast
//GreyLowWest

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP.h>

#define GreyOrchardTrigPin D1
#define GreyOrchardEchoPin D2

#define GreyEastTrigPin D3
#define GreyEastEchoPin D4

#define GreyWestTrigPin D5
#define GreyWestEchoPin D6

IPAddress local_IP(192, 168, 1, 32);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 1, 0);

const char* ssid = "myssid"; // Enter your WiFi name
const char* password = "mypassword"; // Enter WiFi password

const char* Server = "192.168.1.30";
const int Port = 1883;
long GreyOrchardDuration, GreyOrchardDistance; // Duration used to calculate distance
long GreyEastDuration, GreyEastDistance; // Duration used to calculate distance
long GreyWestDuration, GreyWestDistance; // Duration used to calculate distance

char msg[50]; // Set msg variable for conversion for
WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
// Configures static IP address
if (!WiFi.config(local_IP, gateway, subnet))
{
Serial.println("STA Failed to configure");
}
// Connect to WiFi
WiFi.mode(WIFI_STA);
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}

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

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

// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");

ArduinoOTA.onStart( {
Serial.println("Start");
});
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("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Connected to the WiFi networkdddd");

// Setup I/O pins for ultrasound.
pinMode(GreyOrchardTrigPin,OUTPUT);
pinMode(GreyOrchardEchoPin,INPUT);
pinMode(GreyEastTrigPin,OUTPUT);
pinMode(GreyEastEchoPin,INPUT);
pinMode(GreyWestTrigPin,OUTPUT);
pinMode(GreyWestEchoPin,INPUT);

// Connect to the broker.
client.setServer(Server, Port);
client.setCallback(callback);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP8266Client")) {
Serial.println("connected");
}
else {
Serial.print("failed with state ");
Serial.println(client.state());
delay(2000);
}
}
}

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
Serial.println("-----------------------");
}
// This could be a way to have MQTT from the web page, eg read the level
// client.subscribe("tank1");

void loop() {

// GreyOrchard Read
digitalWrite(GreyOrchardTrigPin, LOW);
delayMicroseconds(2);
digitalWrite(GreyOrchardTrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(GreyOrchardTrigPin, LOW);
GreyOrchardDuration = pulseIn(GreyOrchardEchoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
GreyOrchardDistance = GreyOrchardDuration/5.82;
Serial.print(GreyOrchardDistance);
Serial.println(" GreyOrchardDistance mm");

//We sometimes get zero readings for some reason, take them out
if(GreyOrchardDistance > 0) {
//Publish the variable "GreyOrchardDistance" to topic "GreyOrchard" on the broker.
sprintf(msg, "%ld", GreyOrchardDistance);
client.publish("GreyOrchard", msg); //Topic name, input message
}

// GreyEast Read
digitalWrite(GreyEastTrigPin, LOW);
delayMicroseconds(2);
digitalWrite(GreyEastTrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(GreyEastTrigPin, LOW);
GreyEastDuration = pulseIn(GreyEastEchoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
GreyEastDistance = GreyEastDuration/5.82;
Serial.print(GreyEastDistance);
Serial.println(" GreyEastDistance mm");

//We sometimes get zero readings for some reason, take them out
if(GreyEastDistance > 0) {
//Publish the variable "GreyEastDistance" to topic "GreyEast" on the broker.
sprintf(msg, "%ld", GreyEastDistance);
client.publish("GreyEast", msg); //Topic name, input message
}

// GreyWest Read
digitalWrite(GreyWestTrigPin, LOW);
delayMicroseconds(2);
digitalWrite(GreyWestTrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(GreyWestTrigPin, LOW);
GreyWestDuration = pulseIn(GreyWestEchoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
GreyWestDistance = GreyWestDuration/5.82;
Serial.print(GreyWestDistance);
Serial.println(" GreyWestDistancccccccccccccccccccce mm");

//We sometimes get zero readings for some reason, take them out
if(GreyWestDistance > 0) {
//Publish the variable "GreyWestDistance" to topic "GreyWest" on the broker.
sprintf(msg, "%ld", GreyWestDistance);
client.publish("GreyWest", msg); //Topic name, input message
}
delay(2000);

client.loop();
}

I suspect that the OTA process is causing the specified IP address to be overridden by providing one by DHCP, but I am not sure

From OTA Updates — ESP8266 Arduino Core 3.1.2-21-ga348833 documentation

IP address depends on your network configuration)

I have my router configured to give my boards a fixed IP address via DCHP so I have not had the need to specify one in the sketch

Ok, i'll look at the router, thanks