ESP-07S starts and works but does not register with DHCP server

I have removed a ESP-07S module from the prototype breadboard and soldered it into the newly manufactured PC board.
This particular device was programmed and working in the breadboard and was set to connect to my local WiFi network after checking its EEPROM stored configuration settings.
It was several months ago since it was last powered up.

Now I wanted to check which IP address it had come up with so I looked in my router's admin pages (ASUS RT-AC68U).
But the unit was not listed anywhere in the client list so I hooked up a serial monitor to the debug port of the unit and restarted it. Luckily I have code that sends the current settings out the debug port in order to view the settings it is using. So I could see the unit was connected to my wifi network and also the IP address it uses.
So in the end I could communicate with it.

But it raises a question about when and how the ESP-07S is actually connecting to the WiFi network on startup:
Does it not use the DHCP server on the network if it has once connected successfully?
Or does it cache connection info somewhere to be used on startup to speed things up (it looks like this is what it is doing)?

In my setup() function I am doing a lot before actually starting wifi. This includes reading config from EEPROM where the ssid and password of the network to connect to is stored. Seems like the ESP is (re-)connecting a lot faster than it should if it uses the DHCP server...

BosseB:
In my setup() function I am doing a lot before actually starting wifi. This includes reading config from EEPROM where the ssid and password of the network to connect to is stored. Seems like the ESP is (re-)connecting a lot faster than it should if it uses the DHCP server...

how did you time this?

No on cold boot, if this is what the code asks to do, you'll use DHCP to obtain an address. but some DHCP servers do cache stuff and IP (you are likely to get the same IP again) so may be this is why it's faster ? but I'm surprised you actually see a difference in "user time".... all this is usually pretty fast, depends how you coded stuff

Did you look at the DHCP lease time in your router.
Mine has a default/factory setting of 24hours.

DHCP is a hassle on a LAN.
I like to program a fixed IP into my ESP modules (ignoring DHCP).
Same IP address, even if you haven't used the module past the router's DHCP lease time.
DHCP on a LAN is only ok if you have mDNS running on the module, and use mDNS enabled devices.
Leo..

Wawa:
DHCP is a hassle on a LAN.
I like to program a fixed IP into my ESP modules (ignoring DHCP).
Same IP address, even if you haven't used the module past the router's DHCP lease time.
DHCP on a LAN is only ok if you have mDNS running on the module, and use mDNS enabled devices.
Leo..

I do have a config setting for using a fixed IP address even in station mode. It was included to allow one unit to connect to a local network set up by another unit acting as an AP but without the DHCP.
However, in the case of a regular router how can I get the gateway and DNS values from the DHCP server so the ESP can reach the Internet?

I don't want to hardcode these too. But I guess I can assume that if I set the last octet of the configured fixed IP address to 1 it would reach the typical router's gateway. THis is how I did it when I added the fixed address config item...
Can't be sure about that being valid everywhere, though.

Just thought about DNS now:
DNS might be hardcoded to 8.8.8.8 (Google) or similar? Or OPEN-DNS servers...
How do I set DNS? This is my setup() code for these items:

		if (ESPConf.fixedaddress == 1) //Do not use DHCP, set fixed address
		{
			//The 4 addresses below are (ip, gateway, subnet, DNS1, DNS2) and must be calculated from the used IP address
			local_ip = ESPConf.addr;
			gateway = ESPConf.addr;
			gateway[3] = 1; //Force fake gateway as the first address in the network

			WiFi.config(local_ip, gateway, netmask);
		}
		else
		{
			local_ip = IPAddress(0,0,0,0);
			WiFi.config(local_ip, local_ip, local_ip);	//Reset to use DHCP
		}
		WiFi.hostname(ESPConf.host); //This is the hostrname that should be supplied to the DHCP server
	    WiFi.begin(ESPConf.ssid, ESPConf.passwd);

I've no problem with DHCP in my LAN... not sure why this is a hassle... hundreds of millions of people use that..

J-M-L:
I've no problem with DHCP in my LAN... not sure why this is a hassle... hundreds of millions of people use that..

Me neither, however I have a use case where I need a fixed IP outside of the DHCP range and then the issues arising when using that and trying to connect to the Internet need to be handled. See above (I edited my reply).

usually there are two options:

1/ the dynamic route, you let DHCP configure everything
2/ the hard-coded route, your supply all the parameters. for that you have a mode where the device creates first its own WiFi network and offer a web interface to enter the parameters which are saved in persistant storage, then you reboot and read from that storage how to configure the device.

for option 2, you can consider @tzapu's WiFiManager (cf Introduction to WifiManager-for-Esp8266)

(My reservation on that lib is the heavy use of the String class all over without success testing)

J-M-L:
I've no problem with DHCP in my LAN... not sure why this is a hassle... hundreds of millions of people use that..

  1. You use a Win7 machine (no mDNS).
  2. and have a shortcut in your browser, pointing to the current IP address of the ESP.
  3. You power the ESP off for some time (days, weeks).
  4. The DHCP setting in the router expires
  5. You want to use the ESP again, but the shortcut in the browser doesn't work anymore, because the router has allocated a new/different IP address to the ESP.
  6. You spend 10 minutes finding that new IP address and updating the shortcut.

None of that is needed if you have a fixed IP in the ESP.

If you have a fruit phone (with mDNS), or a PC (with mDNS), then none of the above is a problem either.
You just can use the mDNS name in the browser shortcut.
But with Android phones..., a hassle.
Leo..

Wawa:

  1. You use a Win7 machine (no mDNS).

I've a mac and iPhone :slight_smile:

Wawa:
2) and have a shortcut in your browser, pointing to the current IP address of the ESP.

I don't. My wifi gadget and all iOT stuff are on a totally different network than my trusted computers. I've zero trust in those. I barely talk to them directly, they communicate with a internet hosted platform and I communicate with that platform too. So as long as the device can get to the internet I'm OK

Wawa:
3) You power the ESP off for some time (days, weeks).

Yes, because of the above it's not a pb. The internet hosted service is always there and will tell me it did not hear from my arduinos for a while

Wawa:
4) The DHCP setting in the router expires

The lease can expire, my experience has been that the cache might not. it takes forever at least with my gears for the same IP to be reallocated to a different mac Address.

Wawa:
5) You want to use the ESP again, but the shortcut in the browser doesn't work anymore, because the router has allocated a new/different IP address to the ESP.
6) You spend 10 minutes finding that new IP address and updating the shortcut.

When I mess around my ESP is connected to the Serial port, so it spits out its IP. So it's easy.

:slight_smile: :smiley: :smiley:

J-M-L:
When I mess around my ESP is connected to the Serial port, so it spits out its IP. So it's easy.

That is how I connected to my prototype PCB after moving the ESP-07 from the breadboard to the PCB.
But it is not a good way to do it in production....
One thing I often do is that I add a HTTP call to a PHP script on my webserver in the setup() function, where the current IP is supplied. Then the PHP script either sends it to me as an email or posts it to a text file on the webserver, which I can easily read using any web browser.
But then I need the ESP to be able to reach the Internet, hence have the gateway defined as well as at least one working DNS server.
I have just modified the code to add this (hardcoding OpenDNS servers), so I will soon know if it works OK.

BosseB:
But then I need the ESP to be able to reach the Internet, hence have the gateway defined as well as at least one working DNS server.

that's where the approach used by @tzapu in WiFiManager makes it easy. your ESP can create its own access point, use that as configuration mode, connect from your smartphone, reboot in standard mode and then you are good to go

I should have added that I don't rely on the internet for my ESP project.
Internet is too flaky here, and if it goes down I can't e.g. operate my home lighting anymore.
All the pages of the home lighting dashboard are in the ESP, and it even has AP fallback in case the router fails.
Fixed IP works for me.
Leo..

Wawa:
I should have added that I don't rely on the internet for my ESP project.
Internet is too flaky here, and if it goes down I can't e.g. operate my home lighting anymore.
All the pages of the home lighting dashboard are in the ESP, and it even has AP fallback in case the router fails.
Fixed IP works for me.
Leo..

For a hobby home project I am planning to change the webserver reporting to target a local Linux web server on my internal network rather than use my public webserver via the Internet....

The ESP itself has enough memory (SPIFFS) to store/serve many fancy web pages.
Leo..

Internet is too flaky here, and if it goes down I can't e.g. operate my home lighting anymore.

Hopefully you do still have plain old switches :slight_smile:

Wawa:
The ESP itself has enough memory (SPIFFS) to store/serve many fancy web pages.
Leo..

But I don't think it can run a database server like MySql to store the retrieved data in...
Would be nice if I could put the config stuff into an on-board webpage though. As it is now I have made a TCP server on a special port that can handle simple commands for reading/writing the config stuff. Then I had to also write a program (for the PC), which talks to this TCP server to transfer the config data.
The problem with this approach is that as I modify the flash code in the ESP and need more config items I also have to modify the PC program so it tracks this. And I had to make it such that the PC program must be able to handle ESP units at different levels of the config system since I will not reprogram all of the ESP units when I need a new item for one.
Before I embarked on this I actually googled for on-board solutions but I could not find any good ones to base my design on...

J-M-L:
Hopefully you do still have plain old switches :slight_smile:

Yep, but fancy LED lighting has several backup systems as well.

@ BosseB.
Did you read this guide.
Leo..

Well you can have 1 or 3 megabytes of storage, that’s what SPIFFS offers with a file based type of API.

Running a database would mean your ESP would need to be the SQL server which is doable but would take cycles away from your program and be indeed not super fast.