diff --git a/src/globalConfig.cpp b/src/globalConfig.cpp index 8776862..5c433ed 100644 --- a/src/globalConfig.cpp +++ b/src/globalConfig.cpp @@ -27,6 +27,7 @@ uint16_t cfgMqttPort; // Port of MQTT broker (optional) char cfgMqttUser[32]; // MQTT: Username char cfgMqttPass[32]; // MQTT: Password uint8_t cfgMqttLp[WB_CNT]; // Array with assignments to openWB loadpoints, e.g. [4,2,0,1]: Box0 = LP4, Box1 = LP2, Box2 = no MQTT, Box3 = LP1 +char cfgMqttWattTopic[60]; // MQTT: Topic for setting the watt value for PV charging, default: "wbec/pv/setWatt" char cfgNtpServer[30]; // NTP server char cfgFoxUser[32]; // powerfox: Username char cfgFoxPass[16]; // powerfox: Password @@ -134,6 +135,7 @@ void loadConfig() { cfgMqttPort = doc["cfgMqttPort"] | 1883UL; strncpy(cfgMqttUser, doc["cfgMqttUser"] | "", sizeof(cfgMqttUser)); strncpy(cfgMqttPass, doc["cfgMqttPass"] | "", sizeof(cfgMqttPass)); + strncpy(cfgMqttWattTopic, doc["cfgMqttWattTopic"] | "wbec/pv/setWatt", sizeof(cfgMqttWattTopic)); strncpy(cfgNtpServer, doc["cfgNtpServer"] | "europe.pool.ntp.org", sizeof(cfgNtpServer)); strncpy(cfgFoxUser, doc["cfgFoxUser"] | "", sizeof(cfgFoxUser)); strncpy(cfgFoxPass, doc["cfgFoxPass"] | "", sizeof(cfgFoxPass)); diff --git a/src/globalConfig.h b/src/globalConfig.h index ce1df5f..de695aa 100644 --- a/src/globalConfig.h +++ b/src/globalConfig.h @@ -38,6 +38,7 @@ extern uint16_t cfgMqttPort; // Port of MQTT broker (optional) extern char cfgMqttUser[32]; // MQTT: Username extern char cfgMqttPass[32]; // MQTT: Password extern uint8_t cfgMqttLp[WB_CNT]; // Array with assignments to openWB loadpoints, e.g. [4,2,0,1]: Box0 = LP4, Box1 = LP2, Box2 = no MQTT, Box3 = LP1 +extern char cfgMqttWattTopic[60]; // MQTT: Topic for setting the watt value for PV charging, default: "wbec/pv/setWatt" extern char cfgNtpServer[30]; // NTP server extern char cfgFoxUser[32]; // powerfox: Username extern char cfgFoxPass[16]; // powerfox: Password diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 99b7040..aa0d942 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -92,6 +92,12 @@ void callback(char* topic, byte* payload, uint8_t length) LOG(0, ", no box assigned", ""); } } + + // set the watt value via MQTT (#54) + if (strcmp(topic, cfgMqttWattTopic) == 0) { + pv_setWatt(atol(buffer)); + } + callbackActive = false; } @@ -134,6 +140,7 @@ void reconnect() { client.subscribe(topic); } } + client.subscribe(cfgMqttWattTopic); } else { LOG(m, "failed, rc=%d try again in 5 seconds", client.state()) }