Bonjour,
Mon objectif et d’intégrer les données de ma piscine (température, pH, etc) à mon équipement jeedom.
Pour cela j’ai fait un script php qui va chercher sur le site du constructeur les informations dont j’ai besoin (édité en temps réelle).
Tout cela fonctionne parfaitement bien en local (Wamp), et encore mieux, cela fonctionne sur un serveur (Apache).
Tout content j’ai donc essayé de l’intégrer à mon serveur jeedom grâce au plugin Script. Mais malheureusement, ça ne marche plus !
De ce que j’ai compris, chaque script ne peux retourner qu’une seul valeur numérique, donc j’ai fait un script par information que je cherche. (ici je ne parlerais que de celui de la température).
Pour être plus précis, lorsque je lance le script, cela met énormément de temps à s’effectuer (~45s), hors sur Apache ou Wamp c’était quasiment instantané. De plus, le résultat de ma requête affiche « 0 ».
Je me dis que c’est peut-être que jeedom n’autorise pas les requête http via curl ? ou peut-être qu’il y a un autre problème ? C’est pour cela que je m’en refaire à vous ! est ce que quelqu’un à déjà eu ce problème ? ou avez-vous des idées de correctif ?
Merci d’avance pour vos retours
Mon script:
<?php
define("DOC_ROOT","/var/www/html");
//set the directory for the cookie using defined document root var
$path = DOC_ROOT."/glpi";
//build a unique path with every request to store. the info per user with custom func. I used this function to build unique paths based on member ID, that was for my use case. It can be a regular dir.
//$path = build_unique_path($path); // this was for my use case
//login form action url
$url="https://www.bayrol-poolaccess.de/webview/m/login.php?r=reg";
//$postinfo = "email=".$username."&password=".$password."&login=1";
$postinfo = array(
'username' => 'USERNAME',
'password' => 'MOTDEPASSE',
'login' => 1
);
$cookie_file_path = $path."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_exec($ch);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "https://www.bayrol-poolaccess.de/webview/getdata.php?cid=5282");
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
$data = array();
preg_match_all("#<h1>([0-9.]*)<\/h1>#",$html,$data);
$data = $data[1];
// Les données sont affichés dans $data
// $data[0] = Acidité (pH)
// $data[1] = Tension (mV)
// $data[2] = Température (°C)
echo $data[2];
?>