Page 10 sur 19

Re: Projet TBH

Publié : 30 nov. 2015, 22:22
par deennoo
C'est pas un script payant ?? Tu casses le marché !! Lol

Re: Projet TBH

Publié : 01 déc. 2015, 19:43
par Neutrino
T'as raison, je devrais le mettre sur le market de domoticz et le faire payer.... Mince, tout est gratuit ici :mrgreen:
@slybreiz, il faut créer des capteurs virtuels de type température + humidité.
ensuite tu envoies les données avec un truc genre :

Code : Tout sélectionner

commandArray[1] = {['UpdateDevice'] = IDXdeTonCapteur.. '|0|' .. TEMP..";"..HYGRO}

Re: Projet TBH

Publié : 01 déc. 2015, 21:01
par slybreiz
merci

j'ai donc rajouter :

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..'

Re: Projet TBH

Publié : 01 déc. 2015, 21:18
par mich423
Bonsoir,
J'essaie de récupérer la température et humidité intérieure et extérieure, j'ai l'erreur suivante:

unexpected symbol near ')'

Voici mon script, pouvez vous m'aider. Merci.

commandArray = {}

-- Time to run?

time = os.date("*t")

if ((time.hour == 7 or time.hour == 11 or time.hour == 15 or time.hour == 19 or time.hour == 23) and time.min == 00) then

local appelTBH=assert(io.popen("php /home/pi/domoticz/scripts/tbhweb.php"))

local tempHyroTBH = appelTBH:read('*all')
appelTBH:close()
tempInt,hygroInt,tempExt,hygroExt = tempHyroTBH:match("([^;]+);([^;]+);([^;]+);([^;]+)")
print(tempInt.." "..hygroInt.." "..tempExt.." "..tempExt..)
--Ensuite remplissez votre commandArray avec les données recueillies :)
commandArray[1] = {['UpdateDevice'] = 146 '|0|' tempInt..";"..hygroInt..}
commandArray[2] = {['UpdateDevice'] = 147 '|0|' ..tempExt..";"..tempExt..}
end
return commandArray

Re: Projet TBH

Publié : 01 déc. 2015, 21:26
par Neutrino
J'aime bien ne pas donner des scripts complets, ça permet au gens de faire des erreurs et d'apprendre ;)


@slybreik

Code : Tout sélectionner

commandArray[1] = {['UpdateDevice'] = '28|0|' .. tempInt..";"..hygroInt}

commandArray[2] = {['UpdateDevice'] = '29|0|' .. tempExt..";"..hygroExt}
@mich423
il manque ton login et mot de passe (mais c'est peut-être fait exprès), ensuite, regarde la réponse ci-dessus :)
les .. servent à assembler 2 chaînes, donc finir par hygroExt.. ne marchera pas.

Re: Projet TBH

Publié : 01 déc. 2015, 21:53
par mich423
Bonsoir,

merci, je viens de modifier comme ceci (pour le login et mot de passe, c'est fait exprès ), toujours la même erreur, voici mon script complet

commandArray = {}

-- Time to run?

time = os.date("*t")

if ((time.hour == 7 or time.hour == 11 or time.hour == 15 or time.hour == 19 or time.hour == 23) and time.min == 00) then

local appelTBH=assert(io.popen("php /home/pi/domoticz/scripts/tbhweb.php login mot_de_passe"))

local tempHyroTBH = appelTBH:read('*all')
appelTBH:close()
tempInt,hygroInt,tempExt,hygroExt = tempHyroTBH:match("([^;]+);([^;]+);([^;]+);([^;]+)")
print(tempInt.." "..hygroInt.." "..tempExt.." "..tempExt..)
--Ensuite remplissez votre commandArray avec les données recueillies :)
commandArray[1] = {['UpdateDevice'] = 146 '|0|' ..tempInt..";"..hygroInt}
commandArray[2] = {['UpdateDevice'] = 147 '|0|' ..tempExt..";"..tempExt}
end
return commandArray

et l'erreur:

unexpected symbol near ')'

Re: Projet TBH

Publié : 01 déc. 2015, 21:57
par Neutrino
Nouvelle version du script tbhweb.php pour prendre en compte les rupture de synchro entre la tablette et leur serveurs :

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);
?>
Ensuite pour mich423:

Code : Tout sélectionner

commandArray[1] = {['UpdateDevice'] = '146|0|' ..tempInt..";"..hygroInt}
commandArray[2] = {['UpdateDevice'] = '147|0|' ..tempExt..";"..tempExt}

Re: Projet TBH

Publié : 01 déc. 2015, 22:00
par slybreiz
Ok merci

Oui le login MDP fait exprès .

Oui je comprend mieux maintenant ça permet d apprendre .:-)

Re: Projet TBH

Publié : 01 déc. 2015, 22:12
par mich423
Désolé,
même avec tes modifications, toujours la même erreur

unexpected symbol near ')'

Re: Projet TBH

Publié : 01 déc. 2015, 22:17
par Neutrino
Peux-tu donner l'erreur complète et mettre tout ton script entre des balises