1
0
moha/topics_callbacks/pws2mqtt.php

24 lines
867 B
PHP
Raw Normal View History

<?php
2022-01-08 23:45:38 +01:00
$topics["pws2mqtt"] = new topic;
2022-01-08 23:45:38 +01:00
$topics["pws2mqtt"]->callback = function($topic, $message)
{
global $topics, $logFh, $devices, $included;
2022-01-17 00:18:50 +01:00
$fn = $topic[1]; // get friendlyname
2022-01-17 21:01:11 +01:00
logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topic[0], $topic[1]));
2022-01-08 23:45:38 +01:00
$device = & $devices[$topic[0]];
2022-01-17 00:18:50 +01:00
$payloadArray = json_decode($message->payload);
if (!isset($device[$fn])) //must not exists, but ...
2022-01-08 23:45:38 +01:00
{
2022-01-17 00:18:50 +01:00
logger(LOG_WARNING, $logFh, "init of " . $fn .EOL);
$device[$fn] = array();
$device[$fn]["device"] = new device;
$device[$fn]["device"]->type = $payloadArray->type;
$device[$fn]["device"]->ieeeAddress = $payloadArray->ieeeAddress;
2022-01-17 21:01:11 +01:00
$indexDevices[$device[$fn]["device"]->ieeeAddress] = & $device[$fn]["device"];
2022-01-08 23:45:38 +01:00
}
2022-01-17 00:18:50 +01:00
$device = & $device[$fn];
2022-01-08 23:45:38 +01:00
changeDevice($topic[0], $topic[1], $device["device"], $payloadArray);
}
?>