element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
In the Air Design Challenge
  • Challenges & Projects
  • Design Challenges
  • In the Air Design Challenge
  • More
  • Cancel
In the Air Design Challenge
Blog In the Air Design Challenge - Pollen & Allergen Sensing – Post 3 (AirVantage Intro)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tomaja
  • Date Created: 22 Nov 2014 4:50 PM Date Created
  • Views 624 views
  • Likes 1 like
  • Comments 5 comments
  • iot_pollen
  • in_the_air
Related
Recommended

In the Air Design Challenge - Pollen & Allergen Sensing – Post 3 (AirVantage Intro)

tomaja
tomaja
22 Nov 2014

Previous posts:

In the Air Design Challenge - Pollen & Allergen Sensing

In the Air Design Challenge - Pollen & Allergen Sensing – Post 1 (Pollen Sensor)

In the Air Design Challenge - Pollen & Allergen Sensing – Post 2

 

Since I spent a lot of time on trying to get notifications from AirVantage when new values are published from BBB (in my case just a Paho MQTT client) I decided to dedicate a short post to AirVantage topic. image

 

Wrong approach

At first, I was trying to subscribe to a topic on AirVantage MQTT and receive messages whenever BBB publishes new sensor values. I tried with a couple of different test clients and a couple of topics but no success. I tried using MQTT wildcards (# and +) but still - nothing arrived from AirVantage.

I read some AirVantage docs and find out that I could use REST API to read published data but I was under impression that I should only use MQTT (for some strange reason image)

After a few hours of failed attempts I posted a question (Subscription to AirVantage MQTT topic) and soon I got a couple of replies. Some of them were from dlahay who was kind enough to answer all my questions and soon I got my app working…

 

Correct approach

The correct way to use AirVantage is the following:

  • Use MQTT to publish new data messages like sensor readings (to topic<SERIAL>/messages/json) and subscribe to a topic (<SERIAL>/tasks/json) to receive commands and settings updates. Code sample written in C for publishing data is provided in my previous post. Check API documentation to see how commands can be sent to subscribed clients.
  • On the remote clients (like mobile phones and computers) use REST API to get published data. For example, you can get historical data for the last 3 months.

 

REST API is well documented and can be found here: https://na.airvantage.net/develop/apiDocumentation/apiDocumentation?page=API+-+System+v1.html

 

The first thing you have to do to start using REST API is to obtain a valid Access Token. There are three ways to get this token and they are described in documentation too.

  1. Resource owner for really trusted application
  2. Authorization code for server-side application
  3. Implicit for client-side application

 

I chose the first one because it’s the easy to implement and fits my needs.

 

It’s as simple as making a HTTPS request to:

https://na.airvantage.net/api/oauth/token?grant_type=password&username=YOUR@EMAIL.COM&password=YOURPA$$WORD&client_id=CLIENT_ID&client_secret=CLIENT_SECRET

 

Where:

  • YOUR@EMAIL.COM is the email you use to login to AirVantage
  • YOURPA$$WORD is your AirVantage password
  • CLIENT_ID is your API Client ID
  • CLIENT_SECRET is the API Client Secret

You obviously need to have an API Client in order to fill in these parameters. If you don’t have one, you need to create it: go to AirVantage management console and there navigate to Develop -> API Clients and then click Create (Name is the only mandatory parameter). After you create a client you will have your Client ID and corresponding Secret Key.

 

In response to the above HTTPS request you will receive a JSON string which, among other values like access rights and token type, contains your Access Token that you can use to perform REST API calls. This token is valid for 1 day (86399s to be exact).

 

One more thing! Many REST API calls take system UID as a parameter, at least those that I require for my application. You can get your system's UID by clicking on System name in the Systems table under Inventory. Make sure not to click the system's serial in that table like I did the first time I tried to get the UID - this will take you to the linked Gateway instead.

 

I hope this will save time to others who are new to AirVantage or MQTT like I am.

 

Cheers,

Dragan

  • Sign in to reply

Top Comments

  • amgalbu
    amgalbu over 10 years ago +1
    Hi dragan That would mean that a device that connects to air vantage using mqtt has no way to receive data (e.g. configuration settings) but implement rest api and poll? That a really bad limitation they…
  • tomaja
    tomaja over 10 years ago in reply to amgalbu

    Hi Ambrogio!

     

    Well, looks like there's no other option apart from using their framework (ie. REST API). There is support for subscription to <SERIAL>/tasks/json. If you subscribe to that topic you should get settings updates and commands. The problem is in the fact that you can't subscribe to <SERIAL>/messages/json.

     

    As explained by dlahay (http://www.element14.com/community/thread/39246/l/subscription-to-airvantage-mqtt-topic), AirVantage MQTT is not a complete MQTT broker service. As I understand, they provide limited MQTT support where you can't publish to an arbitrary topic from Client_1 and subscribe to the same topic on Client_2.

     

    I agree, it would be easier to use just MQTT instead of having to mix it with REST but since I have enough resources (AirVantage will be accessed from BeagleBone Black, smartphone and tablets and desktop clients) this will not be too much of a problem. It just wasn't obvious that I have to use REST, I spent a lot of time on trying to make it work by subscribing to MQTT topic.

     

    Dragan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 10 years ago in reply to tomaja

    Hi Dragan

    It seems to me that Airvantage put a big burden on developers by not providing support for MQTT subscriptions.. Probably the want developers to use their framework

     

    Ambrogio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tomaja
    tomaja over 10 years ago in reply to amgalbu

    Sorry, maybe I didn't put it clear then, I will modify the post to be make it more clear. You can subscribe to settings and commands (I think that you must use REST to issue settings updates and commands, but I'm not sure, didn't try that yet)

    Sensor values can be published via MQTT but if you want to receive these values in some client application, that application will have to use REST to request values (you can't just subscribe to the same topic that you publish data to).

     

    Dragan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 10 years ago in reply to amgalbu

    If that's indeed the case, that would be bad!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • amgalbu
    amgalbu over 10 years ago

    Hi dragan

    That would mean that a device that connects to air vantage using mqtt has no way to receive data (e.g. configuration settings) but implement rest api and poll?

    That a really bad limitation they have put on air vantage!!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube