实现MQTT功能, 修改HTTP接口

This commit is contained in:
lixiaoyuan
2025-09-04 19:31:04 +08:00
parent 61ed4f355f
commit d81bcd9983
30 changed files with 2029 additions and 697 deletions

View File

@@ -4,10 +4,30 @@
#include "common/fields.h"
#include "app/Device.h"
#include "common/Spdlogger.h"
#include "common/Utils.h"
#include "protocol/MqttEntity.h"
Station::Station() : id(0)
{
mqttCli = std::make_shared<MqttClient>();
// 测试,设置默认值
for (int i = 1; i<=5; i++) { mapTempHumUnit[i] = TempHumUnit(Utils::random(20, 40), Utils::random(20, 80)); }
for (int i = 1; i<=5; i++) { mapFire40Unit[i] = 0; }
for (int i = 1; i<=5; i++) {
auto& unit = mapCoolingUnit[i];
unit.powerOn = 1;
unit.mode = i%2;
}
for (int i = 1; i<=5; i++) {
auto& unit = mapAircUnit[i];
unit.powerOn = 1;
unit.temp = Utils::random(20, 40);
unit.hum = Utils::random(20, 80);
}
}
void Station::setFields(Fields& fields)
@@ -15,7 +35,8 @@ void Station::setFields(Fields& fields)
this->id = fields.get<int>(DMStation::STATION_ID);
this->name = fields.value(DMStation::NAME);
this->energyCapacity = fields.get<double>(DMStation::CAPACITY);
this->workModeId = fields.get<int>(DMStation::WORK_MODE_ID);
this->workModeId = fields.get<int>(DMStation::WORK_MODE);
this->code = fields.value(DMStation::CODE);
}
void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
@@ -67,7 +88,7 @@ void Station::setWorkMode(int modeId)
{
this->workModeId = modeId;
std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME)
.update(DMStation::WORK_MODE_ID, std::to_string(modeId))
.update(DMStation::WORK_MODE, std::to_string(modeId))
.where(DMStation::STATION_ID + "=" + std::to_string(id)).str();
Errcode err = DAO::exec(NULL, sql);
if (err != Errcode::OK)