diff options
Diffstat (limited to 'wifi_config.lua')
-rw-r--r-- | wifi_config.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/wifi_config.lua b/wifi_config.lua new file mode 100644 index 0000000..9f43d28 --- /dev/null +++ b/wifi_config.lua @@ -0,0 +1,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())
+
|