MQTTLens is a chrome application which supports MQTT communications. You can use it to simulate a single system communicating with AirVantage via MQTT.
MQTTLens must be installed on your computer.
Understand the basics of MQTT. Refer to page for an introduction.
The first step is to declare a system in AirVantage, providing an identifier. We call this the Serial Number.
What is a system? A system is the AirVantage representation of any connected device, it includes:
- Gateway/modules providing the connectivity
- SIM cards 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 types: temperature, luminosity and humidity. For your convenience, this application has already been published in AirVantage, so that you can use it.
To know more about applications and how to release your own application, refer to tutorial .
Gateway
section Applications
sectionGeneric Greenhouse
in the filter NameContinue
. Note it safely, as you will use it in the next step
In the previous step, you specified a system and how it will communicate with AirVantage. Now let’s configure MQTTLens to connect and send data.
MQTTLens can send MQTT messages to AirVantage exactly like a real system.
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 notification of commands 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
Thus fill in the Subscribe field accordingly and click on the Subscribe button on the right:
A new line is added at 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.
MQTT Lens is now 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
the following json content:
{ "1349907137000": { "machine.temperature": 23.2, "machine.humidity": 70 },
"1349908137000": { "machine.temperature": 24.5 },
"1349909137000": { "machine.temperature": 22.9 },
"1349910137000": { "machine.threshold": 30}
}
As in this screenshot:
You can check the data has been sent by looking at the system in AirVantage:
To learn more about the AirVantage json format, refer to page
To receive notifications when AirVantage cannot understand the payload sent, AirVantage provides a topic you can subscribe to. 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.
To receive success acknowledgements (change the uid accordingly), status must be OK:
[
{"uid": "8006cc58ba2141f69161a78f1bfdea1d", "status" : "OK"}
]
or for failed acknowledgement (change the uid accordingly), set status to any other value except OK (ERROR, KO):
[
{"uid": "3c12547b613740adb686271bdc8f097c", "status" : "ERROR", "message" : "Crashed in flames! Error code: 12345"}
]
You now 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.
If you wish to simulate a fleet of systems, refer to tutorial .
To learn more about MQTT, use the resources from this page . On this page, you can access the time series format, which allows your device to send a compressed data history to AirVantage.
To know more about errors topic, refer to page .
To learn more about communicating with AirVantage via MQTT, refer to page
And please also take a look at our tutorials , which explain how to develop embedded applications!