mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-28 17:56:21 +02:00
0.8.1290001
0.8.1290001 Merge pull request #1703 from tictrick/zero-export
This commit is contained in:
commit
67ac3d6564
8 changed files with 56 additions and 28 deletions
|
@ -1,8 +1,13 @@
|
|||
# Development Changes
|
||||
|
||||
## 0.8.129 - 2024-07-11
|
||||
* sort alarms ascending #1471
|
||||
* fix alarm counter for first alarm
|
||||
* prevent add inverter multiple times #1700
|
||||
|
||||
## 0.8.128 - 2024-07-10
|
||||
* add environments for 16MB flash size ESP32-S3 aka opendtufusion
|
||||
* prevent duplicate alarms, update end time once it is received
|
||||
* prevent duplicate alarms, update end time once it is received #1471
|
||||
|
||||
## 0.8.127 - 2024-06-21
|
||||
* add grid file #1677
|
||||
|
|
|
@ -831,10 +831,10 @@ void app::updateLed(void) {
|
|||
|
||||
|
||||
|
||||
void app::subscribe(const char *subTopic, uint8_t qos) {
|
||||
mMqtt.subscribe(subTopic, qos);
|
||||
void app::subscribeExtern(const char *subTopic, uint8_t qos) {
|
||||
mMqtt.subscribeExtern(subTopic, qos);
|
||||
}
|
||||
|
||||
void app::unsubscribe(const char *subTopic) {
|
||||
mMqtt.unsubscribe(subTopic);
|
||||
void app::unsubscribeExtern(const char *subTopic) {
|
||||
mMqtt.unsubscribeExtern(subTopic);
|
||||
}
|
|
@ -360,8 +360,8 @@ class app : public IApp, public ah::Scheduler {
|
|||
}
|
||||
#endif
|
||||
|
||||
void subscribe(const char *subTopic, uint8_t qos = QOS_0);
|
||||
void unsubscribe(const char *subTopic);
|
||||
void subscribeExtern(const char *subTopic, uint8_t qos = QOS_0);
|
||||
void unsubscribeExtern(const char *subTopic);
|
||||
|
||||
private:
|
||||
#define CHECK_AVAIL true
|
||||
|
|
|
@ -74,8 +74,8 @@ class IApp {
|
|||
#endif
|
||||
virtual void* getRadioObj(bool nrf) = 0;
|
||||
|
||||
virtual void subscribe(const char *subTopic, uint8_t qos) = 0;
|
||||
virtual void unsubscribe(const char *subTopic) = 0;
|
||||
virtual void subscribeExtern(const char *subTopic, uint8_t qos) = 0;
|
||||
virtual void unsubscribeExtern(const char *subTopic) = 0;
|
||||
};
|
||||
|
||||
#endif /*__IAPP_H__*/
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//-------------------------------------
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 8
|
||||
#define VERSION_PATCH 1280001
|
||||
#define VERSION_PATCH 1290001
|
||||
//-------------------------------------
|
||||
typedef struct {
|
||||
uint8_t ch;
|
||||
|
|
|
@ -834,7 +834,7 @@ class Inverter {
|
|||
}
|
||||
}
|
||||
|
||||
if(alarmCnt < 10 && alarmCnt < mAlarmNxtWrPos)
|
||||
if(alarmCnt < 10 && alarmCnt <= mAlarmNxtWrPos)
|
||||
alarmCnt = mAlarmNxtWrPos + 1;
|
||||
|
||||
lastAlarm[mAlarmNxtWrPos] = alarm_t(code, start, end);
|
||||
|
|
|
@ -251,18 +251,18 @@ class PubMqtt {
|
|||
mClient.subscribe(topic, qos);
|
||||
}
|
||||
|
||||
// new - need to unsubscribe the topics.
|
||||
void unsubscribe(const char *subTopic)
|
||||
{
|
||||
mClient.unsubscribe(subTopic); // add as many topics as you like
|
||||
}
|
||||
|
||||
void subscribeExtern(const char *subTopic, uint8_t qos = QOS_0) {
|
||||
char topic[MQTT_TOPIC_LEN + 20];
|
||||
snprintf(topic, (MQTT_TOPIC_LEN + 20), "%s", subTopic);
|
||||
mClient.subscribe(topic, qos);
|
||||
}
|
||||
|
||||
// new - need to unsubscribe the topics.
|
||||
void unsubscribeExtern(const char *subTopic)
|
||||
{
|
||||
mClient.unsubscribe(subTopic); // add as many topics as you like
|
||||
}
|
||||
|
||||
void setConnectionCb(connectionCb cb) {
|
||||
mConnectionCb = cb;
|
||||
}
|
||||
|
|
|
@ -706,11 +706,23 @@ class RestApi {
|
|||
obj[F("last_id")] = iv->getChannelFieldValue(CH0, FLD_EVT, rec);
|
||||
|
||||
JsonArray alarm = obj.createNestedArray(F("alarm"));
|
||||
|
||||
// find oldest alarm
|
||||
uint8_t offset = 0;
|
||||
uint32_t oldestStart = 0xffffffff;
|
||||
for(uint8_t i = 0; i < 10; i++) {
|
||||
alarm[i][F("code")] = iv->lastAlarm[i].code;
|
||||
alarm[i][F("str")] = iv->getAlarmStr(iv->lastAlarm[i].code);
|
||||
alarm[i][F("start")] = iv->lastAlarm[i].start;
|
||||
alarm[i][F("end")] = iv->lastAlarm[i].end;
|
||||
if((iv->lastAlarm[i].start != 0) && (iv->lastAlarm[i].start < oldestStart)) {
|
||||
offset = i;
|
||||
oldestStart = iv->lastAlarm[i].start;
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < 10; i++) {
|
||||
uint8_t pos = (i + offset) % 10;
|
||||
alarm[pos][F("code")] = iv->lastAlarm[pos].code;
|
||||
alarm[pos][F("str")] = iv->getAlarmStr(iv->lastAlarm[pos].code);
|
||||
alarm[pos][F("start")] = iv->lastAlarm[pos].start;
|
||||
alarm[pos][F("end")] = iv->lastAlarm[pos].end;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1173,7 +1185,19 @@ class RestApi {
|
|||
}
|
||||
#endif /* !defined(ETHERNET */
|
||||
else if(F("save_iv") == jsonIn[F("cmd")]) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")], false);
|
||||
Inverter<> *iv;
|
||||
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
||||
iv = mSys->getInverterByPos(jsonIn[F("id")], true);
|
||||
if(nullptr != iv) {
|
||||
if((i != jsonIn[F("id")]) && (iv->config->serial.u64 == jsonIn[F("ser")])) {
|
||||
jsonOut[F("error")] = F("ERR_DUPLICATE_INVERTER");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iv = mSys->getInverterByPos(jsonIn[F("id")], false);
|
||||
iv->config->enabled = jsonIn[F("en")];
|
||||
iv->config->serial.u64 = jsonIn[F("ser")];
|
||||
snprintf(iv->config->name, MAX_NAME_LENGTH, "%s", jsonIn[F("name")].as<const char*>());
|
||||
|
@ -1207,19 +1231,18 @@ class RestApi {
|
|||
|
||||
// pm_src
|
||||
const char *neu = jsonIn[F("pm_src")].as<const char*>();
|
||||
if (strncmp(mConfig->plugin.zeroExport.groups[group].pm_src, neu, strlen(neu)) != 0) {
|
||||
if (strcmp(mConfig->plugin.zeroExport.groups[group].pm_src, neu) != 0) {
|
||||
// unsubscribe
|
||||
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportPowermeterType_t::Mqtt)
|
||||
{
|
||||
mApp->unsubscribe(mConfig->plugin.zeroExport.groups[group].pm_src);
|
||||
|
||||
mApp->unsubscribeExtern(mConfig->plugin.zeroExport.groups[group].pm_src);
|
||||
}
|
||||
// save
|
||||
snprintf(mConfig->plugin.zeroExport.groups[group].pm_src, ZEROEXPORT_GROUP_MAX_LEN_PM_SRC, "%s", jsonIn[F("pm_src")].as<const char*>());
|
||||
// subsrcribe
|
||||
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportPowermeterType_t::Mqtt)
|
||||
{
|
||||
mApp->subscribe(mConfig->plugin.zeroExport.groups[group].pm_src, QOS_2);
|
||||
mApp->subscribeExtern(mConfig->plugin.zeroExport.groups[group].pm_src, QOS_2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1252,7 +1275,7 @@ class RestApi {
|
|||
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttSoC ||
|
||||
mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttU )
|
||||
{
|
||||
mApp->unsubscribe(mConfig->plugin.zeroExport.groups[group].battTopic);
|
||||
mApp->unsubscribeExtern(mConfig->plugin.zeroExport.groups[group].battTopic);
|
||||
|
||||
}
|
||||
// save
|
||||
|
@ -1261,7 +1284,7 @@ class RestApi {
|
|||
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttSoC ||
|
||||
mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttU)
|
||||
{
|
||||
mApp->subscribe(mConfig->plugin.zeroExport.groups[group].battTopic, QOS_2);
|
||||
mApp->subscribeExtern(mConfig->plugin.zeroExport.groups[group].battTopic, QOS_2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue