1
0
moha/topics_callbacks/linky2mqtt.php

38 lines
1.2 KiB
PHP

<?php
//TODO to test and debug
$topics["linky2mqtt"] = new topic;
$devices["linky2mqtt"] = array();
$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"), $topicName, $fn), __FILE__ . ":" . __LINE__);
$payloadArray = json_decode($message->payload, true);
if (!array_key_exists($fn, $device))
{
echo "initializing $fn";
$device[$fn] = array("device" => new device);
$device = &$device[$fn];
$device["device"]->friendlyName = $payloadArray["friendly_name"];
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
$device["device"]->type = $payloadArray["type"];
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
}else
{
$device = &$device[$fn];
}
unset($payloadArray["friendly_name"]);
unset($payloadArray["ieeeAddress"]);
unset($payloadArray["type"]);
//$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
//print_r($device["device"]);
}
?>