Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
2cc195d5
Commit
2cc195d5
authored
Jun 04, 2018
by
Gergo Huszty
Committed by
Marcel Stör
Jun 04, 2018
Browse files
webap_toggle_pin.lua HTML warnings and typos fixed (#2394)
parent
994e8faa
Changes
1
Show whitespace changes
Inline
Side-by-side
lua_examples/webap_toggle_pin.lua
View file @
2cc195d5
wifi
.
setmode
(
wifi
.
SOFTAP
)
wifi
.
ap
.
config
({
ssid
=
"test"
,
pwd
=
"12345678"
})
wifi
.
ap
.
config
({
ssid
=
"test"
,
pwd
=
"12345678"
})
gpio
.
mode
(
1
,
gpio
.
OUTPUT
)
srv
=
net
.
createServer
(
net
.
TCP
)
srv
:
listen
(
80
,
function
(
conn
)
conn
:
on
(
"receive"
,
function
(
client
,
request
)
srv
=
net
.
createServer
(
net
.
TCP
)
srv
:
listen
(
80
,
function
(
conn
)
conn
:
on
(
"receive"
,
function
(
client
,
request
)
local
buf
=
""
local
_
,
_
,
method
,
path
,
vars
=
string.find
(
request
,
"([A-Z]+) (.+)?(.+) HTTP"
)
if
(
method
==
nil
)
then
if
(
method
==
nil
)
then
_
,
_
,
method
,
path
=
string.find
(
request
,
"([A-Z]+) (.+) HTTP"
)
end
local
_GET
=
{}
if
(
vars
~=
nil
)
then
if
(
vars
~=
nil
)
then
for
k
,
v
in
string.gmatch
(
vars
,
"(%w+)=(%w+)&*"
)
do
_GET
[
k
]
=
v
end
end
buf
=
buf
..
"<h1>
Hello, NodeM
cu
.</h1><form src=\"
/
\
">Turn PIN1 <select name=\"
pin
\
" onchange=\"
form
.
submit
()
\
">"
local
_on
,
_off
=
""
,
""
if
(
_GET
.
pin
==
"ON"
)
then
buf
=
buf
..
"<
!DOCTYPE html><html><body><
h1>Hello,
this is
NodeM
CU
.</h1><form src=\"
/
\
">Turn PIN1 <select name=\"
pin
\
" onchange=\"
form
.
submit
()
\
">"
local
_on
,
_off
=
""
,
""
if
(
_GET
.
pin
==
"ON"
)
then
_on
=
" selected=true"
gpio
.
write
(
1
,
gpio
.
HIGH
)
elseif
(
_GET
.
pin
==
"OFF"
)
then
elseif
(
_GET
.
pin
==
"OFF"
)
then
_off
=
" selected=\"
true
\
""
gpio
.
write
(
1
,
gpio
.
LOW
)
end
buf
=
buf
..
"<option"
..
_on
..
">ON</opton><option"
..
_off
..
">OFF</option></select></form>"
buf
=
buf
..
"<option"
..
_on
..
">ON</opt
i
on><option"
..
_off
..
">OFF</option></select></form>
</body></html>
"
client
:
send
(
buf
)
end
)
conn
:
on
(
"sent"
,
function
(
c
)
c
:
close
()
end
)
conn
:
on
(
"sent"
,
function
(
c
)
c
:
close
()
end
)
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