Permalink
Browse files

Add support for retained messages and add a nicer service label

  • Loading branch information...
1 parent 11563a0 commit 70755f2e5ac4bdf14293409ea7e4a681877507a4 @andypiper andypiper committed Jun 18, 2012
Showing with 8 additions and 4 deletions.
  1. +4 −3 docs/mqttpub
  2. +4 −1 services/mqtt.rb
View
@@ -12,7 +12,8 @@ Install Notes
4. OPTIONAL. 'clientid' is the unique client ID which publishes the payload message (default is a prefixed epoc time long, e.g. "github_1336363787").
5. OPTIONAL. 'user' is the v3.1 username (default is none).
6. OPTIONAL. 'pass' is the v3.1 password (default is none).
-7. The payload of the message is JSON received from Github (refer to docs/github_payload).
-8. ruby-mqtt only supports QoS 0.
-9. For testing, you can use mqtt.io as your web MQTT client. broker: q.m2m.io, port: 1883, clientid: {github_username}. You will "Subscribe to Topics": 'github/{github_username}/{repo_name}'. Unauthenticated username/password sets default to the public channel!
+7. OPTIONAL. 'retain' specifies whether or not the publication should be retained as the last/most recent message for new subscribers.
+8. The payload of the message is JSON received from Github (refer to docs/github_payload).
+9. ruby-mqtt only supports QoS 0.
+10. For testing, you can use mqtt.io as your web MQTT client. broker: q.m2m.io, port: 1883, clientid: {github_username}. You will "Subscribe to Topics": 'github/{github_username}/{repo_name}'. Unauthenticated username/password sets default to the public channel!
View
@@ -1,6 +1,9 @@
class Service::MqttPub < Service
+ self.title = 'MQTT publish'
+
string :broker, :port, :topic, :clientid, :user
password :pass
+ boolean :retain
require 'mqtt'
@@ -59,7 +62,7 @@ def receive_push
:username => user,
:password => pass
) do |client|
- client.publish(data['topic'].to_s, payload.to_json)
+ client.publish(data['topic'].to_s, payload.to_json, retain=data['retain'])
# Disconnect (don't send last will and testament)
client.disconnect(false)
end

0 comments on commit 70755f2

Please sign in to comment.