added distants notifications and devices availability warning
This commit is contained in:
parent
02dfa615fa
commit
2e6b2fe5cb
31
class/availibility.php
Normal file
31
class/availibility.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
<?php
|
||||||
|
class availability
|
||||||
|
{
|
||||||
|
// by default all devices are listening for availability
|
||||||
|
|
||||||
|
// callback fonction. Is called with these 4 parameters
|
||||||
|
public function callBack($topic, $fn, $param, $value)
|
||||||
|
{
|
||||||
|
global $devices, $indexDevices, $notificationMethods;
|
||||||
|
switch($param)
|
||||||
|
{
|
||||||
|
case "availability":
|
||||||
|
if ($value != "online")
|
||||||
|
{
|
||||||
|
//your code here
|
||||||
|
logger("Device: " . $topic . "/" . $fn . "is offline");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
echo _("notification received from MQTT") . EOL;
|
||||||
|
//echo $param . "=> " . $value . EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$hooks["availability"] = new availability;
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
10
events.php
10
events.php
@ -33,7 +33,7 @@ function checkEvents()
|
|||||||
publish($event->device, array($event->param => $event->value), "set", $key);
|
publish($event->device, array($event->param => $event->value), "set", $key);
|
||||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||||
{
|
{
|
||||||
logger(LOG_ERROR, __("Error in event recurrence. event: ") . $key);
|
logger(ERROR, __("Error in event recurrence. event: ") . $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDateti
|
|||||||
$event->dateTimeEvent = $event->startDatetime;
|
$event->dateTimeEvent = $event->startDatetime;
|
||||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||||
{
|
{
|
||||||
logger(LOG_ERROR, __("Error in event recurrence. event: ") . $key);
|
logger(ERROR, __("Error in event recurrence. event: ") . $key);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,11 +124,11 @@ function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=fal
|
|||||||
}
|
}
|
||||||
if (empty($s))
|
if (empty($s))
|
||||||
{
|
{
|
||||||
logger(LOG_ERROR, __("setDelay error: unit is empty"));
|
logger(ERROR, __("setDelay error: unit is empty"));
|
||||||
}
|
}
|
||||||
if (($datetime->add(new DateInterval('PT'. $delay . $s))) === false)
|
if (($datetime->add(new DateInterval('PT'. $delay . $s))) === false)
|
||||||
{
|
{
|
||||||
logger(LOG_ERROR, __("setDelay error: datetime->add"));
|
logger(ERROR, __("setDelay error: datetime->add"));
|
||||||
}
|
}
|
||||||
print_r($datetime);
|
print_r($datetime);
|
||||||
if ($replace)
|
if ($replace)
|
||||||
@ -169,7 +169,7 @@ function deleteEvent($eventKey)
|
|||||||
{
|
{
|
||||||
global $events;
|
global $events;
|
||||||
unset ($events[$eventKey]);
|
unset ($events[$eventKey]);
|
||||||
logger(LOG_INFO, __("delete event ") . $eventKey);
|
logger(INFO, __("delete event ") . $eventKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,2 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
$notificationMethods["freemobile"] = new notificationMethod("https://smsapi.free-mobile.fr/sendmsg?user=32886706&pass=JTGUY6l5OG73zX&msg=");
|
class notificationFreemobile
|
||||||
|
{
|
||||||
|
private $url = "https://smsapi.free-mobile.fr/sendmsg?user=32886706&pass=JTGUY6l5OG73zX&msg=";
|
||||||
|
private $name = "freemobile";
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
global $notificationMethods;
|
||||||
|
$notificationMethods[$name]->active = true;
|
||||||
|
$notificationMethods[$name]->level = ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function send($message)
|
||||||
|
{
|
||||||
|
if ($this->active == true)
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
// set url
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $this->url . $message);
|
||||||
|
|
||||||
|
//return the transfer as a string
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
|
// $output contains the output string
|
||||||
|
logger(INFO, curl_exec($ch));
|
||||||
|
|
||||||
|
// close curl resource to free up system resources
|
||||||
|
curl_close($ch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$notificationMethods["freemobile"] = new notificationMethod();
|
||||||
|
|
||||||
|
?>
|
||||||
|
1
moha.php
1
moha.php
@ -53,6 +53,7 @@ define( "WARNING", $client->LOG_WARNING);
|
|||||||
define( "ERROR", $client->LOG_ERR);
|
define( "ERROR", $client->LOG_ERR);
|
||||||
define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR);
|
define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR);
|
||||||
$logLevel = DEBUG;
|
$logLevel = DEBUG;
|
||||||
|
$notificationLevel = WARNING | ERROR;
|
||||||
|
|
||||||
// defining callback functions
|
// defining callback functions
|
||||||
$client->onConnect('connectResponse');
|
$client->onConnect('connectResponse');
|
||||||
|
@ -162,15 +162,4 @@ function publishResponse($mid)
|
|||||||
$mids[$mid] = true;
|
$mids[$mid] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logger($level, $log)
|
|
||||||
{
|
|
||||||
global $logFh, $logLevel;
|
|
||||||
if ( $level >= $logLevel)
|
|
||||||
{
|
|
||||||
fwrite($logFh, "$level : $log" . EOL);
|
|
||||||
print ("$level : $log" . EOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
25
utils.php
25
utils.php
@ -10,5 +10,30 @@ function signalHandler($signal)
|
|||||||
endMoha();
|
endMoha();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notify($message)
|
||||||
|
{
|
||||||
|
foreach($notificationMethods as $value)
|
||||||
|
{
|
||||||
|
$result |= $value->send($message);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function logger($level, $log)
|
||||||
|
{
|
||||||
|
global $logFh, $logLevel;
|
||||||
|
if ( $level >= $logLevel)
|
||||||
|
{
|
||||||
|
fwrite($logFh, "$level : $log" . EOL);
|
||||||
|
print ("$level : $log" . EOL);
|
||||||
|
}
|
||||||
|
if ($level >= $notificationLevel)
|
||||||
|
{
|
||||||
|
if(notify($message) == true)
|
||||||
|
{
|
||||||
|
logger(INFO, __("Notification not sent"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user