Skip to content

Commit

Permalink
Add cfgMqttWattTopic for setting the watt value via MQTT (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
steff393 committed Feb 11, 2023
1 parent 5c46f52 commit d99c2ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/globalConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/globalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit d99c2ec

Please sign in to comment.