|
99 | 99 | uart.setup(0, 115200, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0) |
100 | 100 | uart.on('data', "\n", handle_uart, 0) |
101 | 101 |
|
102 | | --- Create AP for configuration |
103 | | -wifi.ap.config({ssid = 'hackAIR-'..node.chipid(), pwd = 'hackAIR-'..node.chipid()}) |
104 | | - |
105 | | --- Manual mode |
106 | | -enduser_setup.manual(true) |
107 | | -enduser_setup.start( |
108 | | - function() |
109 | | - -- WiFi information is stored in wifi.sta.config so we don't have |
110 | | - -- to do anything special here. |
111 | | - |
112 | | - -- Print debug info |
113 | | - print('Connected to wifi as:' .. wifi.sta.getip()) |
114 | | - tmr.create()::alarm(10000, tmr.ALARM_SINGLE, function() |
115 | | - print('Turning off AP') |
116 | | - enduser_setup.stop() |
117 | | - end) |
118 | | - end, |
119 | | - function(err, str) |
120 | | - print('enduser_setup: Err #' .. err .. ': ' .. str) |
121 | | - end) |
| 102 | +ssid, password, bssid_set, bssid = wifi.sta.getconfig() |
| 103 | +if ssid == '' then |
| 104 | + print('No WiFi configuration stored, going into AP mode') |
| 105 | + enduser_setup.start( |
| 106 | + function() |
| 107 | + -- Print debug info |
| 108 | + ssid, password, bssid_set, bssid = wifi.sta.getconfig() |
| 109 | + print('Connected to '.. ssid .. ' with password ' .. password .. ' as: ' .. wifi.sta.getip()) |
| 110 | + end, |
| 111 | + function(err, str) |
| 112 | + print('enduser_setup: Err #' .. err .. ': ' .. str) |
| 113 | + end |
| 114 | + ) |
| 115 | +else |
| 116 | + wifi.setmode(wifi.STATION) |
| 117 | + wifi.sta.connect() |
| 118 | +end |
122 | 119 |
|
123 | 120 | -- Display a warning message to the prompt |
124 | 121 | print('hackAir ESP Firmware') |
|
0 commit comments