Bonjour,
J’essaye de faire comme sur ce sujet : Traiter le retour d'un script curl , à savoir récupérer sur le site Giwits les données de mon api.
J’ai donc modifié le script avec mon token et mon appid, et rajouté le
$obj['attr']['mode']
de @jpty
J’ai créé un script dans le plugin, je reçois bien mon texte imbuvable avec mes 6 appareils et toutes les infos, tout d’une traite. J’ai donc essayé de créer un scénario avec un bloc CODE, avec le script de @dkvince mais j’ai un retour dans les logs du scénario qui dit :
[2020-09-13 15:39:26][SCENARIO] Start : Scenario lance manuellement.
[2020-09-13 15:39:26][SCENARIO] Exécution du sous-élément de type [action] : code
[2020-09-13 15:39:26][SCENARIO] Exécution d'un bloc code
[2020-09-13 15:39:26][SCENARIO] syntax error, unexpected ';', expecting ')'
[2020-09-13 15:39:26][SCENARIO] Fin correcte du scénario
J’ai essayé d’enlever les " du curl mais du coup j’ai le message :
[2020-09-13 15:39:26][SCENARIO] Start : Scenario lance manuellement.
[2020-09-13 15:39:26][SCENARIO] Exécution du sous-élément de type [action] : code
[2020-09-13 15:39:26][SCENARIO] Exécution d'un bloc code
[2020-09-13 15:39:26][SCENARIO] syntax error, unexpected ';', expecting ')'
[2020-09-13 15:39:26][SCENARIO] Fin correcte du scénario
Mon script :
$json = system("curl -X GET --header 'Accept: application/json' --header 'X-Gizwits-User-token:101434532ac1445a956ea1678b8a8f12' --header 'X-Gizwits-Application-Id:5c9b45e1d7684d9c883a0425644feccd' 'https://euapi.gizwits.com/app/bindings?limit=20&skip=0'";);
$json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json);
if (!empty($json))
{
$findme = 'did';
$pos = strpos($json, $findme);
if ($pos === false)
{
$scenario->setLog('Erreur de retour de la fonction CURL, la fonction renvoi : ' .$json);
}
else
{
$obj = json_decode($json, TRUE);
if (json_last_error() === JSON_ERROR_NONE)
{
$did = $obj['did'];
$scenario->setLog('device_id_1: ' , $did);
$scenario->setData('device_did_1: ' , $did);
$updated_at = $obj['updated_at'];
$scenario->setLog('updated_at_1: ' , $updated_at);
$scenario->setData('updated_at_1': ' , $updated_at);
$obj['attr']['mode'];
$b=1;
foreach ($Infos_devices as $a)
{
$scenario->setData("dev_alias_".$b, $a['dev_alias']);
$scenario->setData("time_week_".$b, $a['time_week']);
$scenario->setData("mode_".$b, $a['mode']);
$scenario->setData("time_hour_".$b, $a['time_hour']);
$scenario->setData("lock_switch_".$b, $a['lock_switch']);
$scenario->setData("timer_switch_".$b, $a['timer_switch']);
$scenario->setData("boost_time_".$b, $a['boost_time']);
$scenario->setData("boost_switch_".$b, $a['boost_switch']);
$scenario->setData("derog_time_".$b, $a['derog_time']);
$scenario->setData("p7_data12_".$b, $a['p7_data12']);
b++;
}
}
}
}
else
{
$scenario->setLog('Erreur json est : ' . $json_errors[json_last_error()]);
}
Je n’ai pas modifier encore les setdata pour avoir les miennes car j’ai besoin d’autres informations, mais je le ferais après.
Pour info, mon retour est sous cette forme (là il n’y a que 2 appareils):
{"devices": [{"protoc": 3, "ws_port": 8080, "port_s": 8883, "is_disabled": false, "gw_did": null, "wifi_soft_version": "04020826", "dev_alias": "", "mesh_id": null, "is_online": false, "host": "eum2m.gizwits.com", "sleep_duration": 0, "dev_label": [], "port": 1883, "remark": "1", "did": "5Dp3fihNrk2MKAtnMV", "mac": "d8bfcc199c7", "product_key": "f0d844ab0d4947ac95276160c705", "wss_port": 8880, "state_last_timestamp": 15973073, "role": "special", "is_sandbox": false, "passcode": "BASMDVRF", "type": "normal", "product_name": "\u672c\u5730\u9020\u6d6a\u6cf5", "is_low_power": false}, {"protoc": 3, "ws_port": 8080, "port_s": 8883, "is_disabled": false, "gw_did": null, "wifi_soft_version": "04020826", "dev_alias": "", "mesh_id": null, "is_online": false, "host": "eum2m.gizwits.com", "sleep_duration": 0, "dev_label": [], "port": 1883, "remark": "1", "did": "GZZoHHab5tJg4zUsF9", "mac": "98fd056d1", "product_key": "f0d844ab0d4947ac95286160bc705", "wss_port": 8880, "state_last_timestamp": 15923079, "role": "special", "is_sandbox": false, "passcode": "FVBIIPW", "type": "normal", "product_name": "\u672c\u5730\u9020\u6d6a\u6cf5", "is_low_power": false}]}
Si quelqu’un peut m’aiguiller. Merci.