This repository was archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
42 lines (39 loc) · 1.26 KB
/
init.lua
File metadata and controls
42 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
SSID = "HOME"
PASSWORD = "BE195A5D4B"
MAXATTEMPTS = 5 -- 15-second timeout
MAIN = "main.lua"
function connect()
local attempts = 0
wifi.sta.connect()
if (not tmr.alarm(0, 3000, tmr.ALARM_AUTO, function()
local status = wifi.sta.status()
if wifi.sta.status() == 5 then --Got ip status
tmr.unregister(0)
print("Connection: Connected to "..SSID..", IP: " .. wifi.sta.getip())
dofile(MAIN)
elseif status == 2 then
tmr.unregister(0)
print("Connection: Error: Wrong password.")
elseif status == 3 then
tmr.unregister(0)
print("Connection: Error: Network access point not found.")
elseif status == 4 then
tmr.unregister(0)
print("Connection: Error: Connection failed.")
elseif attempts > MAXATTEMPTS then
tmr.unregister(0)
print("Connection: Error: Timeout.")
if wifi.sta.status() == 0 then print("Connection: Status: idling.") end
if wifi.sta.status() == 1 then print("Connection: Status: connecting.") end
end
attempts = attempts + 1
end
)) then
print("Timer: Error: Unable to start timer. Retrying.")
connect(timeout)
end
end
print("Connection: Connecting to Wi-Fi.")
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID, PASSWORD)
connect()