2021-12-30 16:18:32 +01:00
|
|
|
<?php
|
2022-01-17 00:18:50 +01:00
|
|
|
logger(DEBUG,"Including utils.php");
|
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)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-01-17 00:18:50 +01:00
|
|
|
return ($value - 32 / 1.8);
|
|
|
|
}
|
|
|
|
|
|
|
|
function millibars($value)
|
|
|
|
{
|
|
|
|
return ($value * 0.029530);
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
|
|
|
|
2022-01-08 11:51:50 +01:00
|
|
|
function mktopic($device)
|
2022-01-02 13:47:41 +01:00
|
|
|
{
|
2022-01-08 11:51:50 +01:00
|
|
|
return $device->topic . "/" . $device->friendlyName;
|
2022-01-02 13:47:41 +01:00
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
|
2022-01-08 11:51:50 +01:00
|
|
|
logger(DEBUG, _("signal handling"), false);
|
|
|
|
//signal handling
|
|
|
|
function signalHandler($signal)
|
2022-01-03 21:11:52 +01:00
|
|
|
{
|
2022-01-08 11:51:50 +01:00
|
|
|
endMoha();
|
2022-01-03 21:11:52 +01:00
|
|
|
}
|
2022-01-08 11:51:50 +01:00
|
|
|
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
|
|
|
?>
|