Accessibility tools

Challenges with cloud messaging for embedded devices has inspired the Kaltiot & SnowGrains teams to create a cross platform Qt API which enables easy push messaging from and to embedded devices. The API is called the Qt Cloud Messaging API and it is built with flexibility and extensibility in mind.

We have decided to target other Qt areas, too, and make the API easily extensible to any service provider instead of being for embedded only. This enables developers to use the same API for both mobile and desktop development.

There is a vast amount of push messaging providers for mobile and web development nowadays. Yet in industries like automation, automotive, robotics and for other embedded devices there has not really been any providers for this type of service. The need is increasing at a rapid pace as embedded and IOT devices are pushed more and more messages by the device owners, car service providers, telemetry, cloud and and many others.

The Qt Cloud Messaging API is simple to adopt and take into use.

Let’s take a sneak peek on how to utilize the API for embedded systems and Android mobile platforms. We’ve integrated the Kaltiot Smart IoT SDK and the Firebase C++ SDK into the backend, and with the Qt Cloud Messaging API we can easily create e.g. a chat application on top of it.

Kaltiot Smart IoT is a service for scalable and secure messaging between devices and services. It provides bi-directional and always online, yet battery optimized communication. The client SDK is designed to work even in constrained low-end devices in poor wireless network conditions. Kaltiot Smart IOT is available for Linux32, Linux64, Raspberry Pi, Mac, Android.

How to use the Qt Cloud Messaging API for embedded devices

Service provider

Pre-requirements:

  1. Get the Kaltiot SDK to your embedded device from (e.g. Linux or Raspberry Pi SDK) https://console.torqhub.io
  2. Get the API key for sending channels or/and creating server side implementation

C++ part:

#include <QObject>
#include <qtcloudmessaging.h>
#include <QtCloudMessagingEmbeddedKaltiot>

int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;

//! Instantiate QtCloudMessaging class into your class or main.cpp
QtCloudMessaging *m_qtCM = new QtCloudMessaging();

//! Add Kaltiot provider.
m_kaltiotPushService = new QTCM_KaltiotPushServiceProvider();

//! Create Parameter variable for provider
QVariantMap params;

//! Difference to Google cloud messaging, the service provider specific parameters are needed.

params["address"] = "QtCloudMessaginDemoApp";
params["version"] = "1.0";
params["channel"] = "weather_broadcast_channel";
params["customer_id"] = "Kaltiot";

//! API_KEY Is needed for mobile client to be able to send topic messages from the client without backend server.

params["API_KEY"] = "8riksUXIIbkQmG4Q1jeG5AniLjkd2xxhtGq8w15h2jMzQ3fpvwEcwUO2dQwE9%2BrP7ofGIRQheZgC9RyxeoDNq0fp4tpjSntLCYr05Yanb9I%3D";

//! Registering the Kaltiot service component.
m_qtCM->registerPushService("KaltiotService",m_kaltiotPushService,&params);
m_qtCM->connectClient("KaltiotService","QtCloudMessaginDemoApp", params);

//! Automatically subcribe to listen one topic e.g. ChatRoom.
m_qtCM->subsribeToChannel("weather_broadcast_channel","KaltiotService","QtCloudMessaginDemoApp");

//! Provide context to QML
engine.rootContext()->setContextProperty("m_qtcloudmsg", m_qtCM);

//! Start QML file
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}

QML part:

in main.qml catch the messages coming from the Kaltiot service.

To receive the message in QML:

Connections{
target :m _qtcloudmsg
onMessageReceived:{

//! Message is received as string and needs parsing to JSON

console.log(message)
}
}

Sending messages

//! For firebase, message structure needs to have data as whole message.
//! Notifications are shown in the Android/iOS notification center.
//! Sending a broadcast message e.g. from the weather station:
//! Message structure for embedded devices is easy:
//! define payload json:
//! {
//!   "payload_type":"STRING",
//!   "payload": encodeURI(JSON.stringify(payload))
//! }
//! Payload is your application specific. E.g:
var payload =
{
msgType:"NEW_WEATHER_INFO",
city: "Oulu",
forecast: "full sunlight for whole next week"
}

//! Capsulate payload to message and send it via QtCloudMessaging API:
var payload_array = [{"payload_type":"STRING","payload": encodeURI(JSON.stringify(payload))}]
m_qtcloudmsg.sendMessage(JSON.stringify(data),"KaltiotService","QtCloudMessaginDemoApp","","weather_broadcast_channel");

Google Firebase

Using the Qt Cloud Messaging API for Android / iOS mobile development with Google Firebase service provider is described below.

Pre-requirements:

  1. Create new project into Google Firebase console: https://firebase.google.com/
  2. Download Google Firebase C++ SDK  and  the Firebase configuration file for Android Gradle:

DISTFILES += \

android/google-services.json

Define Google firebase path into your application.pro file:

e.g. for Android:

GOOGLE_FIREBASE_SDK = /Users/snowgrains/projects/kaltiot/providers/googlecloud/firebase_cpp_sdk
INCLUDEPATH += $${GOOGLE_FIREBASE_SDK}/include
INCLUDEPATH += $$PWD/../../../qtpushserviceplugin \
$$PWD/../../qtcm_firebaseserviceprovider
LIBS += $${GOOGLE_FIREBASE_SDK}/libs/android/armeabi-v7a/gnustl/libmessaging.a
LIBS += $${GOOGLE_FIREBASE_SDK}/libs/android/armeabi-v7a/gnustl/libapp.a

Read more from the Google Cloud messaging:

firebase.google.com →

C++ part:

#include <QObject>
#include "qtcloudmessaging.h"
#include "qtcm_firebaseserviceprovider.h"
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;

//! Instantiate QtCloudMessaging class into your class or main.cpp
QtCloudMessaging *m_qtCM = new QtCloudMessaging();

//! Add Google Firebase provider.
QTCM_FirebaseServiceProvider *m_firebaseService = new QTCM_FirebaseServiceProvider();

//! Create Parameter variable for provider

QVariantMap params;

//! SERVER_API_KEY Is needed for mobile client to be able to send topic messages from the client without Firebase application server.

//! Recommendation from the Google is that server API key is not stored inside of the application code due security reasons.
params["SERVER_API_KEY"] = "<insert here the google firebase server api key. You can get it from the firebase console;
//! Registering the Google firebase service component.
m_qtCM->registerProvider("GoogleFireBase",m_firebaseService,&params);

/*! Connected client is needed for mobile device.

\param Service name "GoogleFireBase"
\param Client identifier name to be used inside the demo application
\param Parameters for the client. Not used at this point.*/

m_qtCM->connectClient("GoogleFireBase","MobileClient", QVariantMap());

//! Automatically subcribe to listen one topic e.g. ChatRoom.
m_qtCM->subsribeToChannel("ChatRoom","GoogleFireBase","MobileClient");
//! Provide context to QML
engine.rootContext()->setContextProperty("m_qtcloudmsg", m_qtCM);
//! Start QML file
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}

QML part:

in main.qml catch the messages coming from the google firebase

Receiving messages

Connections{
target :m _qtcloudmsg
onMessageReceived:{
//! Message is received as string and needs parsing to JSON

console.log(message)
}
}

Sending messages:

//! For firebase, message structure needs to have data as whole message.
//! Notifications are shown in the Android/iOS notification center.
function sendMessage(notification_titile, notification_msg, msg){
var data = { "data":{
"message": {"text":msg } },
"notification" : {
"body" : notification_msg,
"title" : notification_titile
}
}

//! Give data and service provider identifier as well as client name defined in the C++ code.

>m_qtcloudmsg.sendMessage(JSON.stringify(data),"GoogleFireBase","MobileClient","","ChatRoom");
}

You can play around with the Qt Cloud Messaging API + firebase from the sample:

https://github.com/qt

The Qt Cloud Messaging API provides cross-platform API to enable us to include new providers and still keep the development API as same. The API has been developed to be easily extensible to any service provider. Take a sneak peek to ongoing development from the Github and contribute your own backend service to community.

Kaltiot has been developing and hosting IoT cloud services since 2008. Trusted e.g. by Microsoft, Kaltiot passes through 10M messages every hour. https://kaltiot.com

SnowGrains provides Full Stack Software Solutions On The Rocks.