Table of contents

<< Previous

Next >>


Introduction :

 

In this post I will provide Step by step guide for communicating your BBB/Pi with Airvantage over MQTT.

I have used Paho - Open Source messaging for M2M , this guide to install Paho Python MQTT Client on My Raspberry Pi B+. As have not received my BBB so far. I am very much sure that the same steps will also work with BBB.

 

DIY Guide :

 

Step1 : Setup System with MQTT Support on Airvantage M2M cloud..

 

I have used https://doc.airvantage.net/display/USERGUIDE/Using+MQTT+with+AirVantage this guide to setup System with MQTT Support on Airvantage Cloud.

 

Step2 : Test the system using MQTT Client..

I have used MQTTLens Google Chrome extension as easy to use MQTT Client for Test my system on Airvantage cloud from https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm

 

here is screenshot of connection setup to Airvantage system on MQTTLens... Here username is system serial no and Password is system password...

Untitled1.png

Untitled2.png

First subscribe to <username>/messages/json topic then send json string with data....

Untitled3.png

 

here is screen shot of my System working on Airvantage cloud..

Untitled.png

once airvabtage start responding to your MQTT pulish message then move to next step...

 

Step3 : install paho MQTT Python client on your Pi... from this guide http://www.eclipse.org/paho/clients/python/

once installed creat new python file with your system credential...

 

import paho.mqtt.client as paho




host="na.airvantage.net"
port=1883


def on_connect(pahoClient, obj, rc):
# Once connected, publish message
        print "Connected Code = %d"%(rc)
        client.publish("<username>/messages/json", "{\"machine.temperature\": 23.2, \"machine.humidity\": 70}", 0)




def on_log(pahoClient, obj, level, string):
        print string


def on_publish(pahoClient, packet, mid):
# Once published, disconnect
        print "Published"
        pahoClient.disconnect()


def on_disconnect(pahoClient, obj, rc):
        print "Disconnected"


# Create a client instance
client=paho.Client()


# Register callbacks
client.on_connect = on_connect
client.on_log = on_log
client.on_publish = on_publish
client.on_disconnnect = on_disconnect


#Set userid and password
client.username_pw_set(<userID>, <password>)


#connect
x = client.connect(host, port, 60)


client.loop_forever()



 

name this file say airvantage.py or any thing of ur choice..run this file by command

python airvantage.py

 

U will see update on Airvantage cloud with your latest data....

 

In next post I will explore Airvantage API and creat real time python appilication on RaspberryPi with external inputs ... and will show this data on Airvantage cloud...