2022-01-08 11:51:50 +01:00
|
|
|
<?php
|
2022-01-08 23:45:38 +01:00
|
|
|
$topics["pws2mqtt"] = new topic;
|
2022-02-23 10:23:16 +01:00
|
|
|
$devices["pws2mqtt"] = array();
|
|
|
|
|
2022-01-08 11:51:50 +01:00
|
|
|
|
2022-01-08 23:45:38 +01:00
|
|
|
$topics["pws2mqtt"]->callback = function($topic, $message)
|
2022-01-08 11:51:50 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
global $logFh, $devices, $included;
|
|
|
|
$topicName = $topic[0];
|
|
|
|
$fn = $topic[1];
|
|
|
|
logger(INFO, sprintf(_("Incoming notification of device %s => friendly name : %s"), $topicName, $fn), __FILE__ . ":" . __LINE__);
|
|
|
|
$device = & $devices[$topicName];
|
|
|
|
$payloadArray = json_decode($message->payload, true);
|
|
|
|
// friendlyname
|
|
|
|
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"];
|
|
|
|
$device["device"]->topic = $topicName;
|
|
|
|
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
|
|
|
$indexFriendlyNames[$fn] = & $device["device"];
|
2022-01-27 18:41:16 +01:00
|
|
|
|
2022-02-23 10:23:16 +01:00
|
|
|
}else
|
2022-01-08 23:45:38 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device = &$device[$fn];
|
2022-01-08 23:45:38 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
unset($payloadArray["friendly_name"]);
|
|
|
|
unset($payloadArray["ieeeAddress"]);
|
|
|
|
unset($payloadArray["type"]);
|
|
|
|
|
2022-01-27 18:41:16 +01:00
|
|
|
foreach ($payloadArray as $property => $value)
|
|
|
|
{
|
|
|
|
$str = substr($property, -1);
|
|
|
|
if ($str == "f")
|
|
|
|
{
|
|
|
|
$newProperty = rtrim($property, "f") . "c";
|
2022-02-23 10:23:16 +01:00
|
|
|
$payloadArray[$newProperty] = farenheit2celsius($value);
|
2022-01-27 18:41:16 +01:00
|
|
|
}elseif ($str == "h")
|
|
|
|
{
|
|
|
|
$newProperty = substr($property, 0, -3) . "kmh";
|
2022-02-23 10:23:16 +01:00
|
|
|
$payloadArray[$newProperty] = mph2kmh($value);
|
2022-01-27 18:41:16 +01:00
|
|
|
}
|
|
|
|
if ($property == "baromin")
|
|
|
|
{
|
|
|
|
$newProperty = "barominmb";
|
2022-02-23 10:23:16 +01:00
|
|
|
$payloadArray["barominmb"] = millibars($value);
|
2022-01-27 18:41:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
//$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
|
|
|
|
changeDevice($topicName, $fn, $device["device"], $payloadArray);
|
2022-01-08 11:51:50 +01:00
|
|
|
}
|
|
|
|
?>
|