mosquitto 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +29 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +25 -0
- data/LICENSE.md +13 -0
- data/README.md +244 -0
- data/Rakefile +42 -0
- data/TODO.md +19 -0
- data/examples/pub_sub.rb +41 -0
- data/ext/mosquitto/client.c +2163 -0
- data/ext/mosquitto/client.h +145 -0
- data/ext/mosquitto/extconf.rb +31 -0
- data/ext/mosquitto/message.c +168 -0
- data/ext/mosquitto/message.h +16 -0
- data/ext/mosquitto/mosquitto_ext.c +88 -0
- data/ext/mosquitto/mosquitto_ext.h +35 -0
- data/ext/mosquitto/mosquitto_prelude.h +26 -0
- data/ext/mosquitto/rubinius.h +6 -0
- data/ext/mosquitto/ruby18.h +6 -0
- data/ext/mosquitto/ruby19.h +9 -0
- data/ext/mosquitto/ruby2.h +6 -0
- data/lib/mosquitto.rb +11 -0
- data/lib/mosquitto/client.rb +8 -0
- data/lib/mosquitto/logging.rb +32 -0
- data/lib/mosquitto/version.rb +5 -0
- data/mosquitto.gemspec +23 -0
- data/test/helper.rb +59 -0
- data/test/ssl/all-ca.crt +75 -0
- data/test/ssl/client-expired.crt +61 -0
- data/test/ssl/client-revoked.crt +61 -0
- data/test/ssl/client-revoked.csr +12 -0
- data/test/ssl/client-revoked.key +15 -0
- data/test/ssl/client.crt +61 -0
- data/test/ssl/client.csr +12 -0
- data/test/ssl/client.key +15 -0
- data/test/ssl/crl.pem +10 -0
- data/test/ssl/demoCA/crlnumber +1 -0
- data/test/ssl/demoCA/index.txt +1 -0
- data/test/ssl/demoCA/index.txt.attr +1 -0
- data/test/ssl/demoCA/serial +1 -0
- data/test/ssl/gen.sh +70 -0
- data/test/ssl/mosquitto.org.crt +18 -0
- data/test/ssl/openssl.cnf +406 -0
- data/test/ssl/readme.txt +2 -0
- data/test/ssl/rootCA/crlnumber +1 -0
- data/test/ssl/rootCA/index.txt +2 -0
- data/test/ssl/rootCA/index.txt.attr +1 -0
- data/test/ssl/rootCA/serial +1 -0
- data/test/ssl/server-expired.crt +0 -0
- data/test/ssl/server.crt +60 -0
- data/test/ssl/server.csr +12 -0
- data/test/ssl/server.key +15 -0
- data/test/ssl/signingCA/crlnumber +1 -0
- data/test/ssl/signingCA/index.txt +4 -0
- data/test/ssl/signingCA/index.txt.attr +1 -0
- data/test/ssl/signingCA/serial +1 -0
- data/test/ssl/test-alt-ca.crt +58 -0
- data/test/ssl/test-alt-ca.key +15 -0
- data/test/ssl/test-bad-root-ca.crt +17 -0
- data/test/ssl/test-bad-root-ca.key +15 -0
- data/test/ssl/test-ca.srl +1 -0
- data/test/ssl/test-fake-root-ca.crt +17 -0
- data/test/ssl/test-fake-root-ca.key +15 -0
- data/test/ssl/test-root-ca.crt +17 -0
- data/test/ssl/test-root-ca.key +15 -0
- data/test/ssl/test-signing-ca.crt +58 -0
- data/test/ssl/test-signing-ca.key +15 -0
- data/test/test_callbacks.rb +93 -0
- data/test/test_client.rb +141 -0
- data/test/test_custom_logger.rb +30 -0
- data/test/test_integration.rb +572 -0
- data/test/test_loops.rb +56 -0
- data/test/test_mosquitto.rb +28 -0
- data/test/test_pub_sub.rb +51 -0
- data/test/test_threads.rb +69 -0
- data/test/test_tls.rb +67 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92a30539c75dec74a32576327cc88bd883502e89
|
4
|
+
data.tar.gz: 7d44ae4edbd3c241ba38048d1ae46ec1e2948194
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99410f286d02e75c29f7663522c8b8a9f05bb35ccb7fce3f0e9ed8b6ea95b560ec2bd217dfc4c576db50bc38125a63d686cc4bcc3caf56ee77951dbe1e7a22d1
|
7
|
+
data.tar.gz: 49240900ce920a90cb5d5be4a7a5b9add7d576b1edf236b8623b0d95b4c9fb54879a86f20821ead46ba6d62f11674aa14ec9c1fb3ee307742781a84b120021e7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_install:
|
3
|
+
- sudo apt-get update -qq
|
4
|
+
- sudo apt-get install pkg-config cmake openssl
|
5
|
+
- wget http://mosquitto.org/files/source/mosquitto-1.2.3.tar.gz
|
6
|
+
install:
|
7
|
+
- tar xzf mosquitto-1.2.3.tar.gz
|
8
|
+
- cd mosquitto-1.2.3
|
9
|
+
- cmake .
|
10
|
+
- sudo make install
|
11
|
+
- bundle install
|
12
|
+
bundler_args: --quiet
|
13
|
+
rvm:
|
14
|
+
- 1.9.3
|
15
|
+
- 2.0
|
16
|
+
- 2.1
|
17
|
+
- 2.1.1
|
18
|
+
env:
|
19
|
+
- GC_STRESS=0
|
20
|
+
- GC_STRESS=1
|
21
|
+
script: "bundle exec rake"
|
22
|
+
gemfile:
|
23
|
+
- Gemfile
|
24
|
+
notifications:
|
25
|
+
recipients:
|
26
|
+
- lourens@methodmissing.com
|
27
|
+
branches:
|
28
|
+
only:
|
29
|
+
- master
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mosquitto (0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
json (1.8.1)
|
10
|
+
rake (10.1.1)
|
11
|
+
rake-compiler (0.9.2)
|
12
|
+
rake
|
13
|
+
rdoc (4.1.1)
|
14
|
+
json (~> 1.4)
|
15
|
+
yard (0.8.7.3)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
mosquitto!
|
22
|
+
rake
|
23
|
+
rake-compiler (~> 0.9.2)
|
24
|
+
rdoc
|
25
|
+
yard
|
data/LICENSE.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
###This library is Open Source, under the BSD 3-Clause license.
|
2
|
+
|
3
|
+
Copyright © 2003-2014 LogMeIn, Inc.
|
4
|
+
|
5
|
+
All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
11
|
+
3. Neither the names of LogMeIn, Inc., nor Xively Ltd., nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOGMEIN, INC. OR XIVELY LTD. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
# mosquitto - a high perf MQTT 3.1 client
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/xively/mosquitto.png)](https://travis-ci.org/xively/mosquitto)
|
4
|
+
|
5
|
+
The mosquitto gem is meant to serve as an easy, performant and standards compliant client for interacting with MQTT brokers.
|
6
|
+
|
7
|
+
The API consists of two classes:
|
8
|
+
|
9
|
+
[Mosquitto::Client](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client) - the client
|
10
|
+
|
11
|
+
[Mosquitto::Message](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Message) - returned from the client
|
12
|
+
|
13
|
+
## About MQTT and libmosquitto
|
14
|
+
|
15
|
+
[MQ Telemetry Transport](http://mqtt.org/) is :
|
16
|
+
|
17
|
+
```
|
18
|
+
MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging
|
19
|
+
protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design
|
20
|
+
principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure
|
21
|
+
reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of
|
22
|
+
the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile
|
23
|
+
applications where bandwidth and battery power are at a premium.
|
24
|
+
```
|
25
|
+
Please see the [FAQ](http://mqtt.org/faq) and [list of supported software](http://mqtt.org/wiki/software).
|
26
|
+
|
27
|
+
### libmosquitto
|
28
|
+
|
29
|
+
```
|
30
|
+
Mosquitto is an open source (BSD licensed) message broker that implements the MQ Telemetry Transport protocol
|
31
|
+
version 3.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This
|
32
|
+
makes it suitable for "machine to machine" messaging such as with low power sensors or mobile devices such as
|
33
|
+
phones, embedded computers or microcontrollers like the Arduino.
|
34
|
+
```
|
35
|
+
|
36
|
+
See the [project website](http://mosquitto.org/) for more information.
|
37
|
+
|
38
|
+
## Requirements
|
39
|
+
|
40
|
+
This gem links against version 1.2.3 of `libmosquitto` . You will need to install additional packages for your system.
|
41
|
+
|
42
|
+
### OS X
|
43
|
+
|
44
|
+
The preferred installation method for libmosquitto on OS X is with the [Homebrew](https://github.com/Homebrew/homebrew) package manager :
|
45
|
+
|
46
|
+
``` sh
|
47
|
+
brew install mosquitto
|
48
|
+
```
|
49
|
+
|
50
|
+
### Linux Ubuntu
|
51
|
+
|
52
|
+
``` sh
|
53
|
+
sudo apt-get update
|
54
|
+
sudo apt-get install pkg-config cmake openssl
|
55
|
+
```
|
56
|
+
|
57
|
+
The current Ubuntu packages aren't on 1.2.3 yet - it's recommended to build libmosquitto from source (see below) until further notice. OpenSSL is an optional dependency - libmosquitto builds without it, however TLS specific features would not be available.
|
58
|
+
|
59
|
+
### Building libmosquitto from source
|
60
|
+
|
61
|
+
``` sh
|
62
|
+
wget http://mosquitto.org/files/source/mosquitto-1.2.3.tar.gz
|
63
|
+
tar xzf mosquitto-1.2.3.tar.gz
|
64
|
+
cd mosquitto-1.2.3
|
65
|
+
cmake .
|
66
|
+
sudo make install
|
67
|
+
```
|
68
|
+
|
69
|
+
## Compatibility
|
70
|
+
|
71
|
+
This gem is regularly tested against the following Ruby versions on Linux and Mac OS X:
|
72
|
+
|
73
|
+
* Ruby MRI 1.9.3
|
74
|
+
* Ruby MRI 2.0.0 (ongoing patch releases).
|
75
|
+
* Ruby MRI 2.1.0 (ongoing patch releases).
|
76
|
+
* Ruby MRI 2.1.1 (ongoing patch releases).
|
77
|
+
|
78
|
+
Ruby 1.8, Rubinius and JRuby are not supported.
|
79
|
+
|
80
|
+
## Installing
|
81
|
+
|
82
|
+
### OSX / Linux
|
83
|
+
|
84
|
+
When are requirements or dependencies are met, the following should install mosquitto without any problems :
|
85
|
+
|
86
|
+
``` sh
|
87
|
+
gem install mosquitto
|
88
|
+
```
|
89
|
+
|
90
|
+
The extension checks for libmosquitto presence as well as a 1.2.3 version.
|
91
|
+
|
92
|
+
## Usage
|
93
|
+
|
94
|
+
### Threaded loop
|
95
|
+
|
96
|
+
The simplest mode of operation - starts a new thread to process network traffic.
|
97
|
+
|
98
|
+
``` ruby
|
99
|
+
require 'mosquitto'
|
100
|
+
|
101
|
+
publisher = Mosquitto::Client.new("blocking")
|
102
|
+
|
103
|
+
# Spawn a network thread with a main loop
|
104
|
+
publisher.loop_start
|
105
|
+
|
106
|
+
# On publish callback
|
107
|
+
publisher.on_publish do |mid|
|
108
|
+
p "Published #{mid}"
|
109
|
+
end
|
110
|
+
|
111
|
+
# On connect callback
|
112
|
+
publisher.on_connect do |rc|
|
113
|
+
p "Connected with return code #{rc}"
|
114
|
+
# publish a test message once connected
|
115
|
+
publisher.publish(nil, "topic", "test message", Mosquitto::AT_MOST_ONCE, true)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Connect to MQTT broker
|
119
|
+
publisher.connect("test.mosquitto.org", 1883, 10)
|
120
|
+
|
121
|
+
# Allow some time for processing
|
122
|
+
sleep 2
|
123
|
+
|
124
|
+
publisher.disconnect
|
125
|
+
|
126
|
+
# Optional, stop the threaded loop - the network thread would be reaped on Ruby exit as well
|
127
|
+
publisher.loop_stop(true)
|
128
|
+
```
|
129
|
+
|
130
|
+
### Blocking loop (simple clients)
|
131
|
+
|
132
|
+
The client supports a blocking main loop as well which is useful for building simple MQTT clients. Reconnects
|
133
|
+
etc. and other misc operations are handled for you.
|
134
|
+
|
135
|
+
``` ruby
|
136
|
+
require 'mosquitto'
|
137
|
+
|
138
|
+
publisher = Mosquitto::Client.new("blocking")
|
139
|
+
|
140
|
+
# On publish callback
|
141
|
+
publisher.on_publish do |mid|
|
142
|
+
p "Published #{mid}"
|
143
|
+
end
|
144
|
+
|
145
|
+
# On connect callback
|
146
|
+
publisher.on_connect do |rc|
|
147
|
+
p "Connected with return code #{rc}"
|
148
|
+
# publish a test message once connected
|
149
|
+
publisher.publish(nil, "topic", "test message", Mosquitto::AT_MOST_ONCE, true)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Connect to MQTT broker
|
153
|
+
publisher.connect("test.mosquitto.org", 1883, 10)
|
154
|
+
|
155
|
+
# Blocking main loop
|
156
|
+
publisher.loop_forever
|
157
|
+
```
|
158
|
+
|
159
|
+
### Custom main loop
|
160
|
+
|
161
|
+
EventMachine support is forthcoming.
|
162
|
+
|
163
|
+
### Logging
|
164
|
+
|
165
|
+
The client supports any of the Ruby Logger libraries with the standard #add method interface
|
166
|
+
|
167
|
+
``` ruby
|
168
|
+
require 'mosquitto'
|
169
|
+
|
170
|
+
publisher = Mosquitto::Client.new("blocking")
|
171
|
+
|
172
|
+
# Sets a custom log callback for us that pipes to the given logger instance
|
173
|
+
publisher.logger = Logger.new(STDOUT)
|
174
|
+
|
175
|
+
# Connect to MQTT broker
|
176
|
+
publisher.connect("test.mosquitto.org", 1883, 10)
|
177
|
+
```
|
178
|
+
|
179
|
+
### Callbacks
|
180
|
+
|
181
|
+
The following callbacks are supported (please follow links for further documentation) :
|
182
|
+
|
183
|
+
* [connect](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_connect) - called when the broker sends a CONNACK message in response to a connection.
|
184
|
+
* [disconnect](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_disconnect) - called when the broker has received the DISCONNECT command and has disconnected the client.
|
185
|
+
* [log](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_log) - should be used if you want event logging information from the client library.
|
186
|
+
* [subscribe](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_subscribe) - called when the broker responds to a subscription request.
|
187
|
+
* [unsubscribe](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_unsubscribe) - called when the broker responds to a unsubscription request.
|
188
|
+
* [publish](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_publish) - called when a message initiated with Mosquitto::Client#publish has been sent to the broker successfully.
|
189
|
+
* [message](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:on_message) - called when a message is received from the broker.
|
190
|
+
|
191
|
+
### TLS / SSL
|
192
|
+
|
193
|
+
libmosquitto builds with TLS support by default, however [pre-shared key (PSK)](http://rubydoc.info/github/bear-metal/mosquitto/master/Mosquitto/Client:tls_psk_set) support is not available when linked against older OpenSSL versions.
|
194
|
+
|
195
|
+
``` ruby
|
196
|
+
tls_client = Mosquitto::Client.new
|
197
|
+
|
198
|
+
tls_client.logger = Logger.new(STDOUT)
|
199
|
+
|
200
|
+
tls_client.loop_start
|
201
|
+
|
202
|
+
tls_client.on_connect do |rc|
|
203
|
+
p :tls_connection
|
204
|
+
end
|
205
|
+
tls_client.tls_opts_set(Mosquitto::SSL_VERIFY_PEER, "tlsv1.2", nil)
|
206
|
+
tls_client.tls_set('/path/to/mosquitto.org.crt'), nil, nil, nil, nil)
|
207
|
+
tls_client.connect('test.mosquitto.org', 8883, 10)
|
208
|
+
```
|
209
|
+
|
210
|
+
See [documentation](http://rubydoc.info/github/bear-metal/mosquitto) for the full API specification.
|
211
|
+
|
212
|
+
## Contact, feedback and bugs
|
213
|
+
|
214
|
+
This extension is currently maintained by Lourens Naudé (http://github.com/methodmissing) and contributors.
|
215
|
+
|
216
|
+
Please file bugs / issues and feature requests on the [issue tracker](https://github.com/bear-metal/mosquitto/issues)
|
217
|
+
|
218
|
+
## Development
|
219
|
+
|
220
|
+
To run the tests, you can use RVM and Bundler to create a pristine environment for mosquitto development/hacking.
|
221
|
+
Use 'bundle install' to install the necessary development and testing gems:
|
222
|
+
|
223
|
+
``` sh
|
224
|
+
bundle install
|
225
|
+
rake
|
226
|
+
```
|
227
|
+
Tests by default run against the public `test.mosquitto.org` MQTT server, which supports TLS as well. More information is available at http://test.mosquitto.org/. Alternatively, should you wish you run tests against a local MQTT broker, change the following constants in the test helper to `localhost`:
|
228
|
+
|
229
|
+
``` ruby
|
230
|
+
class MosquittoTestCase < Test::Unit::TestCase
|
231
|
+
TEST_HOST = "localhost"
|
232
|
+
TEST_PORT = 1883
|
233
|
+
|
234
|
+
TLS_TEST_HOST = "localhost"
|
235
|
+
TLS_TEST_PORT = 8883
|
236
|
+
```
|
237
|
+
|
238
|
+
## Resources
|
239
|
+
|
240
|
+
Documentation available at http://rubydoc.info/github/bear-metal/mosquitto
|
241
|
+
|
242
|
+
## Special Thanks
|
243
|
+
|
244
|
+
* Roger Light - for libmosquitto
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems' unless defined?(Gem)
|
4
|
+
require 'rake' unless defined?(Rake)
|
5
|
+
|
6
|
+
require 'rake/extensiontask'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'yard'
|
9
|
+
|
10
|
+
YARD::Rake::YardocTask.new do |t|
|
11
|
+
t.files = ['README.md', 'lib/**/*.rb', "ext/mosquitto/*.c"]
|
12
|
+
end
|
13
|
+
|
14
|
+
Rake::ExtensionTask.new('mosquitto') do |ext|
|
15
|
+
ext.name = 'mosquitto_ext'
|
16
|
+
ext.ext_dir = 'ext/mosquitto'
|
17
|
+
CLEAN.include 'lib/**/mosquitto_ext.*'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Run mosquitto tests'
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.test_files = Dir.glob("test/**/test_*.rb")
|
23
|
+
t.verbose = true
|
24
|
+
t.warning = true
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Run mosquitto integration tests'
|
28
|
+
Rake::TestTask.new(:integration) do |t|
|
29
|
+
t.test_files = Dir.glob("test/test_integration.rb")
|
30
|
+
t.verbose = true
|
31
|
+
t.warning = true
|
32
|
+
end
|
33
|
+
|
34
|
+
namespace :debug do
|
35
|
+
desc "Run the test suite under gdb"
|
36
|
+
task :gdb do
|
37
|
+
system "gdb --args ruby rake"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :compile
|
42
|
+
task :default => :test
|
data/TODO.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
* Let close_session be an argument to new client + reinit as well
|
2
|
+
* https://github.com/jobytaffey/mqtt-http-server
|
3
|
+
* Thread support
|
4
|
+
- release GIL when processing callbacks ?
|
5
|
+
- [X] rb_mosquitto_client_loop_write
|
6
|
+
- [X] rb_mosquitto_client_loop_read
|
7
|
+
- [X] rb_mosquitto_client_loop_stop
|
8
|
+
- [X] rb_mosquitto_client_loop_start
|
9
|
+
- [X] rb_mosquitto_client_loop
|
10
|
+
- [X] rb_mosquitto_client_loop_forever
|
11
|
+
- [X] rb_mosquitto_client_subscribe
|
12
|
+
- [X] rb_mosquitto_client_unsubscribe
|
13
|
+
- [X] rb_mosquitto_client_publish
|
14
|
+
- [X] rb_mosquitto_client_connect
|
15
|
+
- [X] rb_mosquitto_client_disconnect
|
16
|
+
- [X] rb_mosquitto_client_reconnect
|
17
|
+
- [X] rb_mosquitto_client_connect_async
|
18
|
+
- [X] rb_mosquitto_client_reinitialise
|
19
|
+
* TLS support
|
data/examples/pub_sub.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift('.')
|
4
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)) + '/../lib')
|
5
|
+
|
6
|
+
require 'mosquitto'
|
7
|
+
|
8
|
+
publisher = Mosquitto::Client.new
|
9
|
+
publisher.loop_start
|
10
|
+
publisher.on_log do |level,msg|
|
11
|
+
p "PUB: #{msg}"
|
12
|
+
end
|
13
|
+
publisher.on_connect do |rc|
|
14
|
+
p "Connect #{rc}"
|
15
|
+
publisher.publish(nil, "topic", "test", Mosquitto::AT_MOST_ONCE, true)
|
16
|
+
end
|
17
|
+
publisher.connect("localhost", 1883, 10)
|
18
|
+
publisher.on_publish do |mid|
|
19
|
+
p "Published #{mid}"
|
20
|
+
end
|
21
|
+
sleep 1.5
|
22
|
+
publisher.loop_stop(true)
|
23
|
+
|
24
|
+
subscriber = Mosquitto::Client.new
|
25
|
+
subscriber.loop_start
|
26
|
+
subscriber.on_log do |level,msg|
|
27
|
+
p "SUB: #{msg}"
|
28
|
+
end
|
29
|
+
subscriber.on_connect do |rc|
|
30
|
+
p "Connect #{rc}"
|
31
|
+
subscriber.subscribe(nil, "topic", Mosquitto::AT_MOST_ONCE)
|
32
|
+
end
|
33
|
+
subscriber.on_subscribe do |mid,qos_count,granted_qos|
|
34
|
+
p "Subscribed #{mid}"
|
35
|
+
end
|
36
|
+
subscriber.connect("localhost", 1883, 10)
|
37
|
+
subscriber.on_message do |msg|
|
38
|
+
p "Message #{msg}"
|
39
|
+
end
|
40
|
+
sleep 1.5
|
41
|
+
subscriber.loop_stop(true)
|