How to Implement an Environmental Monitoring System on the STM32MP257 Board
2025-06-23
325
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-11-27
SECC GreenPHY Solution: Bridging STM32MP135 SOM to V2G Industry Advancement
Debug MSE102x G on MYC-YF13X, providing reference for V2G communication development.
2025-11-20
SECC Solution for Charging Pile Applications
MYIR's SECC solution delivers a high-standard, low-risk rapid development platform for clients, with core strengths in protocol compatibility, operational security, and a comprehensive reference design.
2025-11-02
Simultaneous Control of 4 YOLOv8 Video Streams via MYIR's RK3576 Board
In the era of rapid technological advancement, the integration of artificial intelligence and edge computing is transforming our lives at an unprecedented pace. The RK3576 processor features a quad-co
2025-09-20
Compiling OpenCV and Developing Applications on the RK3576 Board
This article introduces how to compile OpenCV on the RK3576 development board and build an application.
2025-08-30
MYIR T536 Development Board: Multi-protocol IoT Gateway Solution Test
The article details the development and testing of a multi-protocol IoT gateway solution that utilizes MYIR's MYD-LT536 development board, which is based on the Allwinner T536 SoC.
2025-08-29
MYIR RK3576 Development Board: 12-Channel 1080p HD Video Streaming
MYIR has successfully achieved efficient H.264 encoding and low-latency RTSP streaming for 12-channel HD video streams on the Rockchip RK3576 SOM.
2025-08-07
Compiling Kernel for MYD-LMX9X Development Board
This guide walks you through building a Linux kernel for the MYIR MYD-LMX9X Development Board
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).