Aller au contenu

Problème Avec Json.decode En V3.6 Puis En V4


CASINOS

Messages recommandés

Bonjour

J'avais créer des Modules virtuel avec mes stations NetAtmo dont j'avais trouvé la source sur ce site il y a très longtemps

Après des problèmes de santé ou j'avais laissé tombé le suivi de ma HC2, j'ai mis HC2 a jour en 3.6 et plus rien ne marche

fibaro:debug("HC2 start script at " .. os.date());

FHTE = Net.FHttp ("www.monserveur.fr")
response = FHTE:GET("/monfichierserveur/netatmo-home-center-2.php?intext=ext")
  result = json.decode (response)

fibaro:setGlobal("NetTempExt", result.body[1].value[1][1]);
fibaro:setGlobal("NetHumExt", result.body[1].value[1][2]);


NetTempExt = fibaro:getGlobalValue("NetTempExt").. " °C "
NetHumExt = fibaro:getGlobalValue("NetHumExt").. " % "

fibaro:call(137, "setProperty", "ui.Label1.value", NetTempExt);
fibaro:call(137, "setProperty", "ui.Label8.value", NetHumExt);


et en debug j'ai comme message

 [DEBUG] 09:41:20: HC2 start script at Fri Mar 6 09:41:20 2015
[ERROR] 09:41:21: line 6: Expected value but found T_END at character 1

Le php que j'ai mis sur mon serveur pour le NetAmo du bureau qui est mon 30 modules NetAtmo

<?php


// Script développé par Cédric Locqueneux 
// adaptation par Zebk pour envoi data en JSON pour Fibaro HC2

$intext=$_GET['intext'];
$password="PASSWORD";
$username="USERNAME";


$app_id = "XXXXXXXXXXXXXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$token_url = "https://api.netatmo.net/oauth2/token";
$postdata = http_build_query(
        array(
            'grant_type' => "password",
            'client_id' => $app_id,
            'client_secret' => $app_secret,
            'username' => $username,
            'password' => $password
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);
$response = file_get_contents($token_url, false, $context);

$params = null;
$params = json_decode($response, true);
$api_url = "https://api.netatmo.net/api/getuser?access_token=" . $params['access_token'];
$requete = file_get_contents($api_url);

$url_devices = "https://api.netatmo.net/api/devicelist?access_token=" .  $params['access_token'];
$resulat_device = file_get_contents($url_devices);  
$json_devices = json_decode($resulat_device,true);
$module_interne = $json_devices["body"]["devices"][0]["_id"];
$module_externe = $json_devices["body"]["modules"][3]["_id"];
    
$url_mesures_internes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&scale=max&type=Temperature,CO2,Humidity,Pressure,Noise&date_end=last";
$mesures_internes = file_get_contents($url_mesures_internes);

$url_mesures_externes = "https://api.netatmo.net/api/getmeasure?access_token=" .  $params['access_token'] . "&device_id=" . $module_interne . "&module_id=" . $module_externe . "&scale=max&type=Temperature,CO2,Humidity&date_end=last";
$mesures_externes = file_get_contents($url_mesures_externes);   
    
if ($intext == "int") 
echo $mesures_internes ;
else echo $mesures_externes ;

?>

Avez vous une idée de ce qui aurait changé en V3.6 et n'étant pas encore passé en V4.03X que faudra t-il faire ensuite en V4

 

Merci de votre aide

Lien vers le commentaire
Partager sur d’autres sites

@CASINOS

J'avoue avoir survolé ton post, mais j'ai remarqué le T_END dans le debug ... problème Json ou problèmes Netatmo ? (il me semble que Netatmo a eu des problèmes ce matin ?)

Bref, je te donne le lien suivant

Tu verras comment @Krikroff règle ce problème dans le main loop

Lien vers le commentaire
Partager sur d’autres sites

Bon j'ai regardé ton code php et je ne vois pas d'erreur àpremière vue, mais n'ayant pas de station Netatmo je ne peux pas pousser plus loin l'analyse. Essaye de voir avec une personne qui utilise l'API Netatmo. Peux tu placer un var_dump ($json_devices); aprés la ligne 45 et lancer dans ton navigateur : monfichierserveur/netatmo-home-center-2.php?intext=ext

Lien vers le commentaire
Partager sur d’autres sites

Bonjour Nettrust

Je viens de mettre la ligne Var , et voici ce que j'obtiens , sachant que sans je n'avais rien , mais j'avoue ne rien y comprendre

Merci pour ton aide

array(4) { ["status"]=> string(2) "ok" ["body"]=> array(2) { ["modules"]=> array(10) { [0]=> array(11) { ["_id"]=> string(17) "02:00:00:00:22:8c" ["main_device"]=> string(17) "70:ee:50:00:22:d4" ["module_name"]=> string(10) "Terrasse-S" ["type"]=> string(9) "NAModule1" ["firmware"]=> int(41) ["last_message"]=> int(1426182164) ["last_seen"]=> int(1426182138) ["rf_status"]=> int(79) ["battery_vp"]=> int(5906) ["dashboard_data"]=> array(7) { ["time_utc"]=> int(1426182138) ["Temperature"]=> float(14.9) ["Humidity"]=> int(58) ["date_max_temp"]=> int(1426158660) ["date_min_temp"]=> int(1426116625) ["min_temp"]=> float(13.7) ["max_temp"]=> int(17) } ["data_type"]=> array(2) { [0]=> string(11) "Temperature" [1]=> string(8) "Humidity" } } [1]=> array(11) { ["_id"]=> string(17) "03:00:00:00:17:c2" ["main_device"]=> string(17) "70:ee:50:00:22:d4" ["module_name"]=> string(7) "Chambre" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182164) ["last_seen"]=> int(1426182158) ["rf_status"]=> int(72) ["battery_vp"]=> int(4615) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182106) ["Temperature"]=> float(21.1) ["Humidity"]=> int(45) ["CO2"]=> int(615) ["date_max_temp"]=> int(1426150887) ["date_min_temp"]=> int(1426165907) ["min_temp"]=> float(20.9) ["max_temp"]=> float(21.6) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [2]=> array(11) { ["_id"]=> string(17) "03:00:00:00:1d:8e" ["main_device"]=> string(17) "70:ee:50:00:22:d4" ["module_name"]=> string(10) "Terrasse-N" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182164) ["last_seen"]=> int(1426182126) ["rf_status"]=> int(86) ["battery_vp"]=> int(4730) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182126) ["Temperature"]=> float(13.3) ["Humidity"]=> int(63) ["CO2"]=> int(504) ["date_max_temp"]=> int(1426167106) ["date_min_temp"]=> int(1426114824) ["min_temp"]=> int(11) ["max_temp"]=> float(14.9) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [3]=> array(11) { ["_id"]=> string(17) "03:00:00:00:1b:1e" ["main_device"]=> string(17) "70:ee:50:00:22:d4" ["module_name"]=> string(7) "Cuisine" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182164) ["last_seen"]=> int(1426182158) ["rf_status"]=> int(72) ["battery_vp"]=> int(5141) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182106) ["Temperature"]=> float(21.3) ["Humidity"]=> int(40) ["CO2"]=> int(522) ["date_max_temp"]=> int(1426117822) ["date_min_temp"]=> int(1426163498) ["min_temp"]=> float(21.2) ["max_temp"]=> float(22.1) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [4]=> array(11) { ["_id"]=> string(17) "05:00:00:00:7b:4e" ["main_device"]=> string(17) "70:ee:50:00:22:d4" ["module_name"]=> string(12) "Pluviomètre" ["type"]=> string(9) "NAModule3" ["firmware"]=> int(5) ["last_message"]=> int(1426182164) ["last_seen"]=> int(1426182164) ["rf_status"]=> int(91) ["battery_vp"]=> int(4970) ["dashboard_data"]=> array(4) { ["time_utc"]=> int(1426182151) ["Rain"]=> int(0) ["sum_rain_24"]=> int(0) ["sum_rain_1"]=> int(0) } ["data_type"]=> array(1) { [0]=> string(4) "Rain" } } [5]=> array(11) { ["_id"]=> string(17) "02:00:00:00:0f:4e" ["main_device"]=> string(17) "70:ee:50:00:0c:dc" ["module_name"]=> string(8) "TERRASSE" ["type"]=> string(9) "NAModule1" ["firmware"]=> int(41) ["last_message"]=> int(1426182641) ["last_seen"]=> int(1426182634) ["rf_status"]=> int(64) ["battery_vp"]=> int(4983) ["dashboard_data"]=> array(7) { ["time_utc"]=> int(1426182583) ["Temperature"]=> int(14) ["Humidity"]=> int(52) ["date_max_temp"]=> int(1426171766) ["date_min_temp"]=> int(1426144955) ["min_temp"]=> float(6.5) ["max_temp"]=> float(15.6) } ["data_type"]=> array(2) { [0]=> string(11) "Temperature" [1]=> string(8) "Humidity" } } [6]=> array(11) { ["_id"]=> string(17) "03:00:00:00:04:04" ["main_device"]=> string(17) "70:ee:50:00:0c:dc" ["module_name"]=> string(7) "CUISINE" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182641) ["last_seen"]=> int(1426182634) ["rf_status"]=> int(56) ["battery_vp"]=> int(5041) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182583) ["Temperature"]=> float(23.4) ["Humidity"]=> int(24) ["CO2"]=> int(500) ["date_max_temp"]=> int(1426144033) ["date_min_temp"]=> int(1426129577) ["min_temp"]=> float(23.1) ["max_temp"]=> float(23.9) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [7]=> array(11) { ["_id"]=> string(17) "03:00:00:00:14:a0" ["main_device"]=> string(17) "70:ee:50:00:0c:dc" ["module_name"]=> string(7) "CHAMBRE" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182641) ["last_seen"]=> int(1426182635) ["rf_status"]=> int(77) ["battery_vp"]=> int(5007) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182583) ["Temperature"]=> float(22.3) ["Humidity"]=> int(29) ["CO2"]=> int(419) ["date_max_temp"]=> int(1426114813) ["date_min_temp"]=> int(1426140701) ["min_temp"]=> float(21.9) ["max_temp"]=> float(22.9) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [8]=> array(11) { ["_id"]=> string(17) "03:00:00:00:03:f6" ["main_device"]=> string(17) "70:ee:50:00:0c:dc" ["module_name"]=> string(6) "BUREAU" ["type"]=> string(9) "NAModule4" ["firmware"]=> int(41) ["last_message"]=> int(1426182641) ["last_seen"]=> int(1426182635) ["rf_status"]=> int(67) ["battery_vp"]=> int(5068) ["dashboard_data"]=> array(8) { ["time_utc"]=> int(1426182583) ["Temperature"]=> float(22.7) ["Humidity"]=> int(27) ["CO2"]=> int(610) ["date_max_temp"]=> int(1426182327) ["date_min_temp"]=> int(1426140701) ["min_temp"]=> float(22.1) ["max_temp"]=> float(22.7) } ["data_type"]=> array(3) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" } } [9]=> array(11) { ["_id"]=> string(17) "05:00:00:00:0e:a4" ["main_device"]=> string(17) "70:ee:50:00:0c:dc" ["module_name"]=> string(12) "Pluviomètre" ["type"]=> string(9) "NAModule3" ["firmware"]=> int(5) ["last_message"]=> int(1426182641) ["last_seen"]=> int(1426182641) ["rf_status"]=> int(67) ["battery_vp"]=> int(5628) ["dashboard_data"]=> array(4) { ["time_utc"]=> int(1426182628) ["Rain"]=> int(0) ["sum_rain_24"]=> float(0.101) ["sum_rain_1"]=> int(0) } ["data_type"]=> array(1) { [0]=> string(4) "Rain" } } } ["devices"]=> array(2) { [0]=> array(22) { ["_id"]=> string(17) "70:ee:50:00:0c:dc" ["access_code"]=> string(12) "NUcvukSMYjUu" ["alarm_config"]=> array(2) { ["default_alarm"]=> array(7) { [0]=> array(1) { ["db_alarm_number"]=> int(0) } [1]=> array(1) { ["db_alarm_number"]=> int(1) } [2]=> array(1) { ["db_alarm_number"]=> int(2) } [3]=> array(1) { ["db_alarm_number"]=> int(6) } [4]=> array(1) { ["db_alarm_number"]=> int(4) } [5]=> array(1) { ["db_alarm_number"]=> int(5) } [6]=> array(1) { ["db_alarm_number"]=> int(7) } } ["personnalized"]=> array(3) { [0]=> array(4) { ["threshold"]=> int(1500) ["data_type"]=> int(3) ["direction"]=> int(0) ["db_alarm_number"]=> int(12) } [1]=> array(4) { ["threshold"]=> int(20) ["data_type"]=> int(1) ["direction"]=> int(0) ["db_alarm_number"]=> int(8) } [2]=> array(4) { ["threshold"]=> int(60) ["data_type"]=> int(1) ["direction"]=> int(0) ["db_alarm_number"]=> int(8) } } } ["battery_vp"]=> int(0) ["cipher_id"]=> string(71) "enc:16:FYdCf7S7CX9PLE1Lh9fK4UfOE4VHFT6O6HbgIyTLdzW32by7wyd8w7HiSFQkzr6i" ["co2_calibrating"]=> bool(false) ["date_setup"]=> array(2) { ["sec"]=> int(1359763200) ["usec"]=> int(0) } ["firmware"]=> int(96) ["friend_users"]=> array(2) { [0]=> string(24) "515ca67f197759648200000b" [1]=> string(24) "509a54001877592404000c39" } ["invitation_disable"]=> bool(false) ["last_status_store"]=> int(1426182645) ["last_upgrade"]=> int(1398527504) ["meteo_alarms"]=> array(1) { [0]=> array(13) { ["_id"]=> array(1) { ["$id"]=> string(24) "54f5cf291b7759e7738b4585" } ["area"]=> string(24) "Paris et Petite Couronne" ["begin"]=> int(1425391200) ["end"]=> int(1425477600) ["title"]=> string(29) "__MA_ALARM_THUNDERSTORM_TITLE" ["type"]=> string(18) "ALARM_THUNDERSTORM" ["text_field"]=> string(31) "__MA_ALARM_THUNDERSTORM_LEVEL_1" ["level"]=> int(1) ["descr"]=> string(903) "%lng="fr_FR" %lf Des phénomènes habituels dans la région mais occasionnellement et localement dangereux sont prévus %lf (ex. mistral, orage d’été, montée des eaux, fortes vagues submergeant le littoral)%lf %lf %ib %lf Soyez attentifs; si vous pratiquez des activitéssensibles au risque météorologique ou àproximité d'un rivage ou d'un cours d'eau; tenez-vous au courant de l’évolution de la situation.%lf %lf%ie %lng="en_UK" %lf Although rather usual in this region, locally or potentially dangerous phenomena are expected. (such as local winds, summer thunderstorms, rising streams or high waves) %lf %lf %ib %lf Be aware and pay attention to the latest weather updates, especially if you carry out activities exposed to weather or close to a stream or shoreline. %lf %lf%ie" ["status"]=> string(3) "new" ["alarm_id"]=> int(173037) ["time_generated"]=> int(1425395497) ["origin"]=> string(10) "meteoalarm" } } ["module_name"]=> string(5) "SALON" ["modules"]=> array(5) { [0]=> string(17) "02:00:00:00:0f:4e" [1]=> string(17) "03:00:00:00:04:04" [2]=> string(17) "03:00:00:00:14:a0" [3]=> string(17) "03:00:00:00:03:f6" [4]=> string(17) "05:00:00:00:0e:a4" } ["place"]=> array(6) { ["altitude"]=> int(29) ["city"]=> string(9) "Asnières" ["country"]=> string(2) "FR" ["geoip_city"]=> string(13) "Bois-colombes" ["location"]=> array(2) { [0]=> float(2.2849200000001) [1]=> float(48.92261) } ["timezone"]=> string(12) "Europe/Paris" } ["service"]=> array(1) { ["meteo_alarm"]=> bool(true) } ["station_name"]=> string(5) "92600" ["type"]=> string(6) "NAMain" ["wifi_status"]=> int(54) ["dashboard_data"]=> array(11) { ["AbsolutePressure"]=> int(1021) ["time_utc"]=> int(1426182631) ["Noise"]=> int(37) ["Temperature"]=> int(22) ["Humidity"]=> int(24) ["Pressure"]=> float(1024.5) ["CO2"]=> int(460) ["date_max_temp"]=> int(1426114838) ["date_min_temp"]=> int(1426142861) ["min_temp"]=> float(21.7) ["max_temp"]=> float(22.2) } ["data_type"]=> array(5) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" [3]=> string(5) "Noise" [4]=> string(8) "Pressure" } } [1]=> array(18) { ["_id"]=> string(17) "70:ee:50:00:22:d4" ["battery_vp"]=> int(0) ["cipher_id"]=> string(71) "enc:16:6ertH3ZtsPWaSDRLb79q3dRuY4YgFb8K7WwGndUHCFMkofW/QCCWrQoenMojSKtW" ["co2_calibrating"]=> bool(false) ["date_setup"]=> array(2) { ["sec"]=> int(1359763200) ["usec"]=> int(0) } ["firmware"]=> int(96) ["invitation_disable"]=> bool(false) ["last_status_store"]=> int(1426182166) ["last_upgrade"]=> int(1402754143) ["module_name"]=> string(5) "Salon" ["modules"]=> array(5) { [0]=> string(17) "02:00:00:00:22:8c" [1]=> string(17) "03:00:00:00:17:c2" [2]=> string(17) "03:00:00:00:1d:8e" [3]=> string(17) "03:00:00:00:1b:1e" [4]=> string(17) "05:00:00:00:7b:4e" } ["place"]=> array(6) { ["altitude"]=> int(78) ["city"]=> string(6) "Cannes" ["country"]=> string(2) "FR" ["geoip_city"]=> string(6) "Cannes" ["location"]=> array(2) { [0]=> float(7.04421) [1]=> float(43.55123) } ["timezone"]=> string(12) "Europe/Paris" } ["station_name"]=> string(6) "Cannes" ["type"]=> string(6) "NAMain" ["wifi_status"]=> int(45) ["read_only"]=> bool(true) ["dashboard_data"]=> array(11) { ["AbsolutePressure"]=> int(1015) ["time_utc"]=> int(1426182152) ["Noise"]=> int(38) ["Temperature"]=> float(21.7) ["Humidity"]=> int(39) ["Pressure"]=> float(1024.4) ["CO2"]=> int(563) ["date_max_temp"]=> int(1426114844) ["date_min_temp"]=> int(1426163514) ["min_temp"]=> float(21.4) ["max_temp"]=> float(22.9) } ["data_type"]=> array(5) { [0]=> string(11) "Temperature" [1]=> string(3) "CO2" [2]=> string(8) "Humidity" [3]=> string(5) "Noise" [4]=> string(8) "Pressure" } } } } ["time_exec"]=> float(0.066296100616455) ["time_server"]=> int(1426182725) } 
Lien vers le commentaire
Partager sur d’autres sites

Bon pas evident car je ne peux pas tester en direct ajoute un "echo $module_interne.'<br>'.$module_externe;" aprés la ligne 48 et lance dans ton navigateur : monfichierserveur/netatmo-home-center-2.php?intext=ext

"

Lien vers le commentaire
Partager sur d’autres sites

J'ai fait la modif

 

si je lance monfichierserveur/netatmo-home-center-2.php

>>>

70:ee:50:00:0c:dc
03:00:00:00:1b:1e

 

 

si je lance monfichierserveur/netatmo-home-center-2.php?intext=ext

>>>

70:ee:50:00:0c:dc
03:00:00:00:1b:1e

 

soit IDEM

 

Mais si je lance monfichierserveur/netatmo-home-center-2.php?intext=int

70:ee:50:00:0c:dc
03:00:00:00:1b:1e{"status":"ok","body":[{"beg_time":1427446954,"value":[[21.5,411,31,1023.9,38]]}],"time_exec":0.11394810676575,"time_server":1427447403}

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...