-
Notifications
You must be signed in to change notification settings - Fork 1
/
init_wifi.lua
94 lines (93 loc) · 2.11 KB
/
init_wifi.lua
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function wifi_init()
node_name="new"
node_cssid="driot"
node_assid="D3-iot"
node_cpass="k0d1k0s3"
node_apass="10t-play"
node_wifimode=3 --1=sta/2=ap/3=sta&ap
node_cip="dhcp" --static/dhcp
node_cipaddr="192.168.50.3"
node_cipgw="192.168.50.1"
node_aipaddr="192.168.50.1"
node_aipgw="192.168.50.1"
end
function wifi_setup()
if (boot_status~=true)then
-- recovery mode
-- Client Settings
wifi.setmode(wifi.STATIONAP)
wifi.sta.config(node_cssid,node_cpass)
wifi.sta.sethostname(node_name.."-recovery")
wifi.sta.autoconnect(1)
wifi.sta.connect()
if (node_cip=="static") then
STA_IP_cfg =
{
ip = node_cipaddr,
netmask = "255.255.255.0",
gateway = node_cipgw
}
wifi.sta.setip(STA_IP_cfg)
end
-- AP settings
AP_cfg={}
AP_cfg.ssid=(node_name.."-recovery")
AP_cfg.pwd=node_apass
AP_cfg.auth=3
wifi.ap.config(AP_cfg)
-- IP Address
AP_IP_cfg =
{
ip="192.168.168.168",
netmask="255.255.255.0",
gateway="192.168.168.168"
}
wifi.ap.setip(AP_IP_cfg)
-- Dhcp Server
dhcp_config ={}
dhcp_config.start = "192.168.168.1"
wifi.ap.dhcp.config(dhcp_config)
wifi.ap.dhcp.start()
print("leaving wifi config- failsafe recovery, upload service on port 87")
else
-- normal mode
-- client Settings
wifi.setmode(node_wifimode)
wifi.sta.config(node_cssid,node_cpass)
wifi.sta.sethostname(node_name)
wifi.sta.autoconnect(1)
wifi.sta.connect()
if (node_cip=="static") then
STA_IP_cfg =
{
ip = node_cipaddr,
netmask = "255.255.255.0",
gateway = node_cipgw
}
wifi.sta.setip(STA_IP_cfg)
end
if (node_wifimode==3) then
-- AP settings
AP_cfg={}
AP_cfg.ssid=(node_assid)
AP_cfg.pwd=node_apass
AP_cfg.auth=3
wifi.ap.config(AP_cfg)
-- IP Address
AP_IP_cfg =
{
ip=node_aipaddr,
netmask="255.255.255.0",
gateway=node_aipgw
}
wifi.ap.setip(AP_IP_cfg)
-- Dhcp Server
dhcp_config ={}
dhcp_config.start = "192.168.4.2"
wifi.ap.dhcp.config(dhcp_config)
wifi.ap.dhcp.start()
end
print("leaving wifi config-normal booting")
end
end
--node.compile("init_wifi.lua")