41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
//TODO to test and debug
|
|
var_dump($topics);
|
|
if (!array_key_exists("linky2mqtt", $topics)) $topics["linky2mqtt"] = new topic;
|
|
if (!array_key_exists("linky2mqtt", $devices)) $devices["linky2mqtt"] = array();
|
|
|
|
|
|
function linky2mqttCallback($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"];
|
|
mkIndexes();
|
|
}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"]);
|
|
}
|
|
$topics["linky2mqtt"]->callback = "linky2mqttCallback";
|
|
?>
|