Last active
June 13, 2024 15:42
-
-
Save anoochit/33b47539f65bf5c4a91e to your computer and use it in GitHub Desktop.
init.lua for connect to wifi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 5 is not supported anymore.
wifi.sta.config {ssid="SSSID", pwd="Password"}