MQTTLens is a chrome application which allows to communicate using MQTT and can be used to simulate a single system communicating with AirVantage.
MQTTLens must be installed on your computer.
Understand the basics of MQTT; you can check this page to have an introduction.
This first step consists in declaring a system in AirVantage, providing an identifier. We call it the Serial Number.
What is a system? A system is the AirVantage representation of any connected device, it includes:
- Gateway/module providing the connectivity
- SIM card providing access to the wireless network (optional)
- Some applications running on the connected device (embedded firmware & software)
An application must be associated within this system in order to define how it will communicate with AirVantage: protocol used, credentials, data sent and/or commands available.
The application we use in this tutorial defines MQTT communications sending : 3 data: temperature, luminosity and humidity. For your convenience, this application has been already published in AirVantage, so you just have to use it.
To know more about applications and how to release your own application, check this tutorial .
Gateway
section Applications
sectionGeneric Greenhouse
in the filter NameContinue
. Remember it, you will use it in the next step
Form the previous step, you told to AirVantage what was you system and how it will communicate, let’s configure MQTTLens to connect and send data.
MQTTLens can send MQTT messages to AirVantage exactly like a system can do it.
eu.airvantage.net
(default port is correct)Username
with the Serial Number and the Password
with the password your supplied in the previous step.Save Changes
Your connection status must be green:
Let’s subscribe to a topic in order to receive any command from AirVantage.
The first line in MQTT Lens allows you to susbcribe to a topic. For command, you need to subscribe to {Serial Number}/tasks/json
So fill accordingly the field Susbcribe
and click on Subscribe
button on the right:
A new line is added in the bottom of the MQTTLens screen:
You can subscribe to the errors topic:
{Serial Number}/errors
to be notified when a payload will occur later in this tutorial.
Now, MQTT Lens is connected to AirVantage. Let’s start by sending data and then receive a command.
Sending data to AirVantage consists in sending to a topic called {Serial Number}/messages/json
this json content:
{ "1349907137000": { "machine.temperature": 23.2, "machine.humidity": 70 },
"1349908137000": { "machine.temperature": 24.5 },
"1349909137000": { "machine.temperature": 22.9 },
"1349910137000": { "machine.threshold": 30}
}
Like in this screenshot:
You can check the data have been sent looking at the system in AirVantage:
To know more about the AirVantage json format, have a look to this page
AirVantage provides a topic you can subscribe to receive notifications when AirVantage could not understand the payload sent. As an example showing what happens when you send a bad paylod, you can try to publish the following payload with a missing } char at the beginning of the message :
"1349907137000": { "machine.temperature": 23.2, "machine.humidity": 70 },
"1349908137000": { "machine.temperature": 24.5 },
"1349909137000": { "machine.temperature": 22.9 },
"1349910137000": { "machine.threshold": 30}
}
You will receive this notification:
On AirVantage, in the system details, click on the menu More on the top.
You can check the status of this operation in AirVantage.
Send back the operation uid provided in the command to acknowledge it and update the status Failed or Success in AirVantage. In the publish section:
{Serial Number}/acks/json
Note you have to use the
uid
from the task’s message (see above for an example), not from the command’s operation in the ui.
For success acknowledgement (change the uid accordingly), status must be OK:
[
{"uid": "8006cc58ba2141f69161a78f1bfdea1d", "status" : "OK"}
]
or for failed acknowledgement (change the uid accordingly), change the status by whatever except OK (ERROR, KO):
[
{"uid": "3c12547b613740adb686271bdc8f097c", "status" : "KO", "message" : "Crashed in flames! Error code: 12345"}
]
Now, you know how to simulate a single system in order to understand how your system can communicate to AirVantage or to generate specific business contente in order to test accurately your APIs without any real system.
I you wish to simulate a fleet of systems, you may have a look to this tutorial .
To know more about MQTT, you can access to all the ressources from this page . In this page, you can access to the time series format which allows to your device to send a compressed data history to AirVantage.
To know more about errors topic, have a look to this page .
To know more about mqtt with AirVantage, have a look to this page
Have a look to our tutorials explaining how to develop embedded applications!