Skip to content

Instantly share code, notes, and snippets.

@anoochit
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save anoochit/ab4a819474db0aad286d to your computer and use it in GitHub Desktop.

Select an option

Save anoochit/ab4a819474db0aad286d to your computer and use it in GitHub Desktop.
nodemcu dht22 init file
if true then --change to if true
print("set up wifi mode")
wifi.setmode(wifi.STATION)
--please config ssid and password according to settings of your wireless router.
wifi.sta.config("ssid","password")
wifi.sta.connect()
cnt = 0
tmr.alarm(1, 3000, 1, function()
if (wifi.sta.getip() == nil) and (cnt < 20) then
print("IP unavaiable, Waiting...")
cnt = cnt + 1
else
tmr.stop(1)
if (cnt < 20) then print("Config done, IP is "..wifi.sta.getip())
dofile("list.lua")
tmr.alarm(2,5000,1,function()
dofile("script.lua")
end)
else print("Wifi setup time more than 20s, Please verify wifi.sta.config() function. Then re-download the file.")
end
end
end)
else
print("\n")
print("Please edit 'init.lua' first:")
print("Step 1: Modify wifi.sta.config() function in line 5 according settings of your wireless router.")
print("Step 2: Change the 'if false' statement in line 1 to 'if true'.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment