1
0
moha/topics_callbacks/pws2mqtt.php

25 lines
878 B
PHP

<?php
$topics["pws2mqtt"] = new topic;
$topics["pws2mqtt"]->callback = function($topic, $message)
{
global $topics, $logFh, $devices, $included;
$fn = $topic[1]; // get friendlyname
logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topic[0], $topic[1]));
$device = & $devices[$topic[0]];
$payloadArray = json_decode($message->payload);
if (!isset($device[$fn]))
{
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;
$device[$fn]["device"]->friendlyname = $fn;
$indexDevices[$device[$fn]["device"]->ieeeAddress] = & $device[$fn]["device"];
}
$device = & $device[$fn];
changeDevice($topic[0], $fn, $device["device"], $payloadArray);
}
?>