Post your best Lua script examples here

User avatar
By 8art-5imson
#27949 I am trying to get a reliable connection between my esp and router so i can start converting my home automation/IOT stuff to MQTT. i have stripped down my code to the following:
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
wifi.sta.connect()

print(wifi.sta.getip())

I then press "Send to ESP" in ESPlorer it loads it then runs it .... all good.
but then if i reset the board i get "nil" returned as the IP address, the only way to get it to connect again is to "FORMAT" then reload it !
in other words it will only connect once.
i have tried delays, and loops to keep trying until it connects, but wifi status is always 1 not 5.
please can anyone help.. i am very new to LUA.