Boost your IoT Device with Qt
Here at guh GmbH, the creators of the IoT platform nymea, we have been using Qt since right from the start. You may think: it seems an odd choice to use Qt for a device with no UI requirements but just middleware components basically invisible to the user. Let me explain why this definitely isn’t the case. Essentially, there are three misconceptions in the previous statement.
UI Framework: Yes, but so Much More
The first and biggest misconception is that Qt only focuses on UI projects. It is true that Qt started as a UI toolkit many, many years ago. But since then, Qt has evolved into a fully featured set of libraries and tools supporting the developer in every layer of the stack. Even if you don’t need graphical bells and whistles, Qt will increase your productivity by an order of magnitude. I’ll go a bit more in depth later on.
UI has Many Faces
Now, let me address the second misconception in the above statement: that no display equals no UI. Even when you’re building an embedded device without display, there’s hardly no user interface for it. In our example the user interface consists of a web interface running on the IoT box and a client app. The client application, running on mobile phones, PCs or just wall-mounted displays is mostly a thin UI layer, talking to the device. Here, Qt Quick can deliver a smooth, modern experience with a "write once, run everywhere" application. And the coolest part: since Qt 5.10, this very same client application can be re-used as the web interface on the device deploying the new Qt WebGL features.
No More Overhead: Deploy Only What You Need
Another comment I’ve often heard is that importing Qt into an embedded device would be a huge overhead. While in the early days, Qt was built of some few, rather big modules, this has changed a long time ago. At the very latest with Qt5, the modularization of Qt has facilitated fine-grained control of what parts of Qt are needed for a small footprint installation. However, in recent days this has been taken even further, and with Qt for devices it is now possible to strip down the required components to the real bare minimum, invalidating this point completely.
How Qt has Increased Our Productivity Building nymea:
As mentioned above, I’d also like to address some of the features of Qt which have helped increase the productivity of nymea tremendously.
There are too many to list them all here, but the most important ones for our middleware stack are:
- Plugin architecture: Qt’s plugin architecture is a perfect fit to load plugins, taking away all the complexity of finding and loading libraries. With nymea being built based on plugins, this constitutes a significant advantage. The core of the platform is a piece of software managing configurations and the "smartness" of things. All the actual hardware and online services, so called “things”, are enabled in the system via plugins.
- Transport protocols: Just a few calls to the Qt APIs are all it takes. nymea's middleware offers interfaces via sockets (TCP/IP or local sockets), WebSockets, REST and Bluetooth RFCOMM. All of those are simply at hand with Qt, using SSL encryption, providing certificates for secure communication.
- JSONRPC based API: Qt offers support for JSON and allows easy conversion between internal data structures into JSON objects. This is a huge plus for us since nymea speaks a JSONRPC based protocol when interacting with clients.
- Testing and debugging framework: Developers enjoy the advantages of a highly abstracted API. nymea’s codebase is studded with autotests using Qt Test. This turns writing test cases into an easy task and facilitates printing test reports and statistics in a variety of common formats (like UnitXML). Additionally, it enables integration with other existing frameworks for testing and debugging like coverty, Valgrind and all the other tools out there, as in the end, for those it’s just good old C++.
- API documentation using QDoc: Qt offers an amazing documentation on doc.qt.io. QDoc enables doc generation directly out of the code through the CI setup and allows flexible custom styling while still preserving the clean look and feel of Qt docs. For nymea (https://doc.nymea.io/) as a platform which enables third-party developers to add their hardware/service such documentation is obviously essential.
- A ton of small helpers all along the way: Qt offers an uncountable amount of features coming in handy while developing a headless application. From command-line argument parsing and log output filtering to online connectivity, various IPC mechanisms in the system (e.g. D-Bus) etc. Every feature is just ready to use with minimal effort.
- All (or pretty much all) of this comes in a completely cross platform manner. While nymea is focused to run on Linux based devices, thanks to Qt it can be built for just about any platform. Of course, some platform integrated features like D-Bus APIs won’t work on all platforms, but those are very rare exceptions. Currently, nymea has a dpkg based repository for all supported Ubuntu and Debian distributions as well as snap packages for snap based systems. The client app is built for desktops and Android targets. Our team is also working on enabling iOS and the WebGL based version to have a fully Qt Quick based web interface for nymea, all out of a single codebase.
The gist of all this: Qt is an ideal framework whether your project includes a UI or not. Its high number of well-tested, high-quality APIs make every developer's life that much easier, especially as those APIs are super easy to understand. Meanwhile, Qt still allows you to enjoy all the advantages of C++. So as you can see Qt is perfect for IoT.
About nymea: nymea makes your product smart. Fast, plannable, and hassle-free. Our M2M stack guarantees effortless API integrations. We believe in the strength of integrated edge solutions.
Meet us at Embedded World 27th Feb - 1st March 2018. Get your free ticket here: https://www.qt.io/ew-2018
Subscribe to our newsletter
Try Qt 6.5 Now!
Download the latest release here: www.qt.io/download.
Qt 6.5 is the latest Long-Term-Support release with all you need for C++ cross-platform app development.
Qt World Summit 2023: Berlin awaits!
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.