How to Implement an Environmental Monitoring System on the STM32MP257 Board

2025-06-23

93
This article is excerpted from the outstanding creator - lugl4313820, who integrated the ongoing Thingy:91X cellular IoT prototype development platform testing project with MYIR's MYD-LD25X development board (MYIR's STM35MP257-based development board) to implement a simple environmental monitoring system.
1. Hardware Platform
1) MYIR MYD-LD25X Development Board
2) Thingy:91X
2. Implementation Steps
1) The MYR-LD25X development board integrates an onboard Wi-Fi module, enabling connection to the internet via Wi-Fi.
2) Enable MQTT communication to connect with a private server and subscribe to specified topics for data transmission.
3) Design and develop a user interface (UI) using the Qt framework.
4) Receive data and display it in the user interface.
3. How to design QT
1) Qt Installation
1.1 Please download the online installer for Qt from the following link:
Index of /qtproject/official_releases/online_installers/
1.2 After downloading, upload the it to the virtual machine and proceed with the installation. There are several aspects to consider during the installation process. For the rest, just follow the official tutorial to complete the installation.
2) Configuring Cross-Compilation Toolchain in Qt Creator
1.1 In the official example, unlike this version, you only need to select gcc to set GCC first, and then g++ is automatically selected below:
1.2 Select the QT version according to the picture below.
1.3 Then you can cross-compile, as shown below.
3) Creating Desktop Program
Based on the introduction in this article, I created a QT-based desktop program with the following UI:
4) Define Label Values
Define the corresponding label values for the labels that need to be displayed based on the received data:
5) Import QT's QtMqtt/QMqttClient library
#include <qtmqtt qmqttclient="">
Note: The officially released firmware does not include a QTMqtt connection file. When executing a program that uses QtMqtt, an error will be reported.
error while loading shared libraries: libQt5Mqtt.so.5: cannot open shared object file: No such file or directory
Therefore, it needs to be copied from the SDK to the development board directory.
6) Checking the Status of the Connection
At the same time, in order to detect the connection status with the MQTT server, a thread needs to be introduced to detect whether it is connected to the server:
void run() override
{
while (true)
{
if (m_client)
{
QString statusText = m_client->state() == QMqttClient::Connected
? "Connected to server: Success"
: "Connected to server: Failed";
emit updateStatus(statusText);
}
msleep(1000); // Check once every second
}
}
7) Write the following code within the main function:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), m_client(new QMqttClient(this)) // Initialize the MQTT client instance
{
ui->setupUi(this);
// Set MQTT client parameters
m_client->setHostname("hostname");
m_client->setPort(1883); // Default MQTT port
m_client->setClientId("client_id");
m_client->setUsername("usrename");
m_client->setPassword("pwd");
// Connect signal slot to handle successful connection event
connect(m_client, &QMqttClient::connected, this, [this]()
{
// Connection successful, update label text
ui->mqtt_client_state->setText("Connected to server: Success");
// Subscribe to topic
m_client->subscribe(QMqttTopicFilter("devacademy/publish/topic")); });
// Connect signal slot to handle message reception event
connect(m_client, &QMqttClient::messageReceived, this, &MainWindow::onMessageReceived);
// Start MQTT connection
m_client->connectToHost();
// Create and start connection status checking thread
MqttConnectionChecker *checker = new MqttConnectionChecker(m_client, ui->mqtt_client_state, this);
connect(checker, &MqttConnectionChecker::updateStatus, this, [this](const QString &status)
{ ui->mqtt_client_state->setText(status); });
checker->start();
}
8) The callback function for receiving subscription messages is as follows:
void MainWindow::onMessageReceived(const QByteArray &message, const QMqttTopicName &topic)
{
Q_UNUSED(topic);
// Parse JSON data
QJsonDocument doc = QJsonDocument::fromJson(message);
if (!doc.isNull() && doc.isObject())
{
QJsonObject obj = doc.object();
double temp = obj.value("temp").toDouble();
double press = obj.value("press").toDouble()/100;
double humidity = obj.value("humidity").toDouble();
int iaq = obj.value("iaq").toInt();
double co2 = obj.value("co2").toDouble();
double voc = obj.value("voc").toDouble();
//Update these data to the UI
ui->label_temp->setText(QString::number(temp, 'f', 2));
ui->label_press->setText(QString::number(press, 'f', 2));
ui->label_humidity->setText(QString::number(humidity, 'f', 2));
ui->label_iaq->setText(QString::number(iaq, 'f', 2));
ui->label_co2->setText(QString::number(co2, 'f', 2));
ui->label_voc->setText(QString::number(voc, 'f', 2));
// You can update the parsed data to the UI or other processing logic here
}
Else
{
qDebug() << "Invalid JSON message received";
}
}
9) Experimental Results
After compiling the program, upload it to the development board and run it; the results are as follows:
The MYIR MYD-LD25X STM32MP257 development board allows for the design of a user interface with Qt, and with MQTT, it is possible to subscribe to particular topics for real-time environmental monitoring. This solution has significant potential within the Internet of Things (IoT) domain!
2025-06-23
RZ/G2L-Based MYD-YG2LX System Startup Time Optimization Application Notes
This article introduces a debugging case for optimizing system boot time based on the MYD-YG2LX development board.
2025-06-17
OpenCV Pedestrian Detection Application Solution Based on MYIR's T527 Development Board
In this article, we will introduce the testing of OpenCV pedestrian detection solution based on MYIR's MYD-LT527 Development Board (based on Allwinner T527 processor).
2024-09-23
Ethernet Driver Porting Guide Based on MYIR's NXP i.MX.93 Development Board
Ethernet Driver Porting Guide Based on MYIR's NXP i.MX.93 Development Board MYD-LMX9X
2024-08-16
QT Development Guide for NXP i.MX 93 Development Board by MYIR
1. OverviewQt is a cross-platform graphical application development framework that is applied to devices and platforms of different sizes, while providing different license versions for users to choos
2024-06-16
Application Notes | Setting up OTA Functionality on MYIR's NXP i.MX 93 Development Board
1. OverviewOver-the-Air Technology (OTA) is a technology that enables remote management of mobile terminal equipment and SIM card data via the air interface of mobile communication. In this article, O
2024-06-13
Ubuntu System Porting Guide for Renesas RZ/G2L-based Remi Pi
1. OverviewLinux system platform has a variety of open source system building frameworks, which facilitate the developer in building and customizing embedded systems. Currently, some of the more commo
2024-05-22
Boosting the Power Industry: Notes on Porting the IEC61850 Protocol to the MYD-YF13X
Part 1: OverviewIEC 61850 is an international standard for communication systems in Substation Automation Systems (SAS) and management of Decentralized Energy Resources (DER). Through the implementati
2024-02-04
Next-Generation AM62x CPU for Embedded Solutions
Combining MYIR's MYC-YM62X CPU Module and MYD-YM62X Development Board, here we share with you TI's new generation CPU - AM62x used for embedded solutions.
2023-12-07
Developing AIGC using DNN through MYIR's Renesas RZ/G2L based Board
This evaluation report is provided by developer "ALSET" from MYIR’s forum. This article will introduce how to develop AIGC image using Deep Neural Networks (DNN) through MYIR’s Renesas RZ/G2