Store MQTT Data From Sensors Into MySQL Database
This article will explain how e-con’s eSOMiMX6 can be used to store MQTT data from sensors into MySQL database using Qt.
MQTT is a great protocol for Sensors to publish data to their Subscribers. However, when it comes to analytics or reporting, you need historical data. Most MQTT brokers don’t provide any built-in mechanism to save MQTT data into Database.
To showcase how we can store MQTT data from sensors into MySQL database on eSOMiMX6 device, we made the following setup:
Developed a MQTT subscriber Qt application using QtMQTT. The subscriber application will push MQTT Data into MySQL Database.
Made eSOMiMX6 to act as a broker.
Used particle photon board with weather shield addon board to publish temperature, pressure, wind speed, direction values.
The Subscriber/client application used Qt SQL module to access the database.
The Qt SQL module uses driver plugins to communicate with several database APIs. Qt has drivers for SQLite, MySQL, DB2, Oracle, ODBC, and PostgreSQL. With the MySQL driver, it is possible to connect to a MySQL server.
Once the driver part is set up, the data is accessible using the classes, QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel.
Full source code for the application is available on e-con Systems™ developer site.
Please refer our previous articles on How to setup Qt creator for eSOMiMX6 devices and How to build, deploy and run Qt applications on eSOMiIMX6 devices to build and run the application on eSOMiMX6 devices.
For further assistance and queries get in touch with email@example.com
Store MQTT Data From Sensors Into Qt MySQL Database :