blob: 9f43d286cfad33835d1d2ea34eaa1f89c2428297 (
plain)
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
|
local wifiConfig = {}
-- wifi.STATION -- station: join a WiFi network
-- wifi.SOFTAP -- access point: create a WiFi network
-- wifi.wifi.STATIONAP -- both station and access point
wifiConfig.mode = wifi.STATIONAP -- both station and access point
wifiConfig.accessPointConfig = {}
wifiConfig.accessPointConfig.ssid = "ESP-"..node.chipid() -- Name of the SSID you want to create
wifiConfig.accessPointConfig.pwd = "ESP-"..node.chipid() -- WiFi password - at least 8 characters
wifiConfig.accessPointIpConfig = {}
wifiConfig.accessPointIpConfig.ip = "192.168.23.1"
wifiConfig.accessPointIpConfig.netmask = "255.255.255.0"
wifiConfig.accessPointIpConfig.gateway = "192.168.23.1"
wifiConfig.stationPointIpConfig = {}
wifiConfig.stationPointIpConfig.ip = "10.160.137.16" -- provided by WM IT department
wifiConfig.stationPointIpConfig.netmask = "255.255.255.0" -- provided by WM IT department
wifiConfig.stationPointIpConfig.gateway = "10.160.137.1" -- provided by WM IT department
wifiConfig.stationPointConfig = {}
wifiConfig.stationPointConfig.ssid = "WM-Welcome" -- Name of the WiFi network you want to join
wifiConfig.stationPointConfig.pwd = "" -- Password for the WiFi network
-- Tell the chip to connect to the access point
wifi.setmode(wifiConfig.mode)
print('set (mode='..wifi.getmode()..')')
if (wifiConfig.mode == wifi.SOFTAP) or (wifiConfig.mode == wifi.STATIONAP) then
print('AP MAC: ',wifi.ap.getmac())
wifi.ap.config(wifiConfig.accessPointConfig)
wifi.ap.setip(wifiConfig.accessPointIpConfig)
end
if (wifiConfig.mode == wifi.STATION) or (wifiConfig.mode == wifi.STATIONAP) then
print('Client MAC: ',wifi.sta.getmac())
wifi.sta.config(wifiConfig.stationPointConfig)
wifi.sta.setip(wifiConfig.stationPointIpConfig)
end
net.dns.setdnsserver("128.239.51.1", 1)
print('DNS Server 1: '..net.dns.getdnsserver(1))
print('IP: '..wifi.sta.getip())
|