1
1
--- MQTT module
2
2
-- @module mqtt
3
+ -- @usage
4
+ -- local client = mqtt.client {
5
+ -- uri = "mqtts://aladdin:[email protected] ",
6
+ -- clean = true,
7
+ -- version = mqtt.v50, -- specify constant for MQTT version
8
+ -- }
3
9
4
10
--[[
5
11
MQTT protocol DOC: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html
@@ -18,13 +24,6 @@ CONVENTIONS:
18
24
-- @tfield number v50 MQTT v5.0 protocol version constant
19
25
-- @tfield string _VERSION luamqtt library version string
20
26
-- @table mqtt
21
- -- @see mqtt.const
22
- -- @usage
23
- -- local client = mqtt.client {
24
- -- uri = "mqtts://aladdin:[email protected] ",
25
- -- clean = true,
26
- -- version = mqtt.v50, -- specify constant for MQTT version
27
- -- }
28
27
local mqtt = {}
29
28
30
29
-- copy all values from const module
@@ -47,6 +46,7 @@ local ioloop_get = ioloop.get
47
46
48
47
--- Create new MQTT client instance
49
48
-- @param ... Same as for `Client.create`(...)
49
+ -- @treturn Client new client instance
50
50
-- @see Client:__init
51
51
function mqtt .client (...)
52
52
return client_create (... )
76
76
77
77
78
78
--- Validates a topic with wildcards.
79
- -- @param t (string) wildcard topic to validate
80
- -- @return topic, or false+error
79
+ -- @tparam string t wildcard-topic to validate
80
+ -- @treturn [1] string the input topic if valid
81
+ -- @treturn [2] boolean false if invalid
82
+ -- @treturn [2] string error description
81
83
-- @usage local t = assert(mqtt.validate_subscribe_topic("base/+/thermostat/#"))
82
84
function mqtt .validate_subscribe_topic (t )
83
85
if type (t ) ~= " string" then
@@ -114,8 +116,10 @@ function mqtt.validate_subscribe_topic(t)
114
116
end
115
117
116
118
--- Validates a topic without wildcards.
117
- -- @param t (string) topic to validate
118
- -- @return topic, or false+error
119
+ -- @tparam string t topic to validate
120
+ -- @treturn [1] string the input topic if valid
121
+ -- @treturn [2] boolean false if invalid
122
+ -- @treturn [2] string error description
119
123
-- @usage local t = assert(mqtt.validate_publish_topic("base/living/thermostat/setpoint"))
120
124
function mqtt .validate_publish_topic (t )
121
125
if type (t ) ~= " string" then
133
137
--- Returns a Lua pattern from topic.
134
138
-- Takes a wildcarded-topic and returns a Lua pattern that can be used
135
139
-- to validate if a received topic matches the wildcard-topic
136
- -- @param t (string) the wildcard topic
137
- -- @return Lua-pattern (string) or false+err
140
+ -- @tparam string t the wildcard topic
141
+ -- @treturn [1] string Lua-pattern that matches the topic and returns the captures
142
+ -- @treturn [2] boolean false if the topic was invalid
143
+ -- @treturn [2] string error description
138
144
-- @usage
139
145
-- local patt = compile_topic_pattern("homes/+/+/#")
140
146
--
@@ -171,7 +177,7 @@ function mqtt.compile_topic_pattern(t)
171
177
end
172
178
173
179
--- Parses wildcards in a topic into a table.
174
- -- @tparam topic string incoming topic string
180
+ -- @tparam string topic incoming topic string
175
181
-- @tparam table opts parsing options table
176
182
-- @tparam string opts.topic the wild-carded topic to match against (optional if `opts.pattern` is given)
177
183
-- @tparam string opts.pattern the compiled pattern for the wild-carded topic (optional if `opts.topic`
0 commit comments