|
@ -706,11 +706,23 @@ class RestApi { |
|
|
obj[F("last_id")] = iv->getChannelFieldValue(CH0, FLD_EVT, rec); |
|
|
obj[F("last_id")] = iv->getChannelFieldValue(CH0, FLD_EVT, rec); |
|
|
|
|
|
|
|
|
JsonArray alarm = obj.createNestedArray(F("alarm")); |
|
|
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++) { |
|
|
|
|
|
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++) { |
|
|
for(uint8_t i = 0; i < 10; i++) { |
|
|
alarm[i][F("code")] = iv->lastAlarm[i].code; |
|
|
uint8_t pos = (i + offset) % 10; |
|
|
alarm[i][F("str")] = iv->getAlarmStr(iv->lastAlarm[i].code); |
|
|
alarm[pos][F("code")] = iv->lastAlarm[pos].code; |
|
|
alarm[i][F("start")] = iv->lastAlarm[i].start; |
|
|
alarm[pos][F("str")] = iv->getAlarmStr(iv->lastAlarm[pos].code); |
|
|
alarm[i][F("end")] = iv->lastAlarm[i].end; |
|
|
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 */ |
|
|
#endif /* !defined(ETHERNET */ |
|
|
else if(F("save_iv") == jsonIn[F("cmd")]) { |
|
|
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->enabled = jsonIn[F("en")]; |
|
|
iv->config->serial.u64 = jsonIn[F("ser")]; |
|
|
iv->config->serial.u64 = jsonIn[F("ser")]; |
|
|
snprintf(iv->config->name, MAX_NAME_LENGTH, "%s", jsonIn[F("name")].as<const char*>()); |
|
|
snprintf(iv->config->name, MAX_NAME_LENGTH, "%s", jsonIn[F("name")].as<const char*>()); |
|
@ -1207,19 +1231,18 @@ class RestApi { |
|
|
|
|
|
|
|
|
// pm_src
|
|
|
// pm_src
|
|
|
const char *neu = jsonIn[F("pm_src")].as<const char*>(); |
|
|
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
|
|
|
// unsubscribe
|
|
|
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) |
|
|
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
|
|
|
// save
|
|
|
snprintf(mConfig->plugin.zeroExport.groups[group].pm_src, ZEROEXPORT_GROUP_MAX_LEN_PM_SRC, "%s", jsonIn[F("pm_src")].as<const char*>()); |
|
|
snprintf(mConfig->plugin.zeroExport.groups[group].pm_src, ZEROEXPORT_GROUP_MAX_LEN_PM_SRC, "%s", jsonIn[F("pm_src")].as<const char*>()); |
|
|
// subsrcribe
|
|
|
// subsrcribe
|
|
|
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) |
|
|
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 || |
|
|
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttSoC || |
|
|
mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttU ) |
|
|
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
|
|
|
// save
|
|
@ -1261,7 +1284,7 @@ class RestApi { |
|
|
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttSoC || |
|
|
if(mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttSoC || |
|
|
mConfig->plugin.zeroExport.groups[group].pm_type == zeroExportBatteryCfg::mqttU) |
|
|
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); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|