write debug to log and mqtt

master
Dirk Heilig 2024-09-23 14:10:12 +02:00
parent 55989ff7f6
commit ea74c28060
1 changed files with 6 additions and 1 deletions

View File

@ -64,6 +64,7 @@ $mqtt->onMessage(function ($message) use (
&$news, &$news,
&$globalCounter, &$globalCounter,
&$isRunning, &$isRunning,
&$mqtt,
$mqttTopic $mqttTopic
) { ) {
if ($mqttTopic . "/restart" === $message->topic) { if ($mqttTopic . "/restart" === $message->topic) {
@ -71,7 +72,7 @@ $mqtt->onMessage(function ($message) use (
return; return;
} }
if ($mqttTopic . "/debug" === $message->topic) { if ($mqttTopic . "/debug" === $message->topic) {
logit( $debug = strval(
json_encode( json_encode(
$data, $data,
JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_SLASHES +
@ -79,6 +80,9 @@ $mqtt->onMessage(function ($message) use (
JSON_PRETTY_PRINT JSON_PRETTY_PRINT
) )
); );
logit($debug);
$mqtt->publish($mqttTopic . "/debugmsg", $debug, 2);
return; return;
} }
$globalCounter++; $globalCounter++;
@ -104,6 +108,7 @@ $mqtt->onMessage(function ($message) use (
logit("Subscribing to $mqttTopic with QoS $qos "); logit("Subscribing to $mqttTopic with QoS $qos ");
$mqtt->subscribe($mqttTopic, $qos); $mqtt->subscribe($mqttTopic, $qos);
$mqtt->subscribe($mqttTopic . "/restart", $qos); $mqtt->subscribe($mqttTopic . "/restart", $qos);
$mqtt->subscribe($mqttTopic . "/debug", $qos);
logit("Subscribed"); logit("Subscribed");
$timer = 0; $timer = 0;