searating classes from main script
This commit is contained in:
parent
91c3a3a5d4
commit
383fa96ee7
108
class/main.php
Normal file
108
class/main.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
class Message
|
||||
{
|
||||
public $id;
|
||||
public $state = false;
|
||||
public $msg;
|
||||
}
|
||||
|
||||
class topic {
|
||||
public $mid;
|
||||
public $status;
|
||||
public $info;
|
||||
public $devices;
|
||||
public $groups;
|
||||
public $extensions;
|
||||
public $config;
|
||||
}
|
||||
|
||||
class device
|
||||
{
|
||||
public $method; //auto or manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
public $powerSource;
|
||||
public $description;
|
||||
public $functions;
|
||||
public $payload;
|
||||
public $availibility;
|
||||
|
||||
public function set($event)
|
||||
{
|
||||
publish($this, $this->payload, "set", $event);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
publish($this, $this->payload, "get", $event);
|
||||
}
|
||||
}
|
||||
|
||||
class ranges
|
||||
{
|
||||
public $start; //datetime
|
||||
public $end; //datetime
|
||||
}
|
||||
|
||||
class event
|
||||
{
|
||||
public $ieeeAddress;
|
||||
public $topic;
|
||||
public $param;
|
||||
public $value;
|
||||
public $device;
|
||||
public $published;
|
||||
public $dateTimeEvent; // datetime : next occurence for recurrent event
|
||||
public $startDatetime;
|
||||
public $stopDatetime;
|
||||
public $recurrenceInterval; // interval : for recurrent event
|
||||
public $exceptionInterval; // array of object ranges
|
||||
}
|
||||
|
||||
class interval
|
||||
{
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
}
|
||||
|
||||
class notificationMethod
|
||||
{
|
||||
public $url;
|
||||
public $msg;
|
||||
public $active;
|
||||
public $level;
|
||||
|
||||
function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function send($text=null)
|
||||
{
|
||||
if (empty($text)) $text= $this->msg;
|
||||
if (!empty($msg))
|
||||
{
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'method'=>"GET",
|
||||
'header'=>"Accept-language: fr\r\n"
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
/* Envoi une requête HTTP vers $url
|
||||
avec les en-têtes additionnels ci-dessus */
|
||||
$fp = fopen($url . "/" . $msg, 'r', false, $context);
|
||||
$response = stream_get_contents($fp, -1, 0);
|
||||
fclose($fp);
|
||||
}else
|
||||
{
|
||||
// TODO log_error("notificationMethod : $msg is null");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
106
class/main.php~
Normal file
106
class/main.php~
Normal file
@ -0,0 +1,106 @@
|
||||
class Message
|
||||
{
|
||||
public $id;
|
||||
public $state = false;
|
||||
public $msg;
|
||||
}
|
||||
|
||||
class topic {
|
||||
public $mid;
|
||||
public $status;
|
||||
public $info;
|
||||
public $devices;
|
||||
public $groups;
|
||||
public $extensions;
|
||||
public $config;
|
||||
}
|
||||
|
||||
class device
|
||||
{
|
||||
public $method; //auto or manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
public $powerSource;
|
||||
public $description;
|
||||
public $functions;
|
||||
public $payload;
|
||||
public $availibility;
|
||||
|
||||
public function set($event)
|
||||
{
|
||||
publish($this, $this->payload, "set", $event);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
publish($this, $this->payload, "get", $event);
|
||||
}
|
||||
}
|
||||
|
||||
class ranges
|
||||
{
|
||||
public $start; //datetime
|
||||
public $end; //datetime
|
||||
}
|
||||
|
||||
class event
|
||||
{
|
||||
public $ieeeAddress;
|
||||
public $topic;
|
||||
public $param;
|
||||
public $value;
|
||||
public $device;
|
||||
public $published;
|
||||
public $dateTimeEvent; // datetime : next occurence for recurrent event
|
||||
public $startDatetime;
|
||||
public $stopDatetime;
|
||||
public $recurrenceInterval; // interval : for recurrent event
|
||||
public $exceptionInterval; // array of object ranges
|
||||
}
|
||||
|
||||
class interval
|
||||
{
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
}
|
||||
|
||||
class notificationMethod
|
||||
{
|
||||
public $url;
|
||||
public $msg;
|
||||
public $active;
|
||||
public $level;
|
||||
|
||||
function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function send($text=null)
|
||||
{
|
||||
if (empty($text)) $text= $this->msg;
|
||||
if (!empty($msg))
|
||||
{
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'method'=>"GET",
|
||||
'header'=>"Accept-language: fr\r\n"
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
/* Envoi une requête HTTP vers $url
|
||||
avec les en-têtes additionnels ci-dessus */
|
||||
$fp = fopen($url . "/" . $msg, 'r', false, $context);
|
||||
$response = stream_get_contents($fp, -1, 0);
|
||||
fclose($fp);
|
||||
}else
|
||||
{
|
||||
// TODO log_error("notificationMethod : $msg is null");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
124
moha.php
124
moha.php
@ -4,12 +4,7 @@
|
||||
define( "EOL", "\n");
|
||||
define("Z2M", "zigbee2mqtt");
|
||||
|
||||
// log levels
|
||||
/*define( "DEBUG", 0);
|
||||
define( "INFO", 1);
|
||||
define( "WARNING", 3);
|
||||
define( "ERROR", 4);*/
|
||||
$logLevel = LOG_DEBUG;
|
||||
|
||||
|
||||
|
||||
declare(ticks = 1);
|
||||
@ -17,110 +12,7 @@ declare(ticks = 1);
|
||||
$listProperties = array("powerSource" => "batterie");
|
||||
$listPropertiesKeys = array("property");
|
||||
|
||||
class Message
|
||||
{
|
||||
public $id;
|
||||
public $state = false;
|
||||
public $msg;
|
||||
}
|
||||
|
||||
class topic {
|
||||
public $mid;
|
||||
public $status;
|
||||
public $info;
|
||||
public $devices;
|
||||
public $groups;
|
||||
public $extensions;
|
||||
public $config;
|
||||
}
|
||||
|
||||
class device
|
||||
{
|
||||
public $method; //auto or manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
public $powerSource;
|
||||
public $description;
|
||||
public $functions;
|
||||
public $payload;
|
||||
public $availibility;
|
||||
|
||||
public function set($event)
|
||||
{
|
||||
publish($this, $this->payload, "set", $event);
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
publish($this, $this->payload, "get", $event);
|
||||
}
|
||||
}
|
||||
|
||||
class ranges
|
||||
{
|
||||
public $start; //datetime
|
||||
public $end; //datetime
|
||||
}
|
||||
|
||||
class event
|
||||
{
|
||||
public $ieeeAddress;
|
||||
public $topic;
|
||||
public $param;
|
||||
public $value;
|
||||
public $device;
|
||||
public $published;
|
||||
public $dateTimeEvent; // datetime : next occurence for recurrent event
|
||||
public $startDatetime;
|
||||
public $stopDatetime;
|
||||
public $recurrenceInterval; // interval : for recurrent event
|
||||
public $exceptionInterval; // array of object ranges
|
||||
}
|
||||
|
||||
class interval
|
||||
{
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
}
|
||||
|
||||
class notificationMethod
|
||||
{
|
||||
public $url;
|
||||
public $msg;
|
||||
|
||||
function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function send($text=null)
|
||||
{
|
||||
if (empty($text)) $text= $this->msg;
|
||||
if (!empty($msg))
|
||||
{
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'method'=>"GET",
|
||||
'header'=>"Accept-language: fr\r\n"
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
|
||||
/* Envoi une requête HTTP vers $url
|
||||
avec les en-têtes additionnels ci-dessus */
|
||||
$fp = fopen($url . "/" . $msg, 'r', false, $context);
|
||||
$response = stream_get_contents($fp, -1, 0);
|
||||
fclose($fp);
|
||||
}else
|
||||
{
|
||||
// TODO log_error("notificationMethod : $msg is null");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
include "class/main.php";
|
||||
|
||||
//global variables
|
||||
$topics = array(); // list of topics
|
||||
@ -152,11 +44,19 @@ require "events.php";
|
||||
require "db_functions.php";
|
||||
|
||||
$client = new Mosquitto\Client();
|
||||
|
||||
// log levels
|
||||
define( "DEBUG", $client->LOG_DEBUG);
|
||||
define( "INFO", 1);
|
||||
define( "WARNING", 3);
|
||||
define( "ERROR", 4);
|
||||
$logLevel = LOG_DEBUG;
|
||||
|
||||
// defining callback functions
|
||||
$client->onConnect('connectResponse');
|
||||
$client->onDisconnect('disconnectResponse');
|
||||
$client->onSubscribe('subscribeResponse');
|
||||
$client->onUnsubscribe('unsubscribeResponse');
|
||||
|
||||
$client->onMessage('message');
|
||||
$client->onLog('logger');
|
||||
$client->onPublish('publishResponse');
|
||||
@ -168,8 +68,6 @@ pcntl_signal(SIGHUP, 'signalHandler'); // Terminal log-out
|
||||
pcntl_signal(SIGINT, 'signalHandler');
|
||||
|
||||
// Program start
|
||||
|
||||
|
||||
$client->connect("192.168.1.253", 1883, 5);
|
||||
foreach($topics as $name => $topic)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user