Skip to content

Commit

Permalink
main.cpp, network.cpp: prevent excessive MQTT publication of ESPUptim…
Browse files Browse the repository at this point in the history
…e and WiFiRSSI
  • Loading branch information
dingo35 committed Nov 2, 2024
1 parent 5892adc commit 057e7aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 0 additions & 2 deletions SmartEVSE-3/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,6 @@ void mqttPublishData() {
MQTTclient.publish(MQTTprefix + "/EVCurrentL2", EVMeter.Irms[1], false, 0);
MQTTclient.publish(MQTTprefix + "/EVCurrentL3", EVMeter.Irms[2], false, 0);
}
MQTTclient.publish(MQTTprefix + "/ESPUptime", esp_timer_get_time() / 1000000, false, 0);
MQTTclient.publish(MQTTprefix + "/ESPTemp", TempEVSE, false, 0);
MQTTclient.publish(MQTTprefix + "/Mode", Access_bit == 0 ? "Off" : Mode > 3 ? "N/A" : StrMode[Mode], true, 0);
MQTTclient.publish(MQTTprefix + "/MaxCurrent", MaxCurrent * 10, true, 0);
Expand All @@ -3224,7 +3223,6 @@ void mqttPublishData() {
MQTTclient.publish(MQTTprefix + "/EVPlugState", (pilot != PILOT_12V) ? "Connected" : "Disconnected", true, 0);
MQTTclient.publish(MQTTprefix + "/WiFiSSID", String(WiFi.SSID()), true, 0);
MQTTclient.publish(MQTTprefix + "/WiFiBSSID", String(WiFi.BSSIDstr()), true, 0);
MQTTclient.publish(MQTTprefix + "/WiFiRSSI", String(WiFi.RSSI()), false, 0);
#if MODEM
MQTTclient.publish(MQTTprefix + "/CPPWM", CurrentPWM, false, 0);
MQTTclient.publish(MQTTprefix + "/CPPWMOverride", CPDutyOverride ? String(CurrentPWM) : "-1", true, 0);
Expand Down
9 changes: 7 additions & 2 deletions SmartEVSE-3/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,21 @@ void WiFiSetup(void) {
// called by loop() in the main program
void network_loop() {
static unsigned long lastCheck_net = 0;
static int seconds = 0;
if (millis() - lastCheck_net >= 1000) {
lastCheck_net = millis();
//this block is for non-time critical stuff that needs to run approx 1 / second
getLocalTime(&timeinfo, 1000U);
if (!LocalTimeSet && WIFImode == 1) {
_LOG_A("Time not synced with NTP yet.\n");
}
//this block is for non-time critical stuff that needs to run approx 1 / 10 seconds
#if MQTT
MQTTclient.publish(MQTTprefix + "/ESPUptime", esp_timer_get_time() / 1000000, false, 0);
MQTTclient.publish(MQTTprefix + "/WiFiRSSI", String(WiFi.RSSI()), false, 0);
if (seconds++ >= 9) {
seconds = 0;
MQTTclient.publish(MQTTprefix + "/ESPUptime", esp_timer_get_time() / 1000000, false, 0);
MQTTclient.publish(MQTTprefix + "/WiFiRSSI", String(WiFi.RSSI()), false, 0);
}
#endif
}

Expand Down

0 comments on commit 057e7aa

Please sign in to comment.