About Airvantage
Airvantage is a cloud-based solution offered by Sierra Wireless to facilitate the M2M service delivery, making use of its M2M management application and its Airvantage Enterprise Platform for collecting, sharing, and the integration of machine data using API standards. Airvantage M2M management application allows the manipulation of the data in a service that provides all the data shared, illustrated in charts and lists.
Scriptr.io-Airvantage Connector
We thought that beside collecting and sharing Airvantage data, Airvantage users would be interested in analyzing and interpreting the data read and set to the their cloud. Scriptr.io can allow the execution of backend logic and data processing in a javascript code on the Airvantage data. To make it easier, we have worked on wrapping Airvantage APIs into a connector that can be easily deployed into your scriptr.io account from your workspace. This can simply done by clicking on “New Script”>”Import Module” then selecting “airvantage”.
Simulating the APIs
Airvantage has created a demo mobile application (AV Phone) to simulate any machine sending data to Airvantage. We have implemented a simple application to demonstrate the feasibility of calling the airvantage API set, reading and illustrating these sample data on Google charts embedded in scriptr.io workbench. So far, we have implemented the first version of the connector. At a later phase, we will be wrapping more of the Airvantage APIs into a more sophisticated connecter objects to leverage the use of the scriptr.io-Airvantage interactions.
Pre-requisites
In order to implement the following sample application, you need to:
- Sign up for an account at Airvantage
- Create a scriptr.io account
- Install the AV Phone app from Google Play or the Apple Store. Login to it using your Airvantage account and run the application.
- Install the Airvantage module in your scriptr.io account (from your workspace, click on “New Script” > “Import” and scroll down to airvantage)
- Update “/airvantage/config” file in your scriptr.io workspace with your credentials. For the “Resource Owner Flow” authentication, set your username and password variables in the configuration file. For the “Authorization Code Flow” set the client_id and the client_secret.
Our target is to read and present the black and colored ink level of the latest 10 messages sent from the gateway (AV Phone App) to the Airvantage.
Initializing the Connector
The simplest way to use the connector is to require the system.js library as well as the TokenManager.js library in charge of obtaining the auth2.0 access token.
var system = require("../system.js"); var tokenManager = require("../authorization/TokenManager.js");
Authentication
To authorize all the API requests to Airvantage through OAuth 2.0, the TokenManager.js library provides 2 ways of getting an access token and a refresh token (Request an Access Token using the Resource Owner Flow) & (Request an Access Token using the Authorization Code Flow). The tokens are set in global variables. If the refresh token expires, the library will automatically handle retrieving a new valid one.
To request an access token using resource owner flow:
var accessTokenSetResult = tokenManager.getAccessTokenFromCredentials();
Retrieving AV Phone app data (System Messages)
//This method returns a paginated list of systems with their complete details. var systemResults = system.findSystems(); //Choose the uid of the first system available var systemUID = systemResults.items[0].uid; //Retrieve all the messages of the current system described by its systemUID var systemMessages = system.getSystemMessages(systemUID); var count = 0;
Retrieving Message Details and Formatting Data
The data retrieved from the AV Phone App should be formatted in a JSON object as expected by the Google line-chart.
//loop on all the latest 10 messages for(var x=systemMessages.messages.length-11; x<systemMessages.messages.length-1; x++){ var systemMessageUID = systemMessages.messages[x].uid; //retrieve the details of each message var messageDetails = system.getSystemMessageDetails(systemUID, systemMessageUID); if(messageDetails["data"] && messageDetails["data"]["phone.custom.3"] && messageDetails["data"]["phone.custom.4"]){ count ++; //read the colored and black ink levels from the messages sent var blackInkPrinted = parseInt(messageDetails["data"]["phone.custom.3"][0]["value"]); var colorInkPrinted = parseInt(messageDetails["data"]["phone.custom.4"][0]["value"]); result.push([count, blackInkPrinted, colorInkPrinted]); } } //return the results as expected by the Google chart set in the testCharts.js return result;
Display the returned values in a Google line chart
As mentioned, we’ll use scriptr.io’s very efficient Google chart scripts to display the transformed data. Save the above code into a script – let’s call it “test” – and create a new Google chart script by clicking on “+New Script” > “Google Chart”. Select the “test” script as a data source script.

Black and Colored ink usage as sent from the AV Phone App
Get the code
You can get the source code of this sample application from Github.