module Adafruit
Adafruit::IO::MQTT
provides a simple Adafruit
IO
aware wrapper around the Ruby MQTT library at github.com/njh/ruby-mqtt.
Our primary goal is to provide basic MQTT access to feeds.
For example, publishing to a feed is as simple as:
mqtt = Adafruit::IO::MQTT.new user, key mqtt.publish('feed-key', 1)
And subscribing to a feed is just as easy:
mqtt = Adafruit::IO::MQTT.new user, key mqtt.subscribe('feed-key') mqtt.get do |topic, value| puts "GOT VALUE FROM #{topic}: #{value}" end
If you need to access different MQTT endpoints or data formats (JSON, CSV) you can use the MQTT library directly:
mqtt = Adafruit::IO::MQTT.new user, key mqtt.client.get("#{user}/groups/group-key/json") do |topic, message| payload = JSON.parse(message) # etc... end
Documentation for Ruby MQTT is available at www.rubydoc.info/gems/mqtt/MQTT/Client