Ruby

Getting Started

Before getting started, make sure that Ruby and required libraries are installed by visiting the setup page

Import Libraries

require 'qubitro-mqtt'

Define Variables

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

Setup MQTT Client

Minimum configuration to connect to the broker.

Basic
TLS
Basic
MQTT::Client.connect(
:host => host,
:port => 1883,
:client_id => deviceID,
:device_id => deviceID,
:device_token => deviceToken,
:ack_timeout => 15,
:will_topic => deviceID,
:will_payload => payload,
)
TLS
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

Publish

Qubitro MQTT Publish Example Ruby

Subscribe

Qubitro MQTT Subscribe Example Ruby