2022-01-17 00:18:50 +01:00
|
|
|
<?php
|
|
|
|
//TODO to test and debug
|
2022-03-13 22:33:26 +01:00
|
|
|
if (!array_key_exists("linky2mqtt", $topics)) $topics["linky2mqtt"] = new topic;
|
|
|
|
if (!array_key_exists("linky2mqtt", $devices)) $devices["linky2mqtt"] = array();
|
2022-02-23 10:23:16 +01:00
|
|
|
|
2022-01-17 00:18:50 +01:00
|
|
|
|
2022-03-13 22:33:26 +01:00
|
|
|
function linky2mqttCallback($topic, $message)
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
|
|
|
global $topics, $logFh, $devices, $included;
|
|
|
|
$topicName = $topic[0];
|
|
|
|
$friendlyName = $topic[1]; // get friendlyName
|
2022-02-23 10:23:16 +01:00
|
|
|
logger(INFO, sprintf(_("Incoming notification of device %s"), $topicName, $fn), __FILE__ . ":" . __LINE__);
|
|
|
|
$payloadArray = json_decode($message->payload, true);
|
|
|
|
|
|
|
|
if (!array_key_exists($fn, $device))
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
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"];
|
2022-03-13 22:33:26 +01:00
|
|
|
//$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
|
|
|
//$indexFriendlyNames[$topicName][$fn] = & $device["device"];
|
|
|
|
mkIndexes();
|
2022-02-23 10:23:16 +01:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
$device = &$device[$fn];
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
unset($payloadArray["friendly_name"]);
|
|
|
|
unset($payloadArray["ieeeAddress"]);
|
|
|
|
unset($payloadArray["type"]);
|
|
|
|
|
|
|
|
//$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
|
2022-01-17 00:18:50 +01:00
|
|
|
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
|
2022-01-19 00:22:34 +01:00
|
|
|
//print_r($device["device"]);
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
2022-03-13 22:33:26 +01:00
|
|
|
$topics["linky2mqtt"]->callback = "linky2mqttCallback";
|
2022-01-17 00:18:50 +01:00
|
|
|
?>
|