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
b26ed972
Commit
b26ed972
authored
Feb 12, 2017
by
Marcel Stör
Browse files
Improve MQTT client example, fixes #1792
parent
4dfa5cd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/mqtt.md
View file @
b26ed972
...
@@ -48,18 +48,22 @@ m:on("message", function(client, topic, data)
...
@@ -48,18 +48,22 @@ m:on("message", function(client, topic, data)
end
)
end
)
-- for TLS: m:connect("192.168.11.118", secure-port, 1)
-- for TLS: m:connect("192.168.11.118", secure-port, 1)
m
:
connect
(
"192.168.11.118"
,
1883
,
0
,
function
(
client
)
print
(
"connected"
)
end
,
m
:
connect
(
"192.168.11.118"
,
1883
,
0
,
function
(
client
)
function
(
client
,
reason
)
print
(
"failed reason: "
..
reason
)
end
)
print
(
"connected"
)
-- Calling subscribe/publish only makes sense once the connection
-- Calling subscribe/publish only makes sense once the connection
-- was successfully established. You can do that either here in the
-- was successfully established. In a real-world application you want
-- 'connect' callback or you need to otherwise make sure the
-- move those into the 'connect' callback or make otherwise sure the
-- connection was established (e.g. tracking connection status or in
-- connection was established.
-- m:on("connect", function)).
-- subscribe topic with qos = 0
-- subscribe topic with qos = 0
m
:
subscribe
(
"/topic"
,
0
,
function
(
client
)
print
(
"subscribe success"
)
end
)
client
:
subscribe
(
"/topic"
,
0
,
function
(
client
)
print
(
"subscribe success"
)
end
)
-- publish a message with data = hello, QoS = 0, retain = 0
-- publish a message with data = hello, QoS = 0, retain = 0
m
:
publish
(
"/topic"
,
"hello"
,
0
,
0
,
function
(
client
)
print
(
"sent"
)
end
)
client
:
publish
(
"/topic"
,
"hello"
,
0
,
0
,
function
(
client
)
print
(
"sent"
)
end
)
end
,
function
(
client
,
reason
)
print
(
"failed reason: "
..
reason
)
end
)
m
:
close
();
m
:
close
();
-- you can call m:connect again
-- you can call m:connect again
...
...
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