As the title says... Chat on...

User avatar
By Eyal
#19034 How does wifi.sta.autoconnect() work? If I set it, will it be saved for the next wakeup? When should I set it?

I want to use static IP to speed up my application. I used wifi.sta.setip() and it works, but it does not get saved and if I do not call it then on the next wakeup DHCP is used.

In short, what is the correct way to use a static IP? At what stage of my application should I call the above two (if both are necessary at all)? What information is saved (if any) and what I should redo after a restart?

TIA
User avatar
By TerryE
#19044
Eyal wrote:How does wifi.sta.autoconnect() work? If I set it, will it be saved for the next wakeup? When should I set it?
What this does to complete any connection as part of the first net.createServer(). It doesn't materially speed up the first connection.

Eyal wrote:I want to use static IP to speed up my application. I used wifi.sta.setip() and it works, but it does not get saved and if I do not call it then on the next wakeup DHCP is used.
Using static IP doesn't really speed up anything apart from the initial DHCP negotiation which only takes a second or so on first boot. There are valid reasons to use static IP, but this isn't really one of them

Eyal wrote:In short, what is the correct way to use a static IP? At what stage of my application should I call the above two (if both are necessary at all)? What information is saved (if any) and what I should redo after a restart?

You have to do it during the init.luasequence on every boot. The easiest way is to write your config info to a short device-specific config.lua file and simply dofile("config.lua") during the inital boot sequences. This can also set a CONFIG global variable containing any other device-specific parameters, if you wish.
User avatar
By Eyal
#19075 Thanks @TerryE

In case it is not clear, I am not attempting to set up a server, only a client connection (TCP and UDP) to a server.

So, do I need to call autoconnect(0)? Is it involved at all in this scenario?

Also, saving one second of DHCP negotiation is important when the whole other activity is less than one second. As for "on first boot" - this is not what I see, the DHCP dance is repeated on every boot (wakeup).
User avatar
By TerryE
#19099 If you are only using a client then DHCP should be fine.

What concerns me somewhat more is if your hardware configuration is going through app/user/user_main.c:user_init() on every wake up as this clears areas of the Flash memory and intialises SPIFFS and if you are writing to Flash with this frequency then your module will have a very limited life. See my draft section in my ESP8266 wiki page on this