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
360fb59e
Commit
360fb59e
authored
Jan 23, 2015
by
funshine
Browse files
add tcp2uart.lua example
parent
9b472a46
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/fragment.lua
View file @
360fb59e
...
...
@@ -319,3 +319,21 @@ m:connect("192.168.18.101",1883)
m
:
subscribe
(
"/topic"
,
0
,
function
(
m
)
print
(
"sub done"
)
end
)
m
:
on
(
"message"
,
function
(
m
,
t
,
pl
)
print
(
t
..
":"
)
if
pl
~=
nil
then
print
(
pl
)
end
end
)
m
:
publish
(
"/topic"
,
"hello"
,
0
,
0
)
uart
.
setup
(
0
,
9600
,
8
,
0
,
1
,
0
)
sv
=
net
.
createServer
(
net
.
TCP
,
60
)
global_c
=
nil
sv
:
listen
(
9999
,
function
(
c
)
if
global_c
~=
nil
then
global_c
:
close
()
end
global_c
=
c
c
:
on
(
"receive"
,
function
(
sck
,
pl
)
uart
.
write
(
0
,
pl
)
end
)
end
)
uart
.
on
(
"data"
,
4
,
function
(
data
)
if
global_c
~=
nil
then
global_c
:
send
(
data
)
end
end
,
0
)
lua_examples/tcp2uart.lua
0 → 100644
View file @
360fb59e
uart
.
setup
(
0
,
9600
,
8
,
0
,
1
,
0
)
sv
=
net
.
createServer
(
net
.
TCP
,
60
)
global_c
=
nil
sv
:
listen
(
9999
,
function
(
c
)
if
global_c
~=
nil
then
global_c
:
close
()
end
global_c
=
c
c
:
on
(
"receive"
,
function
(
sck
,
pl
)
uart
.
write
(
0
,
pl
)
end
)
end
)
uart
.
on
(
"data"
,
4
,
function
(
data
)
if
global_c
~=
nil
then
global_c
:
send
(
data
)
end
end
,
0
)
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