Connect to the TilliT Broker

Overview

MQTT works by using a subscribe/publish model. In this model, a broker acts as the one destination that all clients connect to. This article will describe how you will be able to connect to the TilliT Broker securely.

MQTT communicates on port 8883. Firewalls will generally block this port by default. Contact your IT services and confirm the port is open before attempting a connection.

MQTT Authentication

All TilliT MQTT connections are secured by a X.509 certificate authentication method. You can only recieve these certificates by first contacting TilliT Support. You will be issued a private key file, certificate file and root authority file that acts to authenticate and secure your connection. Place these files in a secure location that is accessible by your MQTT client software.

MQTT Broker Connection

Once you have the above authentication, use the broker endpoint iot.tillit.cloud to connect to the MQTT Broker on port 8883. Depending on your client. you may need to define the endpoint as ssl://iot.tillit.cloud:8883 (see Ignition). Once connected, you will be able to do the following two things to confirm.

1. Subscribe to the topic /tenant (replace tenant with yours)

2. Publish a message to the topic you subscribed to above. You should receive the message

Example (MQTT X)

You can get get up and running quickly with the MQTTx GUI client - https://mqttx.app/

Follow the following settings as an example. NOTE: ensure you have MQTT v3.1.1 selected and port 8883 is allowed through the firewall

Example (Javascript)

Copy the following contents into a file called mqtt.js and install the dependancies with npm install mqtt. Run with node mqtt.js.

Copy the following contents into a file called mqtt.js and install the dependancies with npm install mqtt. Run with node mqtt.js.
const mqtt = require('mqtt')
const fs = require('fs')

//Replace the following with the correct paths and names
const privateKeyPath =  './tillitEdgeConfig/privKey.key'
const thingCertPath = './tillitEdgeConfig/thingCert.crt'
const tenant = 'bottling'


let client = mqtt.connect({
  host: 'iot.tillit.cloud',
  port: 8883,
  key: fs.readFileSync(privateKeyPath),
  cert: fs.readFileSync(thingCertPath),
  protocol: 'mqtt'
})


client.on('connect', function () {
    console.log("Connected...")
    client.subscribe(`/${tenant}`, function (err) {
        if (!err) {
            console.log("Subscribed...")
            client.publish(`/${tenant}`, JSON.stringify({message: 'Hello!!!'}))
        }else{
            console.log(err)
        }
    })
})


client.on('error', function(err) {
    console.log(err)
})


client.on('message', function (topic, message) {
    console.log("Message Received!")
    console.log(JSON.parse(message))
})

You should see the following output.

Connected...
Subscribed...
Message Received!
{ message: 'Hello!!!' }

If you want to subscribe to anything in a level, then you can use the character + like so:

/tenant/+/assetName/endpoint - receive updates on an asset across any site
/tenant/siteName/+/endpoint - receive updates on a site across any asset
/tenant/+/+/endpoint - receive updates on any site and any asset for an ednpoint

Last updated