Ruby

Getting Started

1
gem install qubitro-mqtt
Copied!

Import Libraries

1
require 'qubitro-mqtt'
Copied!

Define Variables

1
deviceID = "PASTE_DEVICE_ID_HERE"
2
deviceToken = "PASTE_DEVICE_TOKEN_HERE"
3
host = "PASTE_DOMAIN_HERE"
Copied!

Setup MQTT Client

Minimum configuration required to connect to the broker.
1
MQTT::Client.connect(
2
:host => host,
3
:port => 8883,
4
:ssl => true,
5
:client_id => deviceID,
6
:device_id => deviceID,
7
:device_token => deviceToken,
8
:ack_timeout => 15,
9
:will_topic => deviceID,
10
:will_payload => payload,
11
)
Copied!

Advanced configuration

1
MQTT::Client.connect(
2
:host => host,
3
:port => port,
4
:ssl => true | false,
5
:client_id => deviceID,
6
:device_id => deviceID,
7
:device_token => deviceToken,
8
:keep_alive => 15,
9
:clean_session => true | false,
10
:ack_timeout => 15,
11
:will_topic => deviceID,
12
:will_payload => payload,
13
:will_qos => 0 | 1, #QoS 2 not supported
14
:will_retain => false,
15
)
Copied!

Prepare Data

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

Examples

Publish

Qubitro MQTT Publish Example Ruby

Subscribe

Qubitro MQTT Subscribe Example Ruby
Last modified 6mo ago