Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
f5fac7a1
Commit
f5fac7a1
authored
Apr 24, 2017
by
dnc40085
Committed by
Marcel Stör
Apr 24, 2017
Browse files
Updated documentation and example for wps.start() (#1933)
parent
572e4235
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/wps.md
View file @
f5fac7a1
...
...
@@ -34,6 +34,9 @@ none
## wps.start()
Start WiFi WPS function. WPS must be enabled prior calling this function.
!!! note
This function only configures the station with the AP's info, it does not connect to AP automatically.
#### Syntax
`wps.start([function(status)])`
...
...
@@ -45,21 +48,95 @@ Start WiFi WPS function. WPS must be enabled prior calling this function.
#### Example
```
lua
wps
.
enable
()
wps
.
start
(
function
(
status
)
if
status
==
wps
.
SUCCESS
then
print
(
"SUCCESS!"
)
elseif
status
==
wps
.
FAILED
then
print
(
"Failed"
)
elseif
status
==
wps
.
TIMEOUT
then
print
(
"Timeout"
)
elseif
status
==
wps
.
WEP
then
print
(
"WEP not supported"
)
elseif
status
==
wps
.
SCAN_ERR
then
print
(
"WPS AP not found"
)
else
print
(
status
)
--Basic example
wifi
.
setmode
(
wifi
.
STATION
)
wps
.
enable
()
wps
.
start
(
function
(
status
)
if
status
==
wps
.
SUCCESS
then
wps
.
disable
()
print
(
"WPS: Success, connecting to AP..."
)
wifi
.
sta
.
connect
()
return
elseif
status
==
wps
.
FAILED
then
print
(
"WPS: Failed"
)
elseif
status
==
wps
.
TIMEOUT
then
print
(
"WPS: Timeout"
)
elseif
status
==
wps
.
WEP
then
print
(
"WPS: WEP not supported"
)
elseif
status
==
wps
.
SCAN_ERR
then
print
(
"WPS: AP not found"
)
else
print
(
status
)
end
wps
.
disable
()
end
)
--Full example
do
-- Register wifi station event callbacks
wifi
.
eventmon
.
register
(
wifi
.
eventmon
.
STA_CONNECTED
,
function
(
T
)
print
(
"
\n\t
STA - CONNECTED"
..
"
\n\t
SSID: "
..
T
.
SSID
..
"
\n\t
BSSID: "
..
T
.
BSSID
..
"
\n\t
Channel: "
..
T
.
channel
)
end
)
wifi
.
eventmon
.
register
(
wifi
.
eventmon
.
STA_GOT_IP
,
function
(
T
)
print
(
"
\n\t
STA - GOT IP"
..
"
\n\t
Station IP: "
..
T
.
IP
..
"
\n\t
Subnet mask: "
..
T
.
netmask
..
"
\n\t
Gateway IP: "
..
T
.
gateway
)
end
)
wifi
.
setmode
(
wifi
.
STATION
)
wps_retry_func
=
function
()
if
wps_retry_count
==
nil
then
wps_retry_count
=
0
end
if
wps_retry_count
<
3
then
wps
.
disable
()
wps
.
enable
()
wps_retry_count
=
wps_retry_count
+
1
wps_retry_timer
=
tmr
.
create
()
wps_retry_timer
:
alarm
(
3000
,
tmr
.
ALARM_SINGLE
,
function
()
wps
.
start
(
wps_cb
)
end
)
print
(
"retry #"
..
wps_retry_count
)
else
wps_retry_count
=
nil
wps_retry_timer
=
nil
wps_retry_func
=
nil
wps_cb
=
nil
end
end
wps_cb
=
function
(
status
)
if
status
==
wps
.
SUCCESS
then
wps
.
disable
()
print
(
"WPS: success, connecting to AP..."
)
wifi
.
sta
.
connect
()
wps_retry_count
=
nil
wps_retry_timer
=
nil
wps_retry_func
=
nil
wps_cb
=
nil
return
elseif
status
==
wps
.
FAILED
then
print
(
"WPS: Failed"
)
wps_retry_func
()
return
elseif
status
==
wps
.
TIMEOUT
then
print
(
"WPS: Timeout"
)
wps_retry_func
()
return
elseif
status
==
wps
.
WEP
then
print
(
"WPS: WEP not supported"
)
elseif
status
==
wps
.
SCAN_ERR
then
print
(
"WPS: AP not found"
)
wps_retry_func
()
return
else
print
(
status
)
end
wps
.
disable
()
wps_retry_count
=
nil
wps_retry_timer
=
nil
wps_retry_func
=
nil
wps_cb
=
nil
end
wps
.
enable
()
wps
.
start
(
wps_cb
)
end
wps
.
disable
()
end
)
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment