This commit is contained in:
cxh 2025-06-05 09:38:24 +08:00
parent 57d3cfe753
commit 5233c4e9af

View File

@ -5,6 +5,7 @@
#include <thread> #include <thread>
#include "SerialPort.h" #include "SerialPort.h"
#include "LedCommand.h" #include "LedCommand.h"
#include "LedMqttSubscriber.h"
using namespace toml; using namespace toml;
@ -86,6 +87,19 @@ int main()
std::cout << "串口号: " << port << "\n波特率: " << baudrate << std::endl; std::cout << "串口号: " << port << "\n波特率: " << baudrate << std::endl;
// ===== MQTT 测试连接 =====
MqttClient mqtt("config.toml"); // 构造时自动读取配置并初始化
if (mqtt.connect())
{
std::cout << "MQTT 连接成功" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
mqtt.disconnect();
}
else
{
std::cerr << "MQTT 连接失败" << std::endl;
}
SerialPort serial; SerialPort serial;
if (!serial.openPort(port, baudrate)) if (!serial.openPort(port, baudrate))
{ {