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
b6185c88
Commit
b6185c88
authored
Jan 26, 2015
by
funshine
Browse files
add udp example to readme
parent
afa741c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
b6185c88
...
@@ -172,6 +172,20 @@ baudrate:9600
...
@@ -172,6 +172,20 @@ baudrate:9600
..
"Connection: keep-alive\r\nAccept: */*\r\n\r\n"
)
..
"Connection: keep-alive\r\nAccept: */*\r\n\r\n"
)
```
```
####Or a simple http server
```
lua
-- A simple http server
srv
=
net
.
createServer
(
net
.
TCP
)
srv
:
listen
(
80
,
function
(
conn
)
conn
:
on
(
"receive"
,
function
(
conn
,
payload
)
print
(
payload
)
conn
:
send
(
"<h1> Hello, NodeMcu.</h1>"
)
end
)
conn
:
on
(
"sent"
,
function
(
conn
)
conn
:
close
()
end
)
end
)
```
####Connect to MQTT Broker
####Connect to MQTT Broker
```
lua
```
lua
...
@@ -208,18 +222,18 @@ m:close();
...
@@ -208,18 +222,18 @@ m:close();
```
```
####Or a simple http server
#### UDP client and server
```
lua
```
lua
-- A simple http server
-- a udp server
srv
=
net
.
createServer
(
net
.
TCP
)
s
=
net
.
createServer
(
net
.
UDP
)
srv
:
listen
(
80
,
function
(
conn
)
s
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
end
)
conn
:
on
(
"receive"
,
function
(
conn
,
payload
)
s
:
listen
(
5683
)
print
(
payload
)
conn
:
send
(
"<h1> Hello, NodeMcu.</h1>"
)
-- a udp client
end
)
cu
=
net
.
createConnection
(
net
.
UDP
)
conn
:
on
(
"sent"
,
function
(
conn
)
conn
:
close
()
end
)
cu
:
on
(
"receive"
,
function
(
cu
,
c
)
print
(
c
)
end
)
end
)
cu
:
connect
(
5683
,
"192.168.18.101"
)
cu
:
send
(
"hello"
)
```
```
####Do something shining
####Do something shining
...
...
examples/fragment.lua
View file @
b6185c88
...
@@ -25,15 +25,19 @@ ss=net.createServer(net.TCP) ss:listen(80,function(c) end)
...
@@ -25,15 +25,19 @@ ss=net.createServer(net.TCP) ss:listen(80,function(c) end)
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
80
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
end
)
end
)
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
80
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
end
)
end
)
s
=
net
.
createServer
(
net
.
UDP
)
s
:
listen
(
5683
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
end
)
end
)
s
=
net
.
createServer
(
net
.
UDP
)
s
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
end
)
s
:
listen
(
5683
)
su
=
net
.
createConnection
(
net
.
UDP
)
su
:
on
(
"receive"
,
function
(
su
,
c
)
print
(
c
)
end
)
su
:
connect
(
5683
,
"192.168.18.101"
)
su
:
send
(
"hello"
)
mm
=
node
.
list
()
mm
=
node
.
list
()
for
k
,
v
in
pairs
(
mm
)
do
print
(
'file:'
..
k
..
' len:'
..
v
)
end
for
k
,
v
in
pairs
(
mm
)
do
print
(
'file:'
..
k
..
' len:'
..
v
)
end
for
k
,
v
in
pairs
(
d
)
do
print
(
"n:"
..
k
..
", s:"
..
v
)
end
for
k
,
v
in
pairs
(
d
)
do
print
(
"n:"
..
k
..
", s:"
..
v
)
end
su
=
net
.
createConnection
(
net
.
UDP
)
su
:
on
(
"receive"
,
function
(
su
,
c
)
print
(
c
)
end
)
su
:
connect
(
5683
,
"192.168.0.66"
)
su
:
send
(
"/v1/id"
)
gpio
.
mode
(
0
,
gpio
.
INT
)
gpio
.
trig
(
0
,
"down"
,
function
(
l
)
print
(
"level="
..
l
)
end
)
gpio
.
mode
(
0
,
gpio
.
INT
)
gpio
.
trig
(
0
,
"down"
,
function
(
l
)
print
(
"level="
..
l
)
end
)
...
@@ -57,8 +61,6 @@ su:send("hello world")
...
@@ -57,8 +61,6 @@ su:send("hello world")
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
8008
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
pcall
(
loadstring
(
c
))
end
)
end
)
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
8008
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
pcall
(
loadstring
(
c
))
end
)
end
)
s
=
net
.
createServer
(
net
.
UDP
)
s
:
listen
(
8888
,
function
(
c
)
c
:
on
(
"receive"
,
function
(
s
,
c
)
print
(
c
)
pcall
(
loadstring
(
c
))
end
)
end
)
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
8008
,
function
(
c
)
con_std
=
c
function
s_output
(
str
)
if
(
con_std
~=
nil
)
then
con_std
:
send
(
str
)
end
end
s
=
net
.
createServer
(
net
.
TCP
)
s
:
listen
(
8008
,
function
(
c
)
con_std
=
c
function
s_output
(
str
)
if
(
con_std
~=
nil
)
then
con_std
:
send
(
str
)
end
end
node
.
output
(
s_output
,
0
)
c
:
on
(
"receive"
,
function
(
c
,
l
)
node
.
input
(
l
)
end
)
c
:
on
(
"disconnection"
,
function
(
c
)
con_std
=
nil
node
.
output
(
nil
)
end
)
end
)
node
.
output
(
s_output
,
0
)
c
:
on
(
"receive"
,
function
(
c
,
l
)
node
.
input
(
l
)
end
)
c
:
on
(
"disconnection"
,
function
(
c
)
con_std
=
nil
node
.
output
(
nil
)
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