Browse Source

Improve MQTT Power Limit Handling

pull/157/head^2
Andreas Schiffler 2 years ago
parent
commit
16d348dc0b
  1. 33
      tools/esp8266/app.cpp
  2. 8
      tools/esp8266/defines.h

33
tools/esp8266/app.cpp

@ -432,7 +432,6 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
if (std::strcmp(token,"devcontrol")==0){
token = strtok(NULL, "/");
uint8_t iv_id = std::stoi(token);
uint8_t powerLimitControl = 0;
if (iv_id >= 0 && iv_id <= MAX_NUM_INVERTERS){
Inverter<> *iv = this->mSys->getInverterByPos(iv_id);
if(NULL != iv) {
@ -442,24 +441,24 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
case ActivePowerContr: // Active Power Control
token = strtok(NULL, "/"); // get ControlMode aka "PowerPF.Desc" in DTU-Pro Code from topic string
if (token == NULL) // default via mqtt ommit the LimitControlMode
powerLimitControl = AbsolutNonPersistent;
iv->powerLimit[1] = AbsolutNonPersistent;
else
powerLimitControl = std::stoi(token);
// 0x0001 -> relativ limit in percent
// 0x0000 -> absolut limit in Watt
// 0x0101 -> persisten limit in percent (?)
// ...
if (true){ // if (std::stoi((char*)payload) > 0) error handling powerlimit needed?
iv->devControlCmd = ActivePowerContr;
iv->powerLimit[0] = std::stoi((char*)payload);
if (powerLimitControl >= AbsolutNonPersistent && powerLimitControl <= RelativNonPersistent)
iv->powerLimit[1] = powerLimitControl;
if (iv->powerLimit[1] & 0x0001)
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("%") );
else
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("W") );
iv->powerLimit[1] = std::stoi(token);
DPRINTLN(DBG_VERBOSE, F("iv->powerLimit[1]=") + String(iv->powerLimit[1]));
DPRINTLN(DBG_VERBOSE, F("length=") + String(length));
if (length<=5){ // if (std::stoi((char*)payload) > 0) more error handling powerlimit needed?
if (iv->powerLimit[1] >= AbsolutNonPersistent && iv->powerLimit[1] <= RelativPersistent){
iv->devControlCmd = ActivePowerContr;
iv->powerLimit[0] = std::stoi((char*)payload);
if (iv->powerLimit[1] & 0x0001)
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("%") );
else
DPRINTLN(DBG_INFO, F("Power limit for inverter ") + String(iv->id) + F(" set to ") + String(iv->powerLimit[0]) + F("W") );
}
iv->devControlRequest = true;
} else {
DPRINTLN(DBG_INFO, F("Invalid mqtt payload recevied: ") + String((char*)payload));
}
iv->devControlRequest = true;
break;
case TurnOn: // Turn On
iv->devControlCmd = TurnOn;

8
tools/esp8266/defines.h

@ -58,10 +58,10 @@ typedef enum {
} DevControlCmdType;
typedef enum { // ToDo: to be verified by field tests
AbsolutNonPersistent = 0x0000, // 0
RelativNonPersistent = 0x0001, // 1
AbsolutPersistent = 0x0100, // 256
RelativPersistent = 0x0101 // 257
AbsolutNonPersistent = 0UL, // 0x0000
RelativNonPersistent = 1UL, // 0x0001
AbsolutPersistent = 256UL, // 0x0100
RelativPersistent = 257UL // 0x0101
} PowerLimitControlType;
// minimum serial interval

Loading…
Cancel
Save