Skip to content

Instantly share code, notes, and snippets.

@anoochit
Last active June 13, 2024 15:42
Show Gist options
  • Select an option

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

Select an option

Save anoochit/33b47539f65bf5c4a91e to your computer and use it in GitHub Desktop.
init.lua for connect to wifi
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("yourfile.lua")
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
@styks1111

Copy link
Copy Markdown

Line 5 is not supported anymore.

wifi.sta.config {ssid="SSSID", pwd="Password"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment