@@ -50,6 +50,7 @@ char RequiredEVCCID[32] = ""; // R
5050#include " modbus.h"
5151#include " meter.h"
5252#include " evse_bridge.h"
53+ #include " solar_debug_json.h"
5354#include " mqtt_parser.h"
5455#include " mqtt_publish.h"
5556#include " http_api.h"
@@ -617,6 +618,8 @@ void writeMqttCaCert(const String& cert) {
617618}
618619
619620#if MQTT
621+ static void mqttSetSolarDebug (bool enabled); // forward declaration
622+
620623void mqtt_receive_callback (const String topic, const String payload) {
621624 mqtt_command_t cmd;
622625 if (!mqtt_parse_command (MQTTprefix.c_str (), topic.c_str (), payload.c_str (), &cmd))
@@ -798,6 +801,10 @@ void mqtt_receive_callback(const String topic, const String payload) {
798801 request_write_settings ();
799802 break ;
800803
804+ case MQTT_CMD_SOLAR_DEBUG:
805+ mqttSetSolarDebug (cmd.solar_debug );
806+ break ;
807+
801808 default :
802809 return ;
803810 }
@@ -1292,6 +1299,36 @@ void mqttSmartEVSEPublishData() {
12921299 MQTTclientSmartEVSE.publish (MQTTSmartEVSEprefix + " /PairingPin" , PairingPin, true , 0 );
12931300 MQTTclientSmartEVSE.publish (MQTTSmartEVSEprefix + " /MaxCurrent" , String (MaxCurrent * 10 ), true , 0 );
12941301}
1302+
1303+ // Solar debug MQTT publishing (Issue #66)
1304+ // Gated behind SolarDebugEnabled flag — only publishes when enabled.
1305+ // Rate-limited: publishes at most once every SOLAR_DEBUG_INTERVAL_MS.
1306+ static bool SolarDebugEnabled = false ;
1307+ static unsigned long SolarDebugLastPublish = 0 ;
1308+ #define SOLAR_DEBUG_INTERVAL_MS 5000
1309+
1310+ void mqttPublishSolarDebug (void ) {
1311+ if (!SolarDebugEnabled) return ;
1312+ if (!MQTTclient.connected ) return ;
1313+
1314+ unsigned long now = millis ();
1315+ if (SolarDebugLastPublish != 0 && (now - SolarDebugLastPublish) < SOLAR_DEBUG_INTERVAL_MS)
1316+ return ;
1317+
1318+ evse_solar_debug_t snap;
1319+ evse_get_solar_debug (&snap);
1320+
1321+ char json[384 ];
1322+ if (solar_debug_to_json (&snap, json, sizeof (json)) > 0 ) {
1323+ MQTTclient.publish (MQTTprefix + " /Debug/Solar" , json, false , 0 );
1324+ SolarDebugLastPublish = now;
1325+ }
1326+ }
1327+
1328+ static void mqttSetSolarDebug (bool enabled) {
1329+ SolarDebugEnabled = enabled;
1330+ if (!enabled) SolarDebugLastPublish = 0 ;
1331+ }
12951332#endif
12961333
12971334
0 commit comments