1
0
moha/topics_callbacks/linky2mqtt.php

43 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2022-01-17 00:18:50 +01:00
<?php
//TODO to test and debug
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
function linky2mqttCallback($topic, $message)
2022-01-17 00:18:50 +01:00
{
global $topics, $logFh, $devices, $included;
$topicName = $topic[0];
$topics[$topicName]->lastSeen = time();
2022-01-17 00:18:50 +01:00
$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"];
//$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
}
$topics["linky2mqtt"]->callback = "linky2mqttCallback";
$topics["linky2mqtt"]->timeOut = 3; // timeOut in minutes
$topics["linky2mqtt"]->lastSeen = time();
2022-01-17 00:18:50 +01:00
?>