mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
调试修改MQTT通讯解析
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "protocol/HttpEntity.h"
|
||||
#include "common/Spdlogger.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
#include "DataStruct.h"
|
||||
|
||||
void Application::init()
|
||||
{
|
||||
@@ -17,9 +18,9 @@ void Application::init()
|
||||
Config::init("assets/config/app.json");
|
||||
|
||||
// MQTT 数据结构
|
||||
MqttClient::loadDataStruct("assets/config/registeraddr.json");
|
||||
REGAddr::load("assets/config/regaddrs.json");
|
||||
// 设备读取寄存器的地址定义
|
||||
Device::loadParamAddr("assets/config/monitoraddr.json");
|
||||
Device::loadParamAddr("assets/config/regaddrsShow.json");
|
||||
|
||||
// 设置数据库配置
|
||||
DaoEntity::setOption(Config::option.database.host,
|
||||
@@ -67,49 +68,43 @@ void Application::runThreadDevice()
|
||||
|
||||
void Application::runThreadMain()
|
||||
{
|
||||
std::string addr = "tcp://localhost:1883";
|
||||
//mqttCli = std::make_shared<MqttClient>();
|
||||
//mqttCli->init(addr, "ESS", "", "", {});
|
||||
|
||||
while (!isQuit)
|
||||
{
|
||||
if (!this->isInit) // 初始化失败
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
this->isInit = appdata.init();
|
||||
if (!this->isInit) { continue; }
|
||||
}
|
||||
|
||||
static TimeTick ttMqtt;
|
||||
// 检查 场站的 MQTT 连接
|
||||
if (ttMqtt.elapse(10))
|
||||
static TimeTick ttMqtt(1); // 检查 场站的 MQTT 连接
|
||||
if (ttMqtt.elapse(20))
|
||||
{
|
||||
auto& optionMqtt = Config::option.mqtt;
|
||||
if (!optionMqtt.host.empty())
|
||||
{
|
||||
for (auto& item : appdata.mapStation)
|
||||
{
|
||||
if (item.second)
|
||||
auto& station = item.second;
|
||||
if (station && station->isOpen)
|
||||
{
|
||||
// 该函数检查连接状态,若已经连接,则无操作;若未连接,则进行连接操作
|
||||
item.second->initMqtt();
|
||||
//item.second->polling();
|
||||
// 召测
|
||||
item.second->polling();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 召测
|
||||
static TimeTick tt1;
|
||||
if (tt1.elapse(10))
|
||||
{
|
||||
|
||||
static TimeTick ttData(1); // 检查数据
|
||||
if (ttData.elapse(20))
|
||||
{
|
||||
//appdata.initFromDB();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Application::runThreadStat()
|
||||
{
|
||||
int nCachePos = 0;
|
||||
@@ -125,6 +120,7 @@ void Application::runThreadStat()
|
||||
{
|
||||
nCachePos = n;
|
||||
std::string dt = Utils::dateStr(tDate);
|
||||
// // 设备历史数据(电压、电流、功率),存储到 history_day
|
||||
for (auto item: appdata.mapStation)
|
||||
{
|
||||
item.second->writeRuntimeData(dt, nCachePos);
|
||||
@@ -135,15 +131,12 @@ void Application::runThreadStat()
|
||||
//spdlog::info("保存历史数据倒计时: {}", 600 - offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 统计计算,存储到 stat_station
|
||||
for (auto& station : appdata.mapStation)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user