CRC = %x"), $s1, ord($crc))); if ($s1 == ord($crc)) { return true; }else { return false; } } function now() { return new DateTime("now"); } function signalHandler($signal) { global $bbSerialPort, $connected, $client, $logFh; $x = 0; dio_close($bbSerialPort); while ($connected) { if ( $x++ > 60) { $client->disconnect(); fclose($logFh); exit (1); } $client->loop(); } sleep(4); fclose($logFh); exit(0); } function logger($level, $log, $notif = false) { global $logFh, $logLevel, $notificationLevel; //echo "=====>>>> $level => $logLevel => $notificationLevel" . EOL ; //echo $log .EOL; //var_dump($level); //var_dump($log); if ($level & $logLevel) { fwrite($logFh, "$level : $log" . EOL); print ("$level : $log" . EOL); } } date_default_timezone_set('Europe/Paris'); if (! $logFh = fopen("/var/log/pws2mqtt.log", "w") ) { echo _("error opening log file") . EOL; }else { echo _("Log file opened") . EOL; } //signal handling pcntl_signal(SIGTERM, 'signalHandler');// Termination ('kill' was called) pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out pcntl_signal(SIGINT, 'signalHandler'); ?>