Verifying connectivity
Posted: Sat Jan 17, 2015 2:07 pm
So I'm writing a LUA script using NodeMCU and I'm wondering wat is the correct way to verify that the ESP8266 is connected to an AP.
OR
What code should I go with and why?
Code: Select all
-- CONFIG --
SSID = "bbox2-1bb0"
PWD = "password"
------------
-- Connect to Wi-Fi network
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID, PWD)
-- Wait for connection
repeat
tmr.delay(1000) -- 1000ms
until wifi.sta.status() == 5 -- STATION_GOT_IP
print("Connected to network " .. SSID)
print("IP: " .. wifi.sta.getip())
OR
Code: Select all
-- CONFIG --
SSID = "bbox2-1bb0"
PWD = "password"
------------
-- Connect to Wi-Fi network
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID, PWD)
-- Wait for connection
repeat
tmr.delay(1000) -- 1000ms
until wifi.sta.getip() ~= nil
print("Connected to network " .. SSID)
print("IP: " .. wifi.sta.getip())
What code should I go with and why?