1
0
moha/topics_callbacks/linky2mqtt.php

27 lines
927 B
PHP

<?php
//TODO to test and debug
$topics["linky2mqtt"] = new topic;
$topics["linky2mqtt"]->callback = function($topic, $message)
{
global $topics, $logFh, $devices, $included;
$topicName = $topic[0];
$friendlyName = $topic[1]; // get friendlyName
logger(INFO, sprintf(_("Incoming notification of device %s"), $topic[0], $topic[1]));
$device = & $devices[$topic[0]];
$payloadArray = json_decode($message->payload);
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"];
$indexDevices[$device[$fn]["device"]->ieeeAddress] = & $device[$fn]["device"];
}
$device = & $device[$fn];
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
print_r($device["device"]);
}
?>