ESP32 Wifi Problem: IPv4 172.xxx statt 192.xxx

Hallo zusammen,

ich möchte eine WiFi Verbindung zum Laptop als AP aufbauen.
Zur Info: Wifi / LAN soll per “LANConnect” unterschieden werden (geht auch mit 192.xxx)

  1. Verwende ich “nur” die interne fixe IP vom ESP32 “192.168.4.1” geht alles wunderbar.
    Ich bekomme nach dem Verbinden Daten vom ESP32.
    Codeschnipsel:
    // ESP32 as AccessPoint mit Passwort
    WiFi.softAP(ap_ssid, ap_pass);
    Serial.print (" -> Messkampagne1.LAN.Step2");
    // und starte den Server…
    wifiServer.begin();
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    WiFi.onEvent(ModbusEvent_LAN);
    // und dann LAN Start …
    ETH.begin();

  2. verwende ich jetzt aber eine andere hausinterne IP “172.20.30.2”
    muss ich ja umdefinieren:

    bWifiStatus1_softAPConfig =
    WiFi.softAPConfig(IPAddress(172, 20, 30, 2),IPAddress(172, 20, 30, 3),IPAddress(255, 255, 255, 0) );
    delay(50);
    // 2. Name + PW only
    bWifiStatus1_SoftAP =
    WiFi.softAP(ap_ssid, ap_pass);

WiFi.onEvent(ModbusEvent_LAN);
ETH.config(IPAddress(172, 20, 30, 2),IPAddress(172, 20, 30, 3),IPAddress(255, 255, 255, 0),IPAddress(172, 20, 30, 2) );
// und dann LAN Start (standard)…
ETH.begin();

Infos:

  1. mit/ohne vorher WiFi.disconnect etc. brachte alles nichts, DNS Server wird angegeben.
  2. im Scheduler verwende ich: “WiFiClient client = wifiServer.available(); …”
    geht wiederrum alles gut, wenn ich fix 192.xxx verwende, sobald ich umstelle auf 172.xxx
    findet er den Client nicht mehr "if (client) "

Wo kann mein Problem liegen ?
Mit dem WireShark sehe ich, dass der ESP32 die Verbindung nicht zulässt und eine
ReStart macht. Somit ist die Verbindung gekappt.
Hat das irgendwas mit dem DHCP zu tun, den ich eigentlich nicht brauche ?

Ergänzung: PIO Core 4.0.0rc6 Libs auf neuestem Stand:
Danke und Gruss
WVESP32

Is it ok if I or you translate the post to english?
Ist es in Ordnung wenn ich oder den deinen Post nach Englisch übersetze?

Hello “maxgerhardt”,
in english it is also ok, zero problem !
I’ve forgotten: I use an ESP32-EVB Rev.D © 2017 and the Ethernet Lib ID134

Thanks
Wolfgang

Just trying to understand your setup…
Your laptop is the accesspoint you connect to (ESP running in station mode) and also the client you want to send data to from your ESP32? The IPs you are listing (192.168.4.1 and 172.20.30.2) are IPs you want your ESP32 to have?

Hi,
my ESP32 is the Accresspoint, and running in AP-Mode.
The Laptop I can connect with LAN or Wifi, to get the datas for Modbus-TCP.
That i’m out of our companys network, i want to use a second network-card with
IP 172.20.30.2 for the ESP32 only. So i try to change his static IP.
Also in serial-debugging i see, that he trys some parts with
DHCP, but first i want a static IP.
Thanks Wolfgang

Hi Max,

I want to set up a WiFi connection to the laptop as an AP.
FYI: Wifi / LAN should be distinguished by “LANConnect” ( it works with 192.xxx )

If i use "only" the internal fixed IP of the ESP32 "192.168.4.1" all works wonderful.
I get data from the ESP32 after connecting.
Code snippets:
// ESP32 as AccessPoint with password
WiFi.softAP (ap_ssid, ap_pass);
Serial.print ("-> Measurement Campaign1.LAN.Step2");
// and start the server ...
wifiServer.begin ();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WiFi.onEvent (ModbusEvent_LAN);
// and then LAN start ...
ETH.begin ();

But if i use now another IP for my second WIN7-network card: "172.20.30.2"
I have to redefine AP-parameters:
...
bWifiStatus1_softAPConfig =
	WiFi.softAPConfig (IPAddress (172, 20, 30, 2), IPAddress (172, 20, 30, 3), IPAddress (255, 255, 255, 0));
delay (50);
// 2nd Name + PW only
bWifiStatus1_SoftAP =
	WiFi.softAP (ap_ssid, ap_pass);

 WiFi.onEvent (ModbusEvent_LAN);
 // i incluwe DNS also !
 ETH.config (IPAddress (172, 20, 30, 2), IPAddress (172, 20, 30, 3), IPAddress (255, 255, 255, 0), IPAddress (172, 20, 30, 2));
 // and then LAN Start (default) ...
 ETH.begin ();

Info:

with / without before WiFi.disconnect etc. everything brought nothing, DNS server is also specified.
In the scheduler I use: "WiFiClient client = wifiServer.available (); ... "
everything goes well, if I use fix 192.xxx , as soon as I switch to 172.xxx
he no longer finds the client "if (client)"

Where can be my problem ?
With the WireShark I see that the ESP32 does not allow the connection and ReStart message comes. Thus the connection is cut off.
Does this have anything to do with the DHCP, which I do not actually need?

Addition: PIO Core 4.0.0rc6 Libs up to date:
I use an ESP32-EVB Rev.D © 2017 and the Ethernet Lib ID134

Thanks and regards
WVESP32

If you want to connect your laptopt to your ESP32 both need to be in the same subnet. I don’t know how you configured the subnetmask and gateway IP so I can’t help you directly but I think this might be the problem. 192.168.4.x is the standard configurations subnet the ESP32 offers as an AP and if you try to connect to that with your laptop that is set to the static IP 172.20.30.2 it won’t work…

Why don’t you use the standard configuration of the ESP32? I can’t know for sure but it is unlikely, that the subnet your laptop uses to communicate with your companys network is the same as the one defined in the ESP32’s standard configuration.

Hi,
i now that 192.168.4.1. is the standard IP from ESP32.
With this everything works fine.
But we have another application running under 172.20.30.x.
So we want to use this network-range, not the standard.
What shall i say, i think also the ESP32 network parameter MUST be configureable, or ?

I still don’t exaclty get the network topology your are trying to achieve. That application that uses the 172.20.30.x (is it even a class C network?) subnet is running on your laptop? How is an application fixed to one IP?

Can you maybe just list all devices that are relevant to you with their IP, Subnetmask and used Gateway?
At the moment I understand there is:

  • your laptop that uses two networks. A probably wired company network with what IP, Gateway and Subnetmask?
  • your laptop that connects as station to the ESP32’s AP so it should use the ESP32 as Gateway and have the same subnetmask and a maching IP
  • the ESP32 that should work as AP so it should be a Gateway by itself and define the subnet by itself
  • an application?!

Let me explain the actual siuation:
A) we have an “older HMI hardware&application” written in JAVA and the OS is Android 4.0.3.
Here we have a always reachable master-IP 172.20.30.2.
And yes the customer can configure his 2.IP like he want.
And a actual part is also Modbus-handling with a customers pc-program,
parts with CAN and Parts with RS232. It is a data collector with many different configuerable
Hardware constellations.
This system is often in the field.

B) now we want to replace the older hardware with the ESP32 module.
It is newer, faster and have more possibilities (f.e. WiFi).
The beginning is to program the same basic functions inside the ESP32,
that we can replace it directly without doing any changes around.
Means, we need also the master-IP 172.20.30.2 to configure or update the new unit.

C) on my laptop i try a modbus-program over WiFi, with my PC and a second self-sufficient
“out of our companies network” i try the same with LAN directly.

D) in which mode now ESP32 is working f.e. for Wifi, it is not important.
ESP32 is an accesspoint or the station, that’s not the point.

Hope this helpes you to understand my wish for “172.20.30.2”
SubnetMask is: 255.255.255.0, no Gateway

It seems rather strangely that for softAP you may need to configure the IP after starting it, not before like all the other network functions… :confused:

Thanks everslick for the correct written order.
It works for the moment.
I use delay (200) between each command.
WiFi.mode(WIFI_AP);
delay(200);
bool bWifiState1= WiFi.softAP(…);
delay(200);
wait for SYSTEM_EVENT_AP_START
bool bWifiState2= WiFi.softAPConfig(…)
delay(200);
// start Server…
wifiServer.begin();
delay(200);

During bootup there is no problem with delays…
But to change my IP-Adress to: 172.20.30.2 like written,
i will came back in a few days.

1 Like

…which means your problem is still unsolved?
If so, I still think it is a problem with your overall network configuration. To figure this out we will probably need some back-and-forth so I would offer you to just write me privatly on here (auch auf deutsch :slight_smile:) if you still need help. As soon as we find a solution we can post it here to close this thread.

1 Like

Thanks Thomseen for your feedback.

I will check it again today, and let you know what happens.
First test will be: changing 192.168.x.y
Second test will be: 172.20.30.2

I can give an all-clear for IP: 172.20.30.2.
Everything works fine for the moment.
The solution is after the last tests,
the waiting time: delay(200);
between the config commands,
as i described above.
Thanks again for the support.

1 Like