Re: Projet TBH
Publié : 30 nov. 2015, 22:22
C'est pas un script payant ?? Tu casses le marché !! Lol
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
commandArray[1] = {['UpdateDevice'] = IDXdeTonCapteur.. '|0|' .. TEMP..";"..HYGRO}Code : Tout sélectionner
commandArray = {}
---recupere l'heure en minutes
time=os.time()
minutes=tonumber(os.date('%M',time))
hours=tonumber(os.date('%H',time))
maintenant=tonumber(hours*60+minutes)
if(maintenant%10 ==0 )then
local appelTBH=assert(io.popen("php /home/pi/domoticz/scripts/php/capteur_meteo.php login MDG "))
local tempHyroTBH = appelTBH:read('*all')
appelTBH:close()
tempInt,hygroInt,tempExt,hygroExt = tempHyroTBH:match("([^;]+);([^;]+);([^;]+);([^;]+)")
print(tempInt.." "..hygroInt.." "..tempExt.." "..hygroExt)
--Ensuite remplissez votre commandArray avec les donnees recueillies :)
commandArray[1] = {['UpdateDevice'] = 28.. '|0|' .. tempInt..";"..hygroInt}
commandArray[2] = {['UpdateDevice'] = 29.. '|0|' .. tempExt..";"..hygroExt}
end
return commandArray
Code : Tout sélectionner
2015-12-01 20:59:00.198 Error: EventSystem: /home/pi/domoticz/scripts/lua/script_time_tbhweb_meteo.lua:18: malformed number near '28..'Code : Tout sélectionner
commandArray[1] = {['UpdateDevice'] = '28|0|' .. tempInt..";"..hygroInt}
commandArray[2] = {['UpdateDevice'] = '29|0|' .. tempExt..";"..hygroExt}Code : Tout sélectionner
<?php
///////////////////////////////////////////////
// Slush Coin Check
///////////////////////////////////////////////
if($argc == 3) {
$username = $argv[1];
$password = $argv[2];
} else {
die("Usage: username password\n");
}
///////////////////////////////////////////////
// Create the temporary cookie
///////////////////////////////////////////////
$cookiefile = tempnam("", "slush_");
///////////////////////////////////////////////
// Get CSRF
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/accounts/login/?next=/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='(.*?)' \/>/", $data, $csrf);
///////////////////////////////////////////////
// Login to Slush
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/accounts/login/?next=/";
$postfields = "csrfmiddlewaretoken=$csrf[1]&username=$username&password=$password";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
$data = curl_exec($curl);
curl_close($curl);
///////////////////////////////////////////////
// Visit earnings page
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/confort/data-confort-instantane";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
///////////////////////////////////////////////
// Capture current temperature
///////////////////////////////////////////////
try{
$temperature = json_decode($data, true);
if(isset($temperature['temp_int']) and isset($temperature['hygro_int']) and isset($temperature['temp_ext']) and isset($temperature['hygro_ext'])) {
echo $temperature['temp_int'] . ";" . $temperature['hygro_int'] . ";" . $temperature['temp_ext'] . ";" . $temperature['hygro_ext'];
} else {
echo null;
}
} catch(Exception $e){
echo($e);
}
///////////////////////////////////////////////
// Clean up cookie
///////////////////////////////////////////////
unlink($cookiefile);
?>Code : Tout sélectionner
commandArray[1] = {['UpdateDevice'] = '146|0|' ..tempInt..";"..hygroInt}
commandArray[2] = {['UpdateDevice'] = '147|0|' ..tempExt..";"..tempExt}Code : Tout sélectionner
?