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:
@@ -7,7 +7,7 @@
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Snowflake.h"
|
||||
#include "common/Spdlogger.h"
|
||||
|
||||
#include "protocol/MqttEntity.h"
|
||||
|
||||
void ElectPeriod::parse(std::string jsonstr)
|
||||
{
|
||||
@@ -217,6 +217,17 @@ void AppData::initFromDB()
|
||||
void AppData::init()
|
||||
{
|
||||
this->initFromDB();
|
||||
|
||||
auto& optionMqtt = Config::option.mqtt;
|
||||
if (!optionMqtt.host.empty())
|
||||
{
|
||||
for (auto& item : mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
// "tcp://localhost:1883"
|
||||
station->mqttCli->init(optionMqtt.host, station->code, optionMqtt.username, optionMqtt.password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Station> AppData::getStation(int stationId)
|
||||
@@ -245,6 +256,17 @@ std::shared_ptr<Station> AppData::getStationByName(std::string name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Station> AppData::getStationByCode(std::string code)
|
||||
{
|
||||
for (auto iter = mapStation.begin(); iter!=mapStation.end(); ++iter)
|
||||
{
|
||||
if (iter->second->code == code)
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> AppData::getDevice(int stationId, int deviceId)
|
||||
{
|
||||
@@ -423,4 +445,27 @@ std::string AppData::getElectPreiodVal(int month, int hour)
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void AppData::storeRuntimeDB()
|
||||
{
|
||||
auto t = Utils::date();
|
||||
|
||||
std::string valStr;
|
||||
for (auto iter=mapDataDay.begin(); iter!=mapDataDay.end(); ++iter)
|
||||
{
|
||||
auto& v = iter->second;
|
||||
if (v != 0.0)
|
||||
{
|
||||
if (!valStr.empty()) valStr += ",";
|
||||
valStr += ("[" + std::to_string(iter->first) + "," + Utils::toStr(v, 2) + "]");
|
||||
}
|
||||
}
|
||||
valStr = "[" + valStr + "]";
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(t));
|
||||
fields.set("device_id", 1);
|
||||
fields.set("datatype", 1);
|
||||
fields.set("value", valStr);
|
||||
DAO::insertRuntimeData(NULL, fields);
|
||||
}
|
||||
Reference in New Issue
Block a user