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

User avatar
By Warthog
#4662 Hi,
with this code:
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
wifi.sta.connect()

I try to get an IP from my network. But the problem is that the function is not waiting until an IP address is given.
So in my scripts other lines of code do not work because of missing IP.

Is there a mechanism to wait for the IP?

I tried with a
Code: Select allwhile (wifi.sta.getip()!=nil)
, but this does not work.
A constant timer will also not work because the delay may vary.

Any ideas?
User avatar
By GeoNomad
#4677
Warthog wrote:Hi,
with this code:
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
wifi.sta.connect()

I try to get an IP from my network. But the problem is that the function is not waiting until an IP address is given.
So in my scripts other lines of code do not work because of missing IP.

Is there a mechanism to wait for the IP?

I tried with a
Code: Select allwhile (wifi.sta.getip()!=nil)
, but this does not work.
A constant timer will also not work because the delay may vary.

Any ideas?


Check out this post viewtopic.php?f=19&t=827
User avatar
By jankop
#4686 Hi,
try and modify this for you:
Code: Select alltmr.alarm(1,1000, 1, function() if wifi.sta.getip()==nil then print(" Wait to IP address!") else print("New IP address is "..wifi.sta.getip()) tmr.stop(1) end end)

It is tested with Lua 141212
User avatar
By hwiguna
#4718
jankop wrote:Hi,
try and modify this for you:
Code: Select alltmr.alarm(1,1000, 1, function() if wifi.sta.getip()==nil then print(" Wait to IP address!") else print("New IP address is "..wifi.sta.getip()) tmr.stop(1) end end)

It is tested with Lua 141212

Jankop, that's a neat trick! Thank you for sharing.