mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现MQTT功能, 修改HTTP接口
This commit is contained in:
@@ -39,9 +39,6 @@ void Application::init()
|
||||
// 创建HTTP服务线程
|
||||
std::thread([=]() {
|
||||
while (!isQuit) {
|
||||
MqttClient mqttCli;
|
||||
mqttCli.init("tcp://localhost:1883", "AAAAAAAAA", "", "", {"topic/test"}); // 不阻塞
|
||||
|
||||
HttpEntity http;
|
||||
http.listen("0.0.0.0", Config::option.http.port); // 阻塞
|
||||
}
|
||||
@@ -63,37 +60,41 @@ void Application::runThreadDevice()
|
||||
void Application::runThreadMain()
|
||||
{
|
||||
std::string addr = "tcp://localhost:1883";
|
||||
mqttCli = std::make_shared<MqttClient>();
|
||||
mqttCli->init(addr, "ESS", "", "", {});
|
||||
//mqttCli = std::make_shared<MqttClient>();
|
||||
//mqttCli->init(addr, "ESS", "", "", {});
|
||||
|
||||
while (!isQuit)
|
||||
{
|
||||
// 连接场站
|
||||
static TimeTick ttStation;
|
||||
if (ttStation.elapse(10000))
|
||||
{
|
||||
if (!mqttCli->isConnected)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& item: appdata.mapStation)
|
||||
{
|
||||
auto station = item.second;
|
||||
if (station && !station->isConnected)
|
||||
{
|
||||
std::vector<std::string> vecTopics = {"topic/test" + std::to_string(station->id)};
|
||||
mqttCli->subscribe(vecTopics, [=](int id)
|
||||
{
|
||||
station->isConnected = (id == 0);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//// 连接场站
|
||||
//static TimeTick ttStation;
|
||||
//if (ttStation.elapse(10000))
|
||||
//{
|
||||
// if (!mqttCli->isConnected)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for (auto& item: appdata.mapStation)
|
||||
// {
|
||||
// auto station = item.second;
|
||||
// if (station && !station->isConnected)
|
||||
// {
|
||||
// std::string stationCode = station->code;
|
||||
// std::vector<std::string> vecTopics = {
|
||||
// "up/json" + stationCode + "/EMS_YX",
|
||||
// "up/json" + stationCode + "/EMS_YC",
|
||||
// "up/json" + stationCode + "/PCU_YX",
|
||||
// "up/json" + stationCode + "/PCU_YC",
|
||||
// };
|
||||
// mqttCli->subscribe(vecTopics, [=](int id)
|
||||
// {
|
||||
// station->isConnected = (id == 0);
|
||||
// });
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user