For the ones who want to build Internet enabled devices the MQTT connectivity protocol is a must to know and master. The protocol has been around for quite some time when Internet of Things was young and called Machine to Machine :) It was developed by IBM and sits on top of TCP/IP.
The main advantages over the traditional HTTP requests based style communication is the low footprint, quality of service settings and good performance even on unreliable connections. You can learn more about it here http://mqtt.org .
For using MQTT communication you need at least two entities a server based broker that listens to a series of topics and a device that sends the messages. For testing purposes of course you can run both of them locally if you want but that won't help you to store data in the cloud or control things remotely.
In this tutorial you will learn to use it with the Broker running on DeviceHub.net you you sending data or receiving from your laptop for testing purposes first than your other devices or prototypes.
The first step is to register on the platform and create a Device as an entry point for your data on the cloud. You can do that here https://dashboard.devicehub.net/register and follow the wizard there to create your device.
Every Device has a unique id (UUID) and an associated API key of the project it resides to make sending data secure and reliable.
So MQTT functions like this: the broker "listens" and sends messages on a number of topics. These topics are automatically created by DeviceHub.net to be unique and serve for you either to send data towards the platform or the receive it back into your device.
For example I have created a Device in a project and added an Analog sensor (there are other data types too digital, string, map for inputs and digital, analog for outputs). In the Device page I can find the information I need to send to the right topic.
The topic structure is :
Replace the f087b5ef-d918-436b-ace8-eaeebeb76ded api key with the one from your project, 4612 with your Project Id, 8a4aa981-ad13-4749-b829-4f22a745e482 with your Device Id and AnalogSensor with the exact name of your sensor.
Then I placed this in the Topic field in MQTT.fx like in the screenshot bellow. Be sure to check "Retained" this means that once on the server the message is kept. Notice the Quality of Service drop-down also from the laptop either one will do, the message will reach DeviceHub.net safely.
You can also subscribe to the same topic in the Subscribe Tab to see if the messages reach the Broker. Also keep in mind that you can set the MQTT protocol on two separate devices and Publish from one and Subscribe with another to easily send data between them. You can also alternate to reverse the data flow.
If you were lazy and did not change the requests from this tutorial you can check the result on this link https://dashboard.devicehub.net/project/4612/device/8a4aa981-ad13-4749-b829-4f22a745e482/public/81a9e883-44d6-4386-9e53-8dc7774e40c8 this being the shared project in a sandbox account :)
Be advised: it is not a good practice to post API keys on the internet. We only did this to explain this concept and yes you can send values in the sensors from this demo account because it is not connected to an actual device.
If you have any questions let me know,