Previous posts:
In the Air Design Challenge - Pollen & Allergen Sensing
In the Air Design Challenge - Pollen & Allergen Sensing – Post 1 (Pollen Sensor)
Introduction
Since I had problem with customs and still waiting for my kits (Christian is very helpful and hopefully we will sort it out soon) I decided to spend some time in preparing software part of my project, both BeagleBone Black and remote clients.
Development platform
In order to make one code base that will run on multiple platforms (desktop and mobile) I decided to use Qt | Cross-platform application & UI development framework. Qt framework is packed with features that make life easier for developers. I have some experience with Qt but not too much so this will also be a fun way to get more into the Qt framework and development tools.
As we got free AirVantage MQTT access, I decided to use the C version of open source Paho MQTT library (Paho - Open Source messaging for M2M). This library provides versions for use in many popular programming languages (Java, C/C++, Python, Go, JavaScript and C#). There’s also a version called C(Embedded) suitable for microcontrollers if you plan to publish data from a LaunchPad or if you plan to send some commands directly to it (via subscription).
Additionally, I chose to use the AnalogWidgets library for Qt (nice gauges design in my opinion).
This library provides some nice gauges that can easily be customized for my project. I will use it for both apps (clients and BBB dashboard).
BeagleBone Black
BeagleBone Black will serve as a central house unit that’s responsible for communication with AirVantage cloud service and on the other side for communication with CC3200 LaunchPad. It will also serve as a system dashboard – I ordered a 4.3” resistive touchscreen for BeagleBone Black to be used for that role. There are tutorials and even YouTube videos on Qt development for BeagleBone black so I will just provide some links:
- https://www.youtube.com/watch?v=eLr35wUrz6Q
- https://www.youtube.com/watch?v=QmJlHJ1REbM
- Tutorial: Creating Qt-Embedded Projects for Beaglebone with Visual Studio
Project specific code is the part that’s in charge of MQTT publishing and here’s how it looks like. It’s pretty much out-of-the-box example with a small addition to connection options – username and password must be provided for AirVantage. Additionaly QoS parameter had to be set to 0 for data to be published successfully.
Code:
#define ADDRESS "tcp://na.airvantage.net:1883" #define CLIENTID "BBB_Client" #define TOPIC "123456789/messages/json" #define TOPICSUB "123456789/tasks/json" #define PAYLOAD "{\"machine.temperature\":39.2, \"machine.humidity\":86, \"machine.pollen\":3 }" #define QOS 0#define TIMEOUT 10000L QTTClient client; MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; MQTTClient_message pubmsg = MQTTClient_message_initializer; MQTTClient_deliveryToken token; int rc; MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_NONE, NULL); conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; conn_opts.username = "123456789"; conn_opts.password = "supersecret"; if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to connect, return code %d\n", rc); } pubmsg.payload = (void*)PAYLOAD; pubmsg.payloadlen = strlen(PAYLOAD); pubmsg.qos = QOS; pubmsg.retained = 0; MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token); printf("Waiting for up to %d seconds for publication of %s\n on topic %s for client with ClientID: %s\n", (int)(TIMEOUT/1000), PAYLOAD, TOPIC, CLIENTID); rc = MQTTClient_waitForCompletion(client, token, TIMEOUT); printf("Message with delivery token %d delivered\n", token); MQTTClient_disconnect(client, 10000); MQTTClient_destroy(&client);
I plan to add the history charts to the dashboard but I still didn’t manage to get the historical data back from AirVantage. There seems to be a REST API for getting raw historical data (https://na.airvantage.net/develop/apiDocumentation/apiDocumentation?page=API+-+System+v1.html) but I didn’t find anything like it in AirVantage MQTT Docs.
I’m not sure if this is even possible with MQTT.
UPDATE: No, it's not. We have to use the REST API to get historical data. Please read the following post for more details: In the Air Design Challenge - Pollen & Allergen Sensing – Post 3 (AirVantage Intro)
Optionally, depending on sensor inputs or AirVantage commands, BeagleBone Black should also control actuators (if I get enough time for it). I’m not sure I will fit this task into given timeframe, might be done later.
Remote clients (desktop and mobile)
As I said, Qt will also be used for remote clients, both mobile and desktop. It will also be able to show readings history when I sort out how to get it from AirVantage using MQTT.
Additionally, I will support direct actuators control once I get to the point that I can add them - not necessary in the given timeframe.
I’ve come up with an initial application design that runs on Desktop(Windows, Linux and Mac), and mobile (Android, iPhone and BlackBerry) but still not good enough to be presented here so give me a week or two for screenshots.