diff --git a/domo/PhpSerial.php b/domo/PhpSerial.php deleted file mode 100644 index 1d253d5..0000000 --- a/domo/PhpSerial.php +++ /dev/null @@ -1,704 +0,0 @@ - - * @author Rizwan Kassim - * @thanks Aurélien Derouineau for finding how to open serial ports with windows - * @thanks Alec Avedisyan for help and testing with reading - * @thanks Jim Wright for OSX cleanup/fixes. - * @copyright under GPL 2 licence - */ -class PhpSerial -{ - public $_device = null; - public $_winDevice = null; - public $_dHandle = null; - public $_dState = SERIAL_DEVICE_NOTSET; - public $_buffer = ""; - public $_os = ""; - - /** - * This var says if buffer should be flushed by sendMessage (true) or - * manually (false) - * - * @var bool - */ - public $autoFlush = true; - - /** - * Constructor. Perform some checks about the OS and setserial - * - * @return PhpSerial - */ - public function PhpSerial() - { - setlocale(LC_ALL, "en_US"); - - $sysName = php_uname(); - - if (substr($sysName, 0, 5) === "Linux") { - $this->_os = "linux"; - - if ($this->_exec("stty") === 0) { - register_shutdown_function(array($this, "deviceClose")); - } else { - trigger_error( - "No stty availible, unable to run.", - E_USER_ERROR - ); - } - } elseif (substr($sysName, 0, 6) === "Darwin") { - $this->_os = "osx"; - register_shutdown_function(array($this, "deviceClose")); - } elseif (substr($sysName, 0, 7) === "Windows") { - $this->_os = "windows"; - register_shutdown_function(array($this, "deviceClose")); - } else { - trigger_error("Host OS is neither osx, linux nor windows, unable " . - "to run.", E_USER_ERROR); - exit(); - } - } - - // - // OPEN/CLOSE DEVICE SECTION -- {START} - // - - /** - * Device set function : used to set the device name/address. - * -> linux : use the device address, like /dev/ttyS0 - * -> osx : use the device address, like /dev/tty.serial - * -> windows : use the COMxx device name, like COM1 (can also be used - * with linux) - * - * @param string $device the name of the device to be used - * @return bool - */ - public function deviceSet($device) - { - if ($this->_dState !== SERIAL_DEVICE_OPENED) { - if ($this->_os === "linux") { - if (preg_match("@^COM(\\d+):?$@i", $device, $matches)) { - $device = "/dev/ttyS" . ($matches[1] - 1); - } - - if ($this->_exec("stty -F " . $device) === 0) { - $this->_device = $device; - $this->_dState = SERIAL_DEVICE_SET; - - return true; - } - } elseif ($this->_os === "osx") { - if ($this->_exec("stty -f " . $device) === 0) { - $this->_device = $device; - $this->_dState = SERIAL_DEVICE_SET; - - return true; - } - } elseif ($this->_os === "windows") { - if (preg_match("@^COM(\\d+):?$@i", $device, $matches) - and $this->_exec( - exec("mode " . $device . " xon=on BAUD=9600") - ) === 0 - ) { - $this->_winDevice = "COM" . $matches[1]; - $this->_device = "\\.com" . $matches[1]; - $this->_dState = SERIAL_DEVICE_SET; - - return true; - } - } - - trigger_error("Specified serial port is not valid", E_USER_WARNING); - - return false; - } else { - trigger_error("You must close your device before to set an other " . - "one", E_USER_WARNING); - - return false; - } - } - - /** - * Opens the device for reading and/or writing. - * - * @param string $mode Opening mode : same parameter as fopen() - * @return bool - */ - public function deviceOpen($mode = "r+b") - { - if ($this->_dState === SERIAL_DEVICE_OPENED) { - trigger_error("The device is already opened", E_USER_NOTICE); - - return true; - } - - if ($this->_dState === SERIAL_DEVICE_NOTSET) { - trigger_error( - "The device must be set before to be open", - E_USER_WARNING - ); - - return false; - } - - if (!preg_match("@^[raw]\\+?b?$@", $mode)) { - trigger_error( - "Invalid opening mode : ".$mode.". Use fopen() modes.", - E_USER_WARNING - ); - - return false; - } - - $this->_dHandle = @fopen($this->_device, $mode); - - if ($this->_dHandle !== false) { - stream_set_blocking($this->_dHandle, 0); - $this->_dState = SERIAL_DEVICE_OPENED; - - return true; - } - - $this->_dHandle = null; - trigger_error("Unable to open the device", E_USER_WARNING); - - return false; - } - - /** - * Closes the device - * - * @return bool - */ - public function deviceClose() - { - if ($this->_dState !== SERIAL_DEVICE_OPENED) { - return true; - } - - if (fclose($this->_dHandle)) { - $this->_dHandle = null; - $this->_dState = SERIAL_DEVICE_SET; - - return true; - } - - trigger_error("Unable to close the device", E_USER_ERROR); - - return false; - } - - // - // OPEN/CLOSE DEVICE SECTION -- {STOP} - // - - // - // CONFIGURE SECTION -- {START} - // - - /** - * Configure the Baud Rate - * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400, - * 57600 and 115200. - * - * @param int $rate the rate to set the port in - * @return bool - */ - public function confBaudRate($rate) - { - if ($this->_dState !== SERIAL_DEVICE_SET) { - trigger_error("Unable to set the baud rate : the device is " . - "either not set or opened", E_USER_WARNING); - - return false; - } - - $validBauds = array ( - 110 => 11, - 150 => 15, - 300 => 30, - 600 => 60, - 1200 => 12, - 2400 => 24, - 4800 => 48, - 9600 => 96, - 19200 => 19, - 38400 => 38400, - 57600 => 57600, - 115200 => 115200 - ); - - if (isset($validBauds[$rate])) { - if ($this->_os === "linux") { - $ret = $this->_exec( - "stty -F " . $this->_device . " " . (int) $rate, - $out - ); - } elseif ($this->_os === "osx") { - $ret = $this->_exec( - "stty -f " . $this->_device . " " . (int) $rate, - $out - ); - } elseif ($this->_os === "windows") { - $ret = $this->_exec( - "mode " . $this->_winDevice . " BAUD=" . $validBauds[$rate], - $out - ); - } else { - return false; - } - - if ($ret !== 0) { - trigger_error( - "Unable to set baud rate: " . $out[1], - E_USER_WARNING - ); - - return false; - } - - return true; - } else { - return false; - } - } - - /** - * Configure parity. - * Modes : odd, even, none - * - * @param string $parity one of the modes - * @return bool - */ - public function confParity($parity) - { - if ($this->_dState !== SERIAL_DEVICE_SET) { - trigger_error( - "Unable to set parity : the device is either not set or opened", - E_USER_WARNING - ); - - return false; - } - - $args = array( - "none" => "-parenb", - "odd" => "parenb parodd", - "even" => "parenb -parodd", - ); - - if (!isset($args[$parity])) { - trigger_error("Parity mode not supported", E_USER_WARNING); - - return false; - } - - if ($this->_os === "linux") { - $ret = $this->_exec( - "stty -F " . $this->_device . " " . $args[$parity], - $out - ); - } elseif ($this->_os === "osx") { - $ret = $this->_exec( - "stty -f " . $this->_device . " " . $args[$parity], - $out - ); - } else { - $ret = $this->_exec( - "mode " . $this->_winDevice . " PARITY=" . $parity{0}, - $out - ); - } - - if ($ret === 0) { - return true; - } - - trigger_error("Unable to set parity : " . $out[1], E_USER_WARNING); - - return false; - } - - /** - * Sets the length of a character. - * - * @param int $int length of a character (5 <= length <= 8) - * @return bool - */ - public function confCharacterLength($int) - { - if ($this->_dState !== SERIAL_DEVICE_SET) { - trigger_error("Unable to set length of a character : the device " . - "is either not set or opened", E_USER_WARNING); - - return false; - } - - $int = (int) $int; - if ($int < 5) { - $int = 5; - } elseif ($int > 8) { - $int = 8; - } - - if ($this->_os === "linux") { - $ret = $this->_exec( - "stty -F " . $this->_device . " cs" . $int, - $out - ); - } elseif ($this->_os === "osx") { - $ret = $this->_exec( - "stty -f " . $this->_device . " cs" . $int, - $out - ); - } else { - $ret = $this->_exec( - "mode " . $this->_winDevice . " DATA=" . $int, - $out - ); - } - - if ($ret === 0) { - return true; - } - - trigger_error( - "Unable to set character length : " .$out[1], - E_USER_WARNING - ); - - return false; - } - - /** - * Sets the length of stop bits. - * - * @param float $length the length of a stop bit. It must be either 1, - * 1.5 or 2. 1.5 is not supported under linux and on - * some computers. - * @return bool - */ - public function confStopBits($length) - { - if ($this->_dState !== SERIAL_DEVICE_SET) { - trigger_error("Unable to set the length of a stop bit : the " . - "device is either not set or opened", E_USER_WARNING); - - return false; - } - - if ($length != 1 - and $length != 2 - and $length != 1.5 - and !($length == 1.5 and $this->_os === "linux") - ) { - trigger_error( - "Specified stop bit length is invalid", - E_USER_WARNING - ); - - return false; - } - - if ($this->_os === "linux") { - $ret = $this->_exec( - "stty -F " . $this->_device . " " . - (($length == 1) ? "-" : "") . "cstopb", - $out - ); - } elseif ($this->_os === "osx") { - $ret = $this->_exec( - "stty -f " . $this->_device . " " . - (($length == 1) ? "-" : "") . "cstopb", - $out - ); - } else { - $ret = $this->_exec( - "mode " . $this->_winDevice . " STOP=" . $length, - $out - ); - } - - if ($ret === 0) { - return true; - } - - trigger_error( - "Unable to set stop bit length : " . $out[1], - E_USER_WARNING - ); - - return false; - } - - /** - * Configures the flow control - * - * @param string $mode Set the flow control mode. Availible modes : - * -> "none" : no flow control - * -> "rts/cts" : use RTS/CTS handshaking - * -> "xon/xoff" : use XON/XOFF protocol - * @return bool - */ - public function confFlowControl($mode) - { - if ($this->_dState !== SERIAL_DEVICE_SET) { - trigger_error("Unable to set flow control mode : the device is " . - "either not set or opened", E_USER_WARNING); - - return false; - } - - $linuxModes = array( - "none" => "clocal -crtscts -ixon -ixoff", - "rts/cts" => "-clocal crtscts -ixon -ixoff", - "xon/xoff" => "-clocal -crtscts ixon ixoff" - ); - $windowsModes = array( - "none" => "xon=off octs=off rts=on", - "rts/cts" => "xon=off octs=on rts=hs", - "xon/xoff" => "xon=on octs=off rts=on", - ); - - if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff") { - trigger_error("Invalid flow control mode specified", E_USER_ERROR); - - return false; - } - - if ($this->_os === "linux") { - $ret = $this->_exec( - "stty -F " . $this->_device . " " . $linuxModes[$mode], - $out - ); - } elseif ($this->_os === "osx") { - $ret = $this->_exec( - "stty -f " . $this->_device . " " . $linuxModes[$mode], - $out - ); - } else { - $ret = $this->_exec( - "mode " . $this->_winDevice . " " . $windowsModes[$mode], - $out - ); - } - - if ($ret === 0) { - return true; - } else { - trigger_error( - "Unable to set flow control : " . $out[1], - E_USER_ERROR - ); - - return false; - } - } - - /** - * Sets a setserial parameter (cf man setserial) - * NO MORE USEFUL ! - * -> No longer supported - * -> Only use it if you need it - * - * @param string $param parameter name - * @param string $arg parameter value - * @return bool - */ - public function setSetserialFlag($param, $arg = "") - { - if (!$this->_ckOpened()) { - return false; - } - - $return = exec( - "setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1" - ); - - if ($return{0} === "I") { - trigger_error("setserial: Invalid flag", E_USER_WARNING); - - return false; - } elseif ($return{0} === "/") { - trigger_error("setserial: Error with device file", E_USER_WARNING); - - return false; - } else { - return true; - } - } - - // - // CONFIGURE SECTION -- {STOP} - // - - // - // I/O SECTION -- {START} - // - - /** - * Sends a string to the device - * - * @param string $str string to be sent to the device - * @param float $waitForReply time to wait for the reply (in seconds) - */ - public function sendMessage($str, $waitForReply = 0.1) - { - $this->_buffer .= $str; - - if ($this->autoFlush === true) { - $this->serialflush(); - } - - usleep((int) ($waitForReply * 1000000)); - } - - /** - * Reads the port until no new datas are availible, then return the content. - * - * @param int $count Number of characters to be read (will stop before - * if less characters are in the buffer) - * @return string - */ - public function readPort($count = 0) - { - if ($this->_dState !== SERIAL_DEVICE_OPENED) { - trigger_error("Device must be opened to read it", E_USER_WARNING); - - return false; - } - - if ($this->_os === "linux" || $this->_os === "osx") { - // Behavior in OSX isn't to wait for new data to recover, but just - // grabs what's there! - // Doesn't always work perfectly for me in OSX - $content = ""; $i = 0; - - if ($count !== 0) { - do { - if ($i > $count) { - $content .= fread($this->_dHandle, ($count - $i)); - } else { - $content .= fread($this->_dHandle, 128); - } - } while (($i += 128) === strlen($content)); - } else { - do { - $content .= fread($this->_dHandle, 128); - } while (($i += 128) === strlen($content)); - } - - return $content; - } elseif ($this->_os === "windows") { - // Windows port reading procedures still buggy - $content = ""; $i = 0; - - if ($count !== 0) { - do { - if ($i > $count) { - $content .= fread($this->_dHandle, ($count - $i)); - } else { - $content .= fread($this->_dHandle, 128); - } - } while (($i += 128) === strlen($content)); - } else { - do { - $content .= fread($this->_dHandle, 128); - } while (($i += 128) === strlen($content)); - } - - return $content; - } - - return false; - } - - /** - * Flushes the output buffer - * Renamed from flush for osx compat. issues - * - * @return bool - */ - public function serialflush() - { - if (!$this->_ckOpened()) { - return false; - } - - if (fwrite($this->_dHandle, $this->_buffer) !== false) { - $this->_buffer = ""; - - return true; - } else { - $this->_buffer = ""; - trigger_error("Error while sending message", E_USER_WARNING); - - return false; - } - } - - // - // I/O SECTION -- {STOP} - // - - // - // INTERNAL TOOLKIT -- {START} - // - - public function _ckOpened() - { - if ($this->_dState !== SERIAL_DEVICE_OPENED) { - trigger_error("Device must be opened", E_USER_WARNING); - - return false; - } - - return true; - } - - public function _ckClosed() - { - if ($this->_dState === SERIAL_DEVICE_OPENED) { - trigger_error("Device must be closed", E_USER_WARNING); - - return false; - } - - return true; - } - - public function _exec($cmd, &$out = null) - { - $desc = array( - 1 => array("pipe", "w"), - 2 => array("pipe", "w") - ); - - $proc = proc_open($cmd, $desc, $pipes); - - $ret = stream_get_contents($pipes[1]); - $err = stream_get_contents($pipes[2]); - - fclose($pipes[1]); - fclose($pipes[2]); - - $retVal = proc_close($proc); - - if (func_num_args() == 2) $out = array($ret, $err); - return $retVal; - } - - // - // INTERNAL TOOLKIT -- {STOP} - // -} diff --git a/domo/config-domo.yaml b/domo/config-domo.yaml deleted file mode 100644 index e8d0863..0000000 --- a/domo/config-domo.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Format : https://fr.wikipedia.org/wiki/Yaml#Caract%C3%A9ristiques -PrintMessage: 5 # 0=0 5=debug -i2c: - adress: 0x04 - device: 1 -HeartbeatTime: 1 # Fréquence du bâtement de coeur (en seconde) -xmlData: - file: /opt/PvMonit/www/data-xml-test.xml - #fileExpir: 300 # Age en seconde après laquel le fichier n'est plus considéré comme ok - fileExpir: 30000 - checkTime: 10 # Fréquece de la vérificatio du XML (en seconde) - checkError: 3 # nombre d'erreurs sur le xml avant de sortir du mode automatique / stopper le heartbeat - # temps avant erreur = $XML_CHECK_TIME * $XML_CHECK_ERROR - #expir: 600 # Age en seconde après laquel la donnée n'est plus considérer comme viable - expir: 600000 # Age en seconde après laquel la donnée n'est plus considérer comme viable - DownloadRetry: 3 - valueUse: - 0: SOC - 1: P - 2: PPVT - 3: CS - #4: CONSO -relay: - nb: 5 - scriptDir: ./relay.script.d/ - scriptExecInterval: 2 # Interval d'execution des script de relais - correspondance: # A commencer par 0 - 0: Box Internet - 1: Téléphone - 2: Disque dur externe - 3: Pompe de relevage - 4: Chargeur outil électroportatif - diff --git a/domo/config.ini b/domo/config.ini deleted file mode 100644 index 905c585..0000000 --- a/domo/config.ini +++ /dev/null @@ -1,88 +0,0 @@ -import yaml -import time -from smbus2 import SMBus -import os - -from urllib.request import urlopen - - -## for debug : -import pprint - - -# Read the conf file -with open('./config-domo.yaml') as f: - config = yaml.load(f, Loader=yaml.FullLoader) - -# Function for log -def logMsg(level, msg): - if level <= config['PrintMessage'] : - print(time.strftime ('%m/%d/%Y %H:%M') ," - ",msg) - return -1 - -# i2c write -def writeNumber(value): - bus.write_byte(config['i2c']['adress'], value) - return -1 - -logMsg(1, 'Lancement du script domo.py') -logMsg(5, config) - -heartLastCheck=0 -xmlLastCheck=0 -#xmlCheckError=config['xmlData']['checkError'] -logMsg(5, "Début de la boucle") -while 1: - t=int(time.time()) - if xmlLastCheck+config['xmlData']['checkTime'] < t: - logMsg(3, "XML data récup") - attempts = 3 - while attempts > config['xmlData']['DownloadRetry']: - try: - xml = urlopen("http://www.google.com/").read() - f = open( config['xmlData']['file'], 'w' ) - f.write( xml ) - f.close() - break - except urllib2.URLError as e: - attempts += 1 - print(type(e)) - - if not os.path.isfile(config['xmlData']['file']): - logMsg(1, "Êtes vous certain d'avoir correctement configuré la tâche planifié qui télécharge les données XML dans $DATA_FILE ?") - - # if ($xml_last_check+$GLOBALS['XML_CHECK_TIME'] < time()) { - # trucAdir(3, "XML data recup"); - # if (!is_file($GLOBALS['DATA_FILE'])) { - # trucAdir(1, "Êtes vous certain d'avoir correctement configuré la tâche planifié qui télécharge les données XML dans $DATA_FILE ?"); - # $xml_check_error++; - # } else if (filemtime($GLOBALS['DATA_FILE'])+$GLOBALS['DATA_FILE_TIMEOUT'] < time()) { - # trucAdir(1, "Le fichier data est périmé !"); - # $xml_check_error++; - # } else { - # $xml_data_get=xml_data_get($DATA_FILE); - # if ($xml_data_get == null || $xml_data_get == false) { - # trucAdir(2, 'Données XML invalide'); - # $xml_check_error++; - # } else { - # trucAdir(4, 'Les données sont bonnes !'); - # $xml_data_get = xml_data_get($GLOBALS['DATA_FILE']); - # $xml_check_error=0; - # } - # } - # $xml_last_check=time(); - # } - - - - # - - - if heartLastCheck+config['HeartbeatTime'] < t: - bus=SMBus(config['i2c']['device']); - writeNumber(int(ord("H"))) - logMsg(5, 'Heardbeat envoyé') - heartLastCheck=t - - time.sleep(0.01) - diff --git a/domo/data-xml-test.xml b/domo/data-xml-test.xml deleted file mode 100644 index 010cbb0..0000000 --- a/domo/data-xml-test.xml +++ /dev/null @@ -1,244 +0,0 @@ - - - - - 700 - 1568197205 - BMV - BMV-700 - 700 - - - Tension minimale batterie - 21.238 - V - - - Tension maximale de la batterie - 29.442 - V - - - Nombre de secondes depuis la dernière charge complète - 62047 - s - - - Nombre de synchronisations automatiques - 92 - - - - Nombre d'alarmes de tension faible - 0 - - - - Nombre d'alarmes de tension élevée - 0 - - - - Quantité d'énergie déchargée - 506.88 - kWh - - - Quantité d'énergie chargée - 600.07 - kWh - - - Tension de la batterie - 27.74 - V - - - Courant de la batterie - 5.806 - A - - - Puissance instantané - 161 - W - - - Ampères heures consommées - -10.772 - Ah - - - État de charge - 96.7 - % - - - Temps restant - - - - - Raison de l'alarme - Aucune - - - - - - MpttBleu - 1568197205 - MPTT - BlueSolar MPPT 100/30 rev2 - HQ16129A5J2 - - - Tension de la batterie - 27.82 - V - - - Courant de la batterie - 5.7 - A - - - Voltage des panneaux - 55600 - mV - - - Production des panneaux - 162 - W - - - Status de charge - Absorption - - - - Présence d'erreur - Aucune - - - - Le rendement total - 782.28 - kWh - - - Rendement aujourd'hui - 0.4 - kWh - - - Puissance maximum ce jour - 335 - W - - - Rendemain hier - 1.52 - kWh - - - Puissance maximum hier - 312 - W - - - - - MpttBlanc - 1568197205 - MPTT - BlueSolar MPPT 100/30 rev2 - HQ1544WMX65 - - - Tension de la batterie - 27.76 - V - - - Courant de la batterie - 3.3 - A - - - Voltage des panneaux - 63600 - mV - - - Production des panneaux - 92 - W - - - Status de charge - Float (maintient la charge pleine) - - - - Présence d'erreur - Aucune - - - - Le rendement total - 298.53 - kWh - - - Rendement aujourd'hui - 0.26 - kWh - - - Puissance maximum ce jour - 249 - W - - - Rendemain hier - 0.66 - kWh - - - Puissance maximum hier - 257 - W - - - - - Divers - 1568197380 - - - - - - Production total des panneaux - 254 - W - - - - - - - 1568197205 - - - - - - Température du local technique - 17 - °C - - - diff --git a/domo/domo.php b/domo/domo.php deleted file mode 100755 index a8e2938..0000000 --- a/domo/domo.php +++ /dev/null @@ -1,164 +0,0 @@ -deviceSet("/dev/ttyUSB0")) { - $serial->confBaudRate(9600); - $serial->confParity("none"); - $serial->confCharacterLength(8); - $serial->confStopBits(1); - $serial->confFlowControl("none"); - - trucAdir(4, 'Lancement du script'); - - $serial->deviceOpen(); - - trucAdir(4, 'Le device est prêt !'); - - $heartBeatCount=0; - $xml_last_check=0; - $xml_check_error=$GLOBALS['XML_CHECK_ERROR']; - $relay_script_last_exec=0; - while(true) { - - if ($xml_last_check+$GLOBALS['XML_CHECK_TIME'] < time()) { - trucAdir(3, "XML data recup"); - if (!is_file($GLOBALS['DATA_FILE'])) { - trucAdir(1, "Êtes vous certain d'avoir correctement configuré la tâche planifié qui télécharge les données XML dans $DATA_FILE ?"); - $xml_check_error++; - } else if (filemtime($GLOBALS['DATA_FILE'])+$GLOBALS['DATA_FILE_TIMEOUT'] < time()) { - trucAdir(1, "Le fichier data est périmé !"); - $xml_check_error++; - } else { - $xml_data_get=xml_data_get($DATA_FILE); - if ($xml_data_get == null || $xml_data_get == false) { - trucAdir(2, 'Données XML invalide'); - $xml_check_error++; - } else { - trucAdir(4, 'Les données sont bonnes !'); - $xml_data_get = xml_data_get($GLOBALS['DATA_FILE']); - $xml_check_error=0; - } - } - $xml_last_check=time(); - } - // Si pas trop d'erreur - if ($xml_check_error <= $GLOBALS['XML_CHECK_ERROR']) { - // - // Expédition du heartBeat - // - if ($heartBeatCount >= $HEARTBEAT_FREQ) { - $serial->sendMessage("H \n"); - trucAdir(5, 'Heardbeat !'); - $heartBeatCount=0; - } else { - $heartBeatCount++; - } - - // - // Lecture des données - // - $read = $serial->readPort(); - if ($read) { - - $serialDatas=explode("\n",$read); - - foreach ($serialDatas as $serialData) { - if (preg_match('/^ARDOMO DEBUG/', $serialData)) { - trucAdir(5, $serialData); - } else if (preg_match('/^ARDOMO/', $serialData)) { - trucAdir(2, $serialData); - } else if (preg_match('/^E\|/', $serialData)) { - trucAdir(5, "Seri2 : $serialData"); - $serialDataExplode = explode("|", $serialData); - // Vérification du nombre d'information (sinon c'est une erreur) - if (count($serialDataExplode)-1 == $NBRELAY) { - trucAdir(3, "Etat des relays : $serialData"); - $i=0; - foreach($serialDataExplode as $relayEtatValue) { - if ($relayEtatValue != "E") { - $relayEtatJustValue = explode(":", $relayEtatValue); - $relayEtat[$i]=$relayEtatJustValue[1]; - $i++; - } - } - } - } else if (preg_match('/^M\|/', $serialData)) { - trucAdir(5, "Seri3 : $serialData"); - $serialDataExplode = explode("|", $serialData); - // Vérification du nombre d'information (sinon c'est une erreur) - if (count($serialDataExplode)-1 == $NBRELAY) { - trucAdir(3, "Mode des relays : $serialData"); - $i=0; - foreach($serialDataExplode as $relayModValue) { - if ($relayModValue != "M") { - $relayModJustValue = explode(":", $relayModValue); - $relayMod[$i]=$relayModJustValue[1]; - $i++; - } - } - } - /*} else { - trucAdir(5, "Serial ? : $serialData");*/ - } - } - - } - // - // Traitement, ordre... - // - if ($relay_script_last_exec+$GLOBALS['RELAY_SCRIPT_EXEC_INTERVAL'] < time()) { - trucAdir(3, "Traitement des ordres"); - if (isset($relayMod) && isset($relayEtat)) { - foreach ($relayMod as $relay => $Mod) { - // On s'occupe uniquement de ceux qui sont en mode auto - if ($Mod == 2) { - if (is_file($GLOBALS['RELAY_SCRIPT_DIR'].$relay.'.php')) { - $r['etat']=$relayEtat[$relay]; - $r['id']=$relay; - $d=$xml_data_get; - $script_return = (include $GLOBALS['RELAY_SCRIPT_DIR'].$relay.'.php'); - if ($relayEtat[$relay] != $script_return) { - trucAdir(3, "Changement d'état pour le relay ".$relay." (vers ".$script_return.")"); - $serial->sendMessage('RO:'.$relay.'='.$script_return."\n"); - } else { - trucAdir(3, "Aucun changement d'état pour le relay ".$relay); - } - } - } - } - } else { - trucAdir(3, "Aucune donnée sur les relay exploitable pour pouvoir lancer des actions"); - } - $relay_script_last_exec=time(); - } - sleep(0.5); - } else { - trucAdir(1, 'Trop d\'erreur ('.$xml_check_error.') sur le xml, on stop le heartbeat.'); - sleep(10); - } - } - trucAdir(4, 'Fin du script !'); - - } else { - trucAdir(4, 'Le device n\'est pas prêt, on patiente 30s !'); - sleep(3); - } -} -?> diff --git a/domo/function.php b/domo/function.php deleted file mode 100644 index a70f63c..0000000 --- a/domo/function.php +++ /dev/null @@ -1,31 +0,0 @@ -modele == 'BMV-700' || $device->modele == 'BMV-702' || $device->modele == 'BMV-700H') { - // On vérifie que la donnée ne soit pas périmé - if ($device->timerefresh+$GLOBALS['XML_DATA_TIMEOUT'] > time()) { - foreach ($device->datas->data as $data) { - // On récupère SOC - if ($data['id'] == 'SOC') { - $BMV_data['SOC'] = $data->value; - } else if ($data['id'] == 'P') { - $BMV_data['P'] = $data->value; - } - } - } else { - $BMV_data = false; - trucAdir(2, 'Les données sont périmées'); - } - } - } - if (empty($BMV_data['SOC'])) { - trucAdir(2, 'Le SOC/le BMV n\'est pas présent dans les données...'); - $BMV_data = null; - } - return $BMV_data; -} -?> diff --git a/domo/getXml.php b/domo/getXml.php deleted file mode 100644 index a9d14cd..0000000 --- a/domo/getXml.php +++ /dev/null @@ -1,65 +0,0 @@ - diff --git a/domo/relay-script-debug.php b/domo/relay-script-debug.php deleted file mode 100644 index 6185930..0000000 --- a/domo/relay-script-debug.php +++ /dev/null @@ -1,51 +0,0 @@ - $Mod) { - - if (is_file($GLOBALS['RELAY_SCRIPT_DIR'].$relay.'.php')) { - $r['etat']=$relayEtat[$relay]; - $r['id']=$relay; - $d=$xml_data_get; - trucAdir(3, "Etat du relay ".$relay." = ".$relayEtat[$relay]); - $script_return = (include $GLOBALS['RELAY_SCRIPT_DIR'].$relay.'.php'); - if ($relayEtat[$relay] != $script_return) { - trucAdir(3, "Changement d'état pour le relay ".$relay." (vers ".$script_return.")"); - } else { - trucAdir(3, "Aucun changement d'état pour le relay ".$relay); - } - } - -} - - - - -?> diff --git a/domo/relay.script.d/0.php b/domo/relay.script.d/0.php deleted file mode 100644 index 81ec1a3..0000000 --- a/domo/relay.script.d/0.php +++ /dev/null @@ -1,82 +0,0 @@ - 11 && $d['SOC'] > 95) { - // On enregistre la date du dernier allumage - if (empty($timeLastUp[$r['id']])) { - $timeLastUp[$r['id']] = time(); - } - // On allume ! - return 2; - } else { - return 1; - } -// Si c'est allumé, faut-il l'éteindre ? -} else if ($r['etat'] == 2) { - $checkIfComputerIsUp = checkIfComputerIsUp($pingHost); - // S'il est plus de 17h et qu'il n'y a pas d'ordinateur d'allumé - if ((date('G') >= 17 && $checkIfComputerIsUp == 0) - // Si les batteries pass sous les 95% et qu'il n'y a pas d'ordinateur d'allumé - || ($d['SOC'] <= 95 && $checkIfComputerIsUp == 0)) { - - // On enregistre la date de la dernière extinction - if (empty($timeLastDown[$r['id']])) { - $timeLastDown[$r['id']] = time(); - } - // On éteind ! - return 1; - } else { - return 2; - } - -} - -*/ -return 2; -?> diff --git a/domo/relay.script.d/1.php b/domo/relay.script.d/1.php deleted file mode 100644 index 0f31d2c..0000000 --- a/domo/relay.script.d/1.php +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/domo/relay.script.d/2.php b/domo/relay.script.d/2.php deleted file mode 100644 index e061aef..0000000 --- a/domo/relay.script.d/2.php +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/domo/relay.script.d/ID.php.exemple b/domo/relay.script.d/ID.php.exemple deleted file mode 100644 index bcc7d3b..0000000 --- a/domo/relay.script.d/ID.php.exemple +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/domo/relay.script.d_php/0.php b/domo/relay.script.d_php/0.php deleted file mode 100644 index 81ec1a3..0000000 --- a/domo/relay.script.d_php/0.php +++ /dev/null @@ -1,82 +0,0 @@ - 11 && $d['SOC'] > 95) { - // On enregistre la date du dernier allumage - if (empty($timeLastUp[$r['id']])) { - $timeLastUp[$r['id']] = time(); - } - // On allume ! - return 2; - } else { - return 1; - } -// Si c'est allumé, faut-il l'éteindre ? -} else if ($r['etat'] == 2) { - $checkIfComputerIsUp = checkIfComputerIsUp($pingHost); - // S'il est plus de 17h et qu'il n'y a pas d'ordinateur d'allumé - if ((date('G') >= 17 && $checkIfComputerIsUp == 0) - // Si les batteries pass sous les 95% et qu'il n'y a pas d'ordinateur d'allumé - || ($d['SOC'] <= 95 && $checkIfComputerIsUp == 0)) { - - // On enregistre la date de la dernière extinction - if (empty($timeLastDown[$r['id']])) { - $timeLastDown[$r['id']] = time(); - } - // On éteind ! - return 1; - } else { - return 2; - } - -} - -*/ -return 2; -?> diff --git a/domo/relay.script.d_php/1.php b/domo/relay.script.d_php/1.php deleted file mode 100644 index 0f31d2c..0000000 --- a/domo/relay.script.d_php/1.php +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/domo/relay.script.d_php/2.php b/domo/relay.script.d_php/2.php deleted file mode 100644 index e061aef..0000000 --- a/domo/relay.script.d_php/2.php +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/domo/relay.script.d_php/ID.php.exemple b/domo/relay.script.d_php/ID.php.exemple deleted file mode 100644 index bcc7d3b..0000000 --- a/domo/relay.script.d_php/ID.php.exemple +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/domo/test.php b/domo/test.php deleted file mode 100644 index bcc64c5..0000000 --- a/domo/test.php +++ /dev/null @@ -1,32 +0,0 @@ -deviceSet("/dev/ttyUSB0"); - - // Set for 9600-8-N-1 (no flow control) - $serial->confBaudRate(9600); //Baud rate: 9600 - $serial->confParity("none"); //Parity (this is the "N" in "8-N-1") - $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1") - $serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1") - $serial->confFlowControl("none"); - - // Then we need to open it - $serial->deviceOpen(); -while (true) { - // Read data - $read = $serial->readPort(); - - // Print out the data - echo $read; - // print exec("echo 'r9g9b9' > /dev/ttyACM0"); - sleep(0.5); -} - // If you want to change the configuration, the device must be closed. - $serial->deviceClose(); - - ?>