ESP32 IP address fail

Hi guys,

I’ve developed a Webserver project in VSCode on an ESP32-Wroom board, which works nicely to switch GPIO pins ON/OFF and PWM outputs. (based on randomnerdtutorials stuff). All controlled nicely on my home WiFi from my PC and phone. The serial monitor in VSCode tells me the ESP32 IP address.

However, I have now changed to an ESP32 board with an aerial (better Wifi connection) and it it tells me a different IP address in VSCode. This IP address is not on showing on my WiFi system and I cannot get the Webserver on my browser now.

Any advice ?

Update 1 :- I’ve just done a test … the ESP32 board reports in VSCode serial monitor “WiFi Connected” and the same IP address, when my WiFi hub is switched OFF !!!

Update 2 :- my code can also send me WhatsApp messages (if I enable) …. and that works on this strange IP address !!! Getting whatsApp messages on my phone !!!

Usually different devices gets different IP-Adresses from the DHCP server.

Is it the IP address of the ESP32’s AP (192.168.4.1) and not the STA IP-Address assigned by your DHCP server?

Or maybe you have “bad network setup” and multiple DHCP server with different IP-ranges in your network? (This actually already happened someone)

Without knowing your code, we can only guess. Please share the code and platformio.ini or a link to your project.

Hi sivar2311,

I expected the new ESP32 to get a different IP address, but by NOT trying to force a static IP address, it comes up with the following on the VSC serial monitor ….

IP address: 192.168.0.127
MAC address: 84:1F:E8:27:8F:6C

Google tells me this IP address is usually my router’s admin page.

If I force an avilable static IP address, the VSC serial monitor shows …..

IP address: 192.168.1.150
MAC address: 84:1F:E8:27:8F:6C

My router shows no such device connected.

I’ve used this new ESP32 device (with separate aerial) before and it connected ok, but not now.

I’ve also tried again today my old ESP32-Wroom (without a sparate aerial), with this same code and it works fine with or without a static IP. It’s “natural” IP is 192.168.1.160, or I can force it to claim 192.168.1.150.

This is my code (not showing all webserver HTML, etc) …

/*********
  Trev's ESP32-WROOM control system - WiFi Webserver controlled, with WhatsApp messaging and CAN bus.
  Based on Rui Santos & Sara Santos - Random Nerd Tutorials
*********/

// Import required libraries
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <HTTPClient.h>
#include <UrlEncode.h>
#include <CAN.h>

// Replace with your network credentials
const char* ssid = "xxxxxxxxxxxxx";     //set to Trev's router ssid
const char* password = "xxxxxxxxxxx";   //set to router password

// CALLMEBOT WhatsApp support
String phoneNumber = "xxxxxxxx";        //Trev's phone number
String apiKey = "xxxxxx";               //Trev's apiKEY for CALLMEBOT.com

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 150);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 254);

IPAddress subnet(255, 255, 0, 0);
//IPAddress primaryDNS(8, 8, 8, 8);   //optional
//IPAddress secondaryDNS(8, 8, 4, 4); //optional


...... GPIO define, HTML, etc ........


// SETUP ROUTINE ###################################
void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  // WiFi LED on board OFF
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

// Setup PWM LED
 // ledcSetup(LED32Channel, freq, resolution);
 // ledcAttachPin(LED32pin, LED32Channel);

// Setup GPIOs all as OUTPUTS
  pinMode(LED13, OUTPUT);

// Setup GPIOs OUTPUTS all OFF
  digitalWrite(LED13, LOW);

// Force static IP address #######################################
  if (!WiFi.config(local_IP, gateway, subnet)) {
    Serial.println("STA Failed to configure");
}

// Connect to Wi-Fi ##############################################
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
// WiFi connected OK
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
// WiFi LED on board ON
  digitalWrite(LED_BUILTIN, HIGH);

  // Print ESP MAC Address
  Serial.println("MAC address: ");
  Serial.println(WiFi.macAddress());

// Set the CAN TX RX pins and start CAN #########################
  CAN.setPins (RX_GPIO_NUM, TX_GPIO_NUM);
  CAN.begin(500E3);

// Route for root / web page ####################################
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){

    request->send(200, "text/html", index_html, processor);
  });

// LOOP #########################################################
void loop() {
  //send CAN messages
  sendCANALL();

  //Flash GPIO 13;
  int LED = 13;
  digitalWrite(LED13, HIGH);
  delay(200);
  digitalWrite(LED13, LOW);
  delay(200);
}

Thank you

Isn’t your router / gateway located on 192.168.1.254 ?

That’s strange. But what network is your ESP32 connected to, then?
Do you have multiple routers / access-points in your network?

Afaik the subnet-mask is wrong and must be 255.255.255.0 for a network 192.168.x.y as it is a class C network. What network masks do you use in your router / accesspoints ?

This looks like there is another DHCP server in your network which is using 192.168.0.x network. !?

Yes, have I misunderstood the lines ….

I thought this should be my router’s gateway ?

The network credentials are in the code, so I guess the ESP32 can’t connect to another network.

Only 1 router in my house.

Thanks, I just tried 255.255.255.0 but still not working.

Not sure about network masks ?

I only have 1 router

This should be your router’s IP Address.

I’m trying to summarize the necessary information:

  • Your network address is 192.168.1.x
  • The netmask of your network is: 255.255.255.0
  • Your router’s address is 192.168.1.254
    (The above settings and the address should be seen in your router’s setup)
  • There is only one router in your network which acts as router, DHCP-server and access-point

When your ESP32 connects to your wifi network it gets the address 192.168.0.150 assigned by the DHCP of your router. But your router doesn’t show this address.

Is that correct?

Additional question: What’s the DHCP settings of your router (address pool)?

Thanks for your help sivar2311,

This is all a bit beyond my knowledge of networking, so bear with me please.

Somewhere in this process, I thought forcing the ESP32 to a static IP 192.168.1.150 was working.

But now not working, so I’m getting confused now. I’ll back-track on the old ESP board to see if I can get static IP working again.

The OLD ESP board naturally connects to 192.168.1.160 and works ok.

The NEW ESP board naturally connects to 192.168.0.127 and I can’t see it on my network.

Let me try again to get the old one working on a static IP, if I can. Ithought it worked before.

By “connects to” means the ESP32 got this address assigned?

192.168.0.x is a different network than 192.168.1.x.
Do you have a hotspot running on your phone with the same wifi credentials (where the ESP32 accidently connect to)?

Print the wifi’s BSSID to see to which station the ESP is connected to on both of your ESP32’s and compare the BSSID’s. Are they equal or different?

Add two additional lines to your code to print the BSSID:

Then compare the BSSID’s which are print by your old ESP32 (which connects correctly) and the new one.

Sorry, had to pop out.

Ok, got that working and the 2 BSSID’s are different.

Neither of these devices appear on my router

OLD ESP32-WROOM
Network info ----- PLUSNET-9TC2ZR
BSSID --------------- 18:58:80:4A:95:4F
Gateway IP -------- 192.168.1.254
Subnet Mask ----- 255.255.255.0
RSSI ---------------- -73 dB
ESP32 IP add ----- 192.168.1.150
ESP32 MAC add - EC:64:C9:90:E5:58

NEW ESP32-WROOM
Network info ----- PLUSNET-9TC2ZR
BSSID --------------- 38:6B:1C:23:89:D2
Gateway IP -------- 192.168.1.254
Subnet Mask ----- 255.255.255.0
RSSI ---------------- -78 dB
ESP32 IP add ----- 192.168.1.150
ESP32 MAC add - 84:1F:E8:27:8F:6C

How do I find the BSSID of my network, to check against the above ?

I can’t find anything on my router webpage

The BSSID is the MAC-Address of the Accesspoint / Router where your device (ESP32) is connected to.

If this address is different, then your ESP is clearly connected to a different router / accespoint!

What is this?
I didn’t see this before in your sketch.

Hi Boris,

Thanks again for your help.

PLUSNET-9TC2ZR is my router.

Gotta go work soon, but before I go, I’ve opened a Wifi analyser on my phone ….

BSSID 18:58:80:4A:95:4F is my Wifi channel 11, very strong signal.

BSSID 38:6B:1C:23:89:D2 is my Wifi channel 4, very weak signal.

Not sure if that helps yet ?

Still neither ESP32 connected on 192.168.1.150

One other point.

The New ESP32, without static IP shows BSSID 38:6B:1C:23:89:D2 and IP 192.168.0.127.

I cannot locate it on my router, so cannot connect to its HTML Webserver.

But this ESP32 is running, flashing LEDs and sending CAN messages …. and sends me whatsApp messeges to my phone, via CallMeBot.

All very strange

This also clearly states that you have two different router or access points in your network, with different settings.

  1. The device is different. If both stations would be located on the same hardware device, the MAC Addresses would look similar but not completely different like 18:58:80:4A:95:4F vs. 38:6B:1C:23:89:D2 does.
  2. The WiFi Channel is different
  3. The Networks are different 192.168.1.x / 255.255.255.0 vs 192.168.0.x / 255.255.255.0. Since these are seperated networks the clients on both networks can not connect each other. That’s why you can’t connect to the webserver on your ESP from your computer.

Thanks Boris,

Can you clarify where you see the 192.168.0.x ?

I don’t understand it

Your second post in this thread.

If you use DHCP you wrote that your ESP got the IP Address 192.168.0.127

I think I’ve just realised what you’re trying to tell me.

I’ve just scanned through all MAC addresses on my system and there’s a device 38:6B:1C:23:89:D3, down at my workshop … it’s a Wifi mesh unit, on an ethernet cable through 100mbps power adaptors (using the house mains wiring).

I’ll bet the NEW ESP 32 connects to that somehow ….. I’ll go switch it off now.

EXACTLY :slight_smile:

Which reminds me to

1 Like

That was it Boris,

With the workshop wifi mesh switched off, I get the NEW ESP32 on my router devices now on IP 192.168.1.228 and it all works, Webserver page and everything.

The static IP 192.168.1.150 still doesn’t work, but that’s a different subject.

I still don’t understand how I’ll make it work, with the workshop mesh back on ?