Matching results

Simulate a system with MQTTLens

Introduction

MQTTLens is a chrome application which allows to communicate using MQTT and can be used to simulate a single system communicating with AirVantage.

Prerequisites

  • MQTTLens must be installed on your computer.

  • Understand the basics of MQTT; you can check this page to have an introduction.

Step 1: Register your device

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 .

Add required information to your system

  • Go to Monitor > Systems and select your system by checking the check box on the left
  • Edit your system by clicking on Edit in the table’s menu More
  • Add a gateway by clicking on the + button in the Gateway section
  • Fill the Serial Number. Remember it, you will use it in the next step
  • Click on Create
  • Associate your application, by clicking on the glass icon in the Applications section
  • Search Generic Greenhouse in the filter Name
  • Click on the application
  • Set a password by clicking on the padlock on the right, fill it and click on Continue. Remember it, you will use it in the next step
  • Save your modifications

Step 2: Configure MQTT Lens

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.

AirVantage address configuration

  • Click on the + to create a new connection
  • Give it a name AirVantage
  • Fill the hostname: eu.airvantage.net (default port is correct)
  • Supply your credentials: fill Username with the Serial Number and the Password with the password your supplied in the previous step.
  • Click on Save Changes

Your connection status must be green:

Subscription to topics

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.

Step 3: Send data and receive commands

Now, MQTT Lens is connected to AirVantage. Let’s start by sending data and then receive a command.

Send data to AirVantage

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:

  • Go to Monitor > Systems and select your system by checking the check box on the left
  • Click on the Timeline button you shall see the timeline of the device communications: MQTT connections and data sent.
  • or Click on the Green house application in your system you can access to the history of values sent for each data defined for this application.

To know more about the AirVantage json format, have a look to this page

Troubleshoot payload errors

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:

Receive and acknowledge commands

On AirVantage, in the system details, click on the menu More on the top.

  • Select your application (Generic Greenhouse)
  • Select your command and parameter
  • Click on Send Command button

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:

  • Fill the topic name with {Serial Number}/acks/json
  • The payload with one of the following content:

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.

Next Steps

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!

TOP