Links

Ruby

Quick guide for Ruby library.

Getting Started

Visit the MQTT overview page for conventions, authentication, and more information.
This library is open-source so you can check it out on GitHub.
Install the packages
gem install qubitro-mqtt

Import Libraries

Then import it and initialize it with the required packages. Of course, you’ll want to replace DEVICE_ID and DEVICE_TOKENwith your actual device credentials which you can find under your device settings on Qubitro Portal.
require 'qubitro-mqtt'

Define Variables

deviceID = "PASTE_DEVICE_ID_HERE"
deviceToken = "PASTE_DEVICE_TOKEN_HERE"
host = "PASTE_DOMAIN_HERE"

Setup MQTT Client

Minimum configuration required to connect to the broker.
MQTT::Client.connect(
:host => host,
:port => 8883,
:ssl => true,
:client_id => deviceID,
:device_id => deviceID,
:device_token => deviceToken,
:ack_timeout => 15,
:will_topic => deviceID,
:will_payload => payload,
)

Advanced configuration

MQTT::Client.connect(
:host => host,
:port => port,
:ssl => true | false,
:client_id => deviceID,
:device_id => deviceID,
:device_token => deviceToken,
:keep_alive => 15,
:clean_session => true | false,
:ack_timeout => 15,
:will_topic => deviceID,
:will_payload => payload,
:will_qos => 0 | 1, #QoS 2 not supported
:will_retain => false,
)

Prepare Data

payload = '{"Key1":1,"Key2":2}'

Examples

We strongly recommend using the 8883 port for MQTT over TLS connectivity.

Publish

Qubitro MQTT Publish Example Ruby

Subscribe

Qubitro MQTT Subscribe Example Ruby

​
✨
Support and Feedback

If you have further questions or suggestions, feel free to join
👇
-> Qubitro Community Discord via this invitation link.
Last modified 2mo ago