This article is about using AirVantage API for AirLink devices. It will focus on a device: the famous GX440.
Prerequisite
- The Developer Studio for ALEOS must be installed and configured.
- Have a basic knownlege of MQTT. See the other tutorial about MQTT for airvantage: MQTT API .
An application model aims to explain to AirVantage how to deal with the device about communication and authentication and managing the data: variable, settings or commands. If you don’t supply such information, the server will ignore all the communication from your device. In this step, we are going to see how to create this application and release it on AirVantage and associate it to your system.
<data>
area. Once it matches your needs, save everything as model.app.Don’t modify the asset id as it is used in the code source application or modify it accordingly.
<?xml version="1.0" encoding="ISO-8859-1"?>
<app:application
xmlns:app="http://www.sierrawireless.com/airvantage/application/1.0"
type="com.test.airvantage.sl.app"
name="AirVantage Greenhouse"
revision="0.0.1">
<capabilities>
<communication>
<protocol comm-id="IMEI" type="MQTT" />
</communication>
<data>
<encoding type="MQTT">
<asset default-label="Greenhouse" id="machine">
<variable default-label="Temperature" path="temperature"
type="double"/>
<variable default-label="Luminosity" path="luminosity"
type="double"/>
<setting default-label="Threshold" path="threshold"
type="int"/>
</asset>
</encoding>
</data>
</capabilities>
</app:application>
test12!
).
It is now time to write an application for our GX440. You can have a look about using MQTT in AirVantage , if you want to have a description about the serialisation details.
main.lua
and update the MQTT path, the broker at the beginning of the file.-- ----------------------------------------------------------------------------
-- CONSTANTS
-- ----------------------------------------------------------------------------
local ASSET_NAME = "machine"
local MQTT_DATA_PATH = "CA1162104660K/messages/json"
local MQTT_COMMAND_PATH = "CA1162104660K/tasks/json"
local MQTT_BROKER = "eu.m2mop.net"
local MQTT_PORT = 1883
local MODBUS_PORT = "/dev/ttyS0"
local MODBUS_CONF = {baudRate = 9600 }
local LOG_NAME = "MODBUS_APP"
-- ----------------------------------------------------------------------------
-- MAIN
-- ----------------------------------------------------------------------------
local function main()
log.setlevel("INFO")
log(LOG_NAME, "INFO", "Application started")
modbus_client = modbus.new(MODBUS_PORT, MODBUS_CONF)
log(LOG_NAME, "INFO", "Modbus - OK")
mqtt_client = mqtt.client.create(MQTT_BROKER, MQTT_PORT, process_mqtt)
log(LOG_NAME, "INFO", "MQTT Client - OK")
mqtt_client:connect(LOG_NAME, nil, nil, nil, nil, "CA1162104660K", "test12!")
mqtt_client:subscribe({MQTT_COMMAND_PATH.."#"})
By default these credentials are uasuser : sierra12345.
Look, it is alive:
MODBUS_APP-INFO: Application started
MODBUS_APP-INFO: Modbus - OK
MODBUS_APP-INFO: MQTT Client - OK
MODBUS_APP-INFO: Init done
MODBUS_APP-INFO: Read data humidity : 0
MODBUS_APP-INFO: Read data temperature : 33
MODBUS_APP-INFO: Read data luminosity : 16
MODBUS_APP-INFO: Read data light : 0
MODBUS_APP-INFO: Sending data {"machine.humidity":0, "machine.temperature":27.0276, "machine.luminosity":12.149870801034, "machine.light":0}
Your data is now sent. You can check your data communication. Just go to Monitor > Systems, then pick your own and click Timeline. That is it.
Find the full sample in github and clone it!
Next Step
Continue the tutorial by using tools supplied by AirVantage to test your communication with your device.