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
dcb6e53a
Commit
dcb6e53a
authored
Mar 31, 2015
by
funshine
Browse files
add auto-reconnect option to mqtt:connect api
parent
09750b56
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
dcb6e53a
...
...
@@ -225,8 +225,10 @@ m:on("message", function(conn, topic, data)
end
end
)
-- for secure: m:connect("192.168.11.118", 1880, 1)
m
:
connect
(
"192.168.11.118"
,
1880
,
0
,
function
(
conn
)
print
(
"connected"
)
end
)
-- m:connect( host, port, secure, auto_reconnect, function(client) )
-- for secure: m:connect("192.168.11.118", 1880, 1, 0)
-- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1)
m
:
connect
(
"192.168.11.118"
,
1880
,
0
,
0
,
function
(
conn
)
print
(
"connected"
)
end
)
-- subscribe topic with qos = 0
m
:
subscribe
(
"/topic"
,
0
,
function
(
conn
)
print
(
"subscribe success"
)
end
)
...
...
@@ -235,7 +237,7 @@ m:subscribe("/topic",0, function(conn) print("subscribe success") end)
-- publish a message with data = hello, QoS = 0, retain = 0
m
:
publish
(
"/topic"
,
"hello"
,
0
,
0
,
function
(
conn
)
print
(
"sent"
)
end
)
m
:
close
();
m
:
close
();
-- if auto-reconnect = 1, will reconnect.
-- you can call m:connect again
```
...
...
app/include/user_version.h
View file @
dcb6e53a
...
...
@@ -7,6 +7,6 @@
#define NODE_VERSION_INTERNAL 0U
#define NODE_VERSION "NodeMCU 0.9.5"
#define BUILD_DATE "build 2015033
0
"
#define BUILD_DATE "build 2015033
1
"
#endif
/* __USER_VERSION_H__ */
app/modules/mqtt.c
View file @
dcb6e53a
This diff is collapsed.
Click to expand it.
examples/fragment.lua
View file @
dcb6e53a
...
...
@@ -397,6 +397,8 @@ string.gsub("abc%0Ddef", "%%(%x%x)", ex) print("hello")
v
=
"abc%0D%0Adef"
pcall
(
function
()
print
(
string.gsub
(
v
,
"%%(%x%x)"
,
function
(
x
)
return
string.char
(
tonumber
(
x
,
16
))
end
))
end
)
mosca
-
v
|
bunyan
m
=
mqtt
.
Client
()
m
:
connect
(
"192.168.18.88"
,
1883
)
topic
=
{}
...
...
@@ -426,3 +428,25 @@ m=mqtt.Client()
m
:
on
(
"connect"
,
function
(
m
)
print
(
"connection"
)
end
)
m
:
connect
(
"192.168.18.88"
,
1883
)
m
:
on
(
"offline"
,
function
(
m
)
print
(
"disconnection"
)
end
)
m
=
mqtt
.
Client
()
m
:
on
(
"connect"
,
function
(
m
)
print
(
"connection "
..
node
.
heap
())
end
)
m
:
on
(
"offline"
,
function
(
conn
)
if
conn
==
nil
then
print
(
"conn is nil"
)
end
print
(
"Reconnect to broker..."
)
print
(
node
.
heap
())
conn
:
connect
(
"192.168.18.88"
,
1883
,
0
,
1
)
end
)
m
:
connect
(
"192.168.18.88"
,
1883
,
0
,
1
)
m
=
mqtt
.
Client
()
m
:
on
(
"connect"
,
function
(
m
)
print
(
"connection "
..
node
.
heap
())
end
)
m
:
on
(
"offline"
,
function
(
conn
)
if
conn
==
nil
then
print
(
"conn is nil"
)
end
print
(
"Reconnect to broker..."
)
print
(
node
.
heap
())
conn
:
connect
(
"192.168.18.88"
,
1883
)
end
)
m
:
connect
(
"192.168.18.88"
,
1883
)
m
:
close
()
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