Class: AwsIotDevice::MqttAdapter::PahoMqttAdapter
- Inherits:
-
Object
- Object
- AwsIotDevice::MqttAdapter::PahoMqttAdapter
- Defined in:
- lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb
Instance Method Summary collapse
- #add_callback_filter_topic(topic, callback = nil, &block) ⇒ Object
- #client_id ⇒ Object
- #connect(*args, &block) ⇒ Object
- #connected? ⇒ Boolean
- #disconnect(send_msg) ⇒ Object
- #generate_client_id ⇒ Object
- #get(topic = nil, &block) ⇒ Object
- #get_packet(topic = nil, &block) ⇒ Object
- #host ⇒ Object
- #host=(host) ⇒ Object
-
#initialize(*args) ⇒ PahoMqttAdapter
constructor
A new instance of PahoMqttAdapter.
- #loop_forever ⇒ Object
- #loop_misc ⇒ Object
- #loop_read ⇒ Object
- #loop_start ⇒ Object
- #loop_stop(thread) ⇒ Object
- #loop_write ⇒ Object
- #mqtt_loop ⇒ Object
- #on_connack(&block) ⇒ Object
- #on_connack=(callback) ⇒ Object
- #on_message(&block) ⇒ Object
- #on_message=(callback) ⇒ Object
- #on_puback(&block) ⇒ Object
- #on_puback=(callback) ⇒ Object
- #on_pubcomp(&block) ⇒ Object
- #on_pubcomp=(callback) ⇒ Object
- #on_pubrec(&block) ⇒ Object
- #on_pubrec=(callback) ⇒ Object
- #on_pubrel(&block) ⇒ Object
- #on_pubrel=(callback) ⇒ Object
- #on_suback(&block) ⇒ Object
- #on_suback=(callback) ⇒ Object
- #on_unsuback(&block) ⇒ Object
- #on_unsuback=(callback) ⇒ Object
- #port ⇒ Object
- #port=(port) ⇒ Object
- #publish(topic, payload = "", retain = false, qos = 0) ⇒ Object
- #remove_callback_filter_topic(topic) ⇒ Object
- #set_tls_ssl_context(ca_cert = nil, cert = nil, key = nil) ⇒ Object
- #ssl ⇒ Object
- #ssl=(ssl) ⇒ Object
- #subscribe(topic, qos) ⇒ Object
- #subscribe_bunch(topics) ⇒ Object
- #unsubscribe(topic) ⇒ Object
- #unsubscribe_bunch(topics) ⇒ Object
Constructor Details
#initialize(*args) ⇒ PahoMqttAdapter
Returns a new instance of PahoMqttAdapter.
7 8 9 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 7 def initialize(*args) @client = PahoMqtt::Client.new(*args) end |
Instance Method Details
#add_callback_filter_topic(topic, callback = nil, &block) ⇒ Object
110 111 112 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 110 def add_callback_filter_topic(topic, callback=nil, &block) @client.add_topic_callback(topic, callback, &block) end |
#client_id ⇒ Object
11 12 13 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 11 def client_id @client.client_id end |
#connect(*args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 15 def connect(*args, &block) if args.last.is_a?(Hash) attr = args.last attr.each_pair do |k, v| if [:host, :port, :keep_alive, :persistent].include?(k) @client.send("#{k}=", v) else raise ArgumentError, "Parameter error, invalid paramater \"#{k}\" for connect with paho-mqtt" end end end @client.connect if block_given? begin yield(self) ensure @mqtt_client.disconnect end end end |
#connected? ⇒ Boolean
86 87 88 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 86 def connected? @client.connected? end |
#disconnect(send_msg) ⇒ Object
82 83 84 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 82 def disconnect(send_msg) @client.disconnect(send_msg) end |
#generate_client_id ⇒ Object
78 79 80 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 78 def generate_client_id @client.generate_client_id end |
#get(topic = nil, &block) ⇒ Object
70 71 72 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 70 def get(topic=nil, &block) @client.loop_read(1) end |
#get_packet(topic = nil, &block) ⇒ Object
74 75 76 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 74 def get_packet(topic=nil, &block) @client.loop_read(1) end |
#host ⇒ Object
182 183 184 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 182 def host @client.host end |
#host=(host) ⇒ Object
186 187 188 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 186 def host=(host) @client.host = host end |
#loop_forever ⇒ Object
48 49 50 51 52 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 48 def loop_forever loop do @client.mqtt_loop end end |
#loop_misc ⇒ Object
66 67 68 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 66 def loop_misc @client.loop_misc end |
#loop_read ⇒ Object
58 59 60 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 58 def loop_read @client.loop_read end |
#loop_start ⇒ Object
40 41 42 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 40 def loop_start Thread.new { loop_forever } end |
#loop_stop(thread) ⇒ Object
44 45 46 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 44 def loop_stop(thread) thread.join end |
#loop_write ⇒ Object
62 63 64 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 62 def loop_write @client.loop_write end |
#mqtt_loop ⇒ Object
54 55 56 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 54 def mqtt_loop @client.mqtt_loop end |
#on_connack(&block) ⇒ Object
150 151 152 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 150 def on_connack(&block) @client.on_connack(&block) end |
#on_connack=(callback) ⇒ Object
118 119 120 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 118 def on_connack=(callback) @client.on_connack = callback end |
#on_message(&block) ⇒ Object
178 179 180 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 178 def (&block) @client.(&block) end |
#on_message=(callback) ⇒ Object
146 147 148 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 146 def (callback) @client. = callback end |
#on_puback(&block) ⇒ Object
162 163 164 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 162 def on_puback(&block) @client.on_puback(&block) end |
#on_puback=(callback) ⇒ Object
130 131 132 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 130 def on_puback=(callback) @client.on_puback = callback end |
#on_pubcomp(&block) ⇒ Object
174 175 176 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 174 def on_pubcomp(&block) @client.on_pubcomp(&block) end |
#on_pubcomp=(callback) ⇒ Object
142 143 144 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 142 def on_pubcomp=(callback) @client.on_pubcomp = callback end |
#on_pubrec(&block) ⇒ Object
166 167 168 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 166 def on_pubrec(&block) @client.on_pubrec(&block) end |
#on_pubrec=(callback) ⇒ Object
134 135 136 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 134 def on_pubrec=(callback) @client.on_pubrec = callback end |
#on_pubrel(&block) ⇒ Object
170 171 172 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 170 def on_pubrel(&block) @client.on_pubrel(&block) end |
#on_pubrel=(callback) ⇒ Object
138 139 140 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 138 def on_pubrel=(callback) @client.on_pubrel = callback end |
#on_suback(&block) ⇒ Object
154 155 156 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 154 def on_suback(&block) @client.on_suback(&block) end |
#on_suback=(callback) ⇒ Object
122 123 124 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 122 def on_suback=(callback) @client.on_suback = callback end |
#on_unsuback(&block) ⇒ Object
158 159 160 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 158 def on_unsuback(&block) @client.on_unsuback(&block) end |
#on_unsuback=(callback) ⇒ Object
126 127 128 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 126 def on_unsuback=(callback) @client.on_unsuback = callback end |
#port ⇒ Object
190 191 192 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 190 def port @client.port end |
#port=(port) ⇒ Object
194 195 196 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 194 def port=(port) @client.port = port end |
#publish(topic, payload = "", retain = false, qos = 0) ⇒ Object
36 37 38 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 36 def publish(topic, payload="", retain=false, qos=0) @client.publish(topic, payload, retain, qos) end |
#remove_callback_filter_topic(topic) ⇒ Object
114 115 116 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 114 def remove_callback_filter_topic(topic) @client.remove_topic_callback(topic) end |
#set_tls_ssl_context(ca_cert = nil, cert = nil, key = nil) ⇒ Object
106 107 108 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 106 def set_tls_ssl_context(ca_cert=nil, cert=nil, key=nil) @client.config_ssl_context(cert, key, ca_cert) end |
#ssl ⇒ Object
198 199 200 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 198 def ssl @client.ssl end |
#ssl=(ssl) ⇒ Object
202 203 204 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 202 def ssl=(ssl) @client.ssl = ssl end |
#subscribe(topic, qos) ⇒ Object
90 91 92 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 90 def subscribe(topic, qos) @client.subscribe([topic, qos]) end |
#subscribe_bunch(topics) ⇒ Object
94 95 96 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 94 def subscribe_bunch(topics) @client.subscribe(topics) end |
#unsubscribe(topic) ⇒ Object
98 99 100 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 98 def unsubscribe(topic) @client.unsubscribe(topic) end |
#unsubscribe_bunch(topics) ⇒ Object
102 103 104 |
# File 'lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb', line 102 def unsubscribe_bunch(topics) @client.unsubscribe(topics) end |