1
0
moha/topics_callbacks/linky2mqtt.php

34 lines
1.0 KiB
PHP
Raw Normal View History

2022-01-17 00:18:50 +01:00
<?php
//TODO to test and debug
$topics["linky2mqtt"] = new topic;
/*$devices["linky2mqtt"]["linky"]["device"] = new device;
$device = &$devices["linky2mqtt"]["linky"]["device"];
*/
$topics["linky2mqtt"]->callback = function($topic, $message)
{
global $topics, $logFh, $devices, $included;
$topicName = $topic[0];
$friendlyName = $topic[1]; // get friendlyName
logger(INFO, sprintf(_("Icoming notification of device %s"), $topic[0], $topic[1]));
$device = & $devices[$topic[0]];
$payloadArray = json_decode($message->payload);
//print_r($payloadArray);
//print_r($device) ;
if (!isset($device[$fn])) //must not exists, but ...
{
logger(LOG_WARNING, $logFh, "init of " . $fn .EOL);
$device[$fn] = array();
$device[$fn]["device"] = new device;
$device[$fn]["device"]->type = "mesure";
$device[$fn]["device"]->ieeeAddress = $payloadArray["ADSC"];
//addDevice($device[$fn], $fn, );
}
$device = & $device[$fn];
//print_r($device);
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
print_r($device["device"]);
}
?>