1
0
moha/utils.php

92 lines
1.5 KiB
PHP
Raw Normal View History

2021-12-30 16:18:32 +01:00
<?php
2022-01-28 23:05:58 +01:00
logger(DEBUG, _("Including utils.php"), __FILE__ . ":" . __LINE__);
2021-12-30 16:18:32 +01:00
2022-01-19 00:22:34 +01:00
function bool2string($var)
{
if ($var === false)
{
return "false";
}elseif($var === true)
{
return "true";
}else
{
return $var;
}
}
2021-12-30 16:18:32 +01:00
function now()
{
2022-01-20 00:26:57 +01:00
$now = new datetime();
return $now;
2021-12-30 16:18:32 +01:00
}
2022-01-17 00:18:50 +01:00
function farenheit2celsius($value)
{
return round((((float)$value - 32) / 1.8),2);
}
function mph2kmh($value)
{
return round(((float)$value * 1.60934),2);
2022-01-17 00:18:50 +01:00
}
function millibars($value)
{
return round(((float)$value * 33.86),2);
}
function mktopic($device)
{
return $device->topic . "/" . $device->friendlyName;
}
2021-12-30 16:18:32 +01:00
2022-01-30 00:21:50 +01:00
function getDevice($topic, $fn)
{
global $topics, $devices;
if (array_key_exists($topic, $topics))
{
$var = $devices[$topic];
$path = explode("/", $fn);
foreach($path as $tmp)
{
if (array_key_exists($tmp, $var))
{
$var = $var[$tmp];
}else
{
return false;
}
}
return $var;
}else
{
return false;
}
}
2022-01-29 19:58:01 +01:00
function getValue($ieeeAddress, $property)
2022-01-28 23:05:58 +01:00
{
global $indexDevices;
2022-01-29 19:58:01 +01:00
return $indexDevices[$ieeeAddress]->$property["value"];
2022-01-28 23:05:58 +01:00
}
function setValue($fn, $property, $value)
{
global $indexDevices;
$indexDevices(RDC_SALON_MVMT2)->occupancy["value"] = $value;
}
logger(DEBUG, _("signal handling"), __FILE__ . ":" . __LINE__, false);
//signal handling
function signalHandler($signal)
{
endMoha();
}
pcntl_signal(SIGTERM, 'signalHandler');// Termination ('kill' was called)
pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
pcntl_signal(SIGINT, 'signalHandler');
2021-12-30 16:18:32 +01:00
?>