MQTT Broker

How to I connect a "thing" to the Assetwolf IoT portal using MQTT?

Here's our quick guide for customers with an Assetwolf portal who want to make an MQTT connection.

Here's a simple architecture diagram of how Assetwolf uses an MQTT broker:

MQTT diagram 1

Your asset is over on the left hand side of the above diagram, here are the steps to connect.

1. Connect to the broker

Depending on your setup, we will give you either secure SSL or insecure credentials. It's easy to use a non-SSL connection, which is the standard set-up for demo sites. You will need these parameters:

  • your clientID
  • port number
  • your portal's MQTT password

The port number will be 1883 for non-SSL connection, or 8883 is SSL.

To find these in your portal, log in as a Superuser and go to Set-up -> Global Asset Connection Details.

This is how this looks if you use the MQTTlens Chrome App:

MQTT broker connection using MQTTlens


2. Publish some data

Your device should publish its data to:

$sensorTopic = "up/client/clientId/asset/assetId";

The topic is structured in this way:

  • "up" (i.e. device to cloud)
  • clientID (i.e. your client identifier)
  • assetId (i.e. the asset's ID).

The JSON payload should look like this (but you can remove newlines and spaces):

    "deviceId": "123456768abcd",
    "data": {
        "sensor.pressure": 1.0124,
        "sensor.temperature": 21.5

In this JSON object, there is:

  • the device ID (which must be the same as the deviceId in the MQTT topic)
  • a further "data" JSON object containing the sensor values, or whatever data is coming from the asset.

An alternative format is like this:

    "deviceId": "123456768abcd",
    "pressure": 1.0124,
    "temperature": 21.5

Be sure to use double-quotes around all alphanumeric fields, but not single quotes. (Numeric fields don't need to be quoted).

The above example is simple, but in practice there may be a large number of key-value pairs in the data.

If you wish to send data for sensor readings that were taken in the past, you can include a field called "timestamp". Make your field value a Unix microtime (milliseconds since 1970). This is optional, and you only need to send this if you are reporting earlier sensor data.

It is not essential to send a full set of data every time. For example, your application may prefer to send send "temperature" every 15 minutes, but only send "pressure" once an hour. If so, simply omit "pressure" from the JSON data object when not needed. When processing rules, if a rule depends on "pressure" then Assetwolf will use the most recent previous datapoint for which "pressure" was specified; however, when displaying graphs Assetwolf will only display points when they were specified in the data payload.

3. Check your data is arriving

Go to the Superuser Dashboard on your portal, and look at your assets. If all is well, you should see some data has arrived.

Google ChromeScreenSnapz780.jpg