-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME
242 lines (144 loc) · 6.06 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
SYNOPSIS
use AnyEvent::MQTT;
my $mqtt = AnyEvent::MQTT->new;
my $cv = $mqtt->subscribe(topic => '/topic',
callback => sub {
my ($topic, $message) = @_;
print $topic, ' ', $message, "\n"
});
my $qos = $cv->recv; # subscribed, negotiated QoS == $qos
# publish a simple message
$cv = $mqtt->publish(message => 'simple message',
topic => '/topic');
$cv->recv; # sent
# publish line-by-line from file handle
$cv = $mqtt->publish(handle => \*STDIN,
topic => '/topic');
$cv->recv; # sent
# publish from AnyEvent::Handle
$cv = $mqtt->publish(handle => AnyEvent::Handle->new(my %handle_args),
topic => '/topic');
$cv->recv; # sent
DESCRIPTION
AnyEvent module for MQTT client.
IMPORTANT: This is an early release and the API is still subject to
change.
DISCLAIMER
This is not official IBM code. I work for IBM but I'm writing this in
my spare time (with permission) for fun.
Constructs a new AnyEvent::MQTT object. The supported parameters are:
host
The server host. Defaults to 127.0.0.1.
port
The server port. Defaults to 1883.
timeout
The timeout for responses from the server.
keep_alive_timer
The keep alive timer.
user_name
The user name for the MQTT broker.
password
The password for the MQTT broker.
tls
Set flag to enable TLS encryption, Default is no encryption.
will_topic
Set topic for will message. Default is undef which means no will
message will be configured.
will_qos
Set QoS for will message. Default is 'at-most-once'.
will_retain
Set retain flag for will message. Default is 0.
will_message
Set message for will message. Default is the empty message.
clean_session
Set clean session flag for connect message. Default is 1.
client_id
Sets the client id for the client overriding the default which is
NetMQTTpmNNNNN where NNNNN is the current process id.
message_log_callback
Defines a callback to call on every message.
on_error
Defines a callback to call when some error occurs.
Two parameters are passed to the callback.
$on_error->($fatal, $message)
where $fatal is a boolean flag and $message is the error message. If
the error is fatal, $fatal is true.
handle_args
a reference to a list to pass as arguments to the
L<AnyEvent::Handle> constructor (defaults to
an empty list reference).
This method attempts to destroy any resources in the event of a
disconnection or fatal error.
This method is used to publish to a given topic. It returns an AnyEvent
condvar which is notified when the publish is complete (written to the
kernel or ack'd depending on the QoS level). The parameter hash must
included at least a topic value and one of:
message
with a string value which is published to the topic,
handle
the value of which must either be an L<AnyEvent::Handle> or will be
passed to an L<AnyEvent::Handle> constructor as the C<fh> argument.
The L<push_read()> method is called on the L<AnyEvent::Handle> with a
callback that will publish each chunk read to the topic.
The parameter hash may also keys for:
qos
to set the QoS level for published messages (default
MQTT_QOS_AT_MOST_ONCE),
handle_args
a reference to a list to pass as arguments to the
L<AnyEvent::Handle> constructor in the final case above (defaults to
an empty list reference), or
push_read_args
a reference to a list to pass as the arguments to the
L<AnyEvent::Handle#push_read> method (defaults to ['line'] to read,
and subsequently publish, a line at a time.
Returns a 16-bit number to use as the next message id in a message
requiring an acknowledgement.
This method subscribes to the given topic. The parameter hash may
contain values for the following keys:
topic
for the topic to subscribe to (this is required),
callback
for the callback to call with messages (this is required),
qos
QoS level to use (default is MQTT_QOS_AT_MOST_ONCE),
cv
L<AnyEvent> condvar to use to signal the subscription is complete.
The received value will be the negotiated QoS level.
This method returns the value of the cv parameter if it was supplied or
an AnyEvent condvar created for this purpose.
This method unsubscribes to the given topic. The parameter hash may
contain values for the following keys:
topic
for the topic to unsubscribe from (this is required),
callback
for the callback to call with messages (this is optional and currently
not supported - all callbacks are unsubscribed),
cv
L<AnyEvent> condvar to use to signal the unsubscription is complete.
This method returns the value of the cv parameter if it was supplied or
an AnyEvent condvar created for this purpose.
This method starts the connection to the server. It will be called
lazily when required publish or subscribe so generally is should not be
necessary to call it directly.
This method is used to register an AnyEvent::Handle read type method to
read MQTT messages.
POD ERRORS
Hey! The above document had some coding errors, which are explained
below:
Around line 39:
Unknown directive: =method
Around line 123:
Unknown directive: =method
Around line 128:
Unknown directive: =method
Around line 174:
Unknown directive: =method
Around line 179:
Unknown directive: =method
Around line 208:
Unknown directive: =method
Around line 233:
Unknown directive: =method
Around line 239:
Unknown directive: =method