How to send a stream using MQTT

This tutorial will show how to send data streams to Altair SmartWorks with MQTT.

First, we need to know what we want to send and how to send it. Data is sent to Altair SmartWorks REST API. You need:

  • A device in Altair SmartWorks
  • A valid Apikey
  • Your data
  • A MQTT client

If you're registered in Altair SmartWorks, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.

Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like 98346673a6377ef1fde2357eeaae0da582b150b00cabcd5a0d83045425407ab4.
Now we define our data. It will be a simple data set with temperature and humidity:

Finally we need a MQTT client. In this case we are going to use the Paho Python Client (http://www.eclipse.org/paho/clients/python/).

Once you have installed the library on your system you can use this example:

Remember that, unlike the HTTP api, MQTT will not send back a response, you can go to the control panel and see the stream sent. You will find more examples and implementations of the Paho client here.

Alternative implementation in C language using paho-mqtt lib.

For installing paho-mqtt libs for C you can get information in HERE