array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$result = file_get_contents($request, false, stream_context_create($arrContextOptions));
$result = trim($result, "\r\n\t\0 {}");
$result = explode(",", $result);
$data = array();
//loop through split result
foreach($result as $row) {
//split again at ':'
$split = explode(":", $row);
//add key / value pair to result array
$data[trim($split[0], '"')] = trim($split[1], '"');
}
return $data;
}
function JUDO_LOGIN($username, $password) {
$res = JUDO_QUERY('group=register&command=login&msgnumber=2&name=login&user='.$username.'&password='.$password.'&role=customer');
if (!($res['status'] == 'error'))
return $res['token'];
return NULL;
}
function JUDO_CONNECT($token, $serialno) {
$res = JUDO_QUERY('group=register&command=connect&msgnumber=5&token='.$token.'¶meter=i-soft%20plus&serial%20number='.$serialno);
if (!($res['status'] == 'error'))
return true;
return false;
}
# Begin device interrogation
$JUDO_TOKEN = NULL;
# First, check if a token is saved
if (file_exists("./judo_token.txt")) {
$handle = fopen("./judo_token.txt", "r");
if (!feof($handle)) {
$JUDO_TOKEN = fgets($handle);
}
fclose($handle);
#echo('DEBUG: Found token "'.$JUDO_TOKEN.'"
');
}
# Try the token
if ($JUDO_TOKEN != NULL) {
#echo('DEBUG: Token present, testing...
');
$res = JUDO_SHOWDEVICES($JUDO_TOKEN);
#echo('DEBUG: SHOW response
');
#print_r($res);
if ($res == NULL) {
echo('DEBUG: Token bad, re-login necessary!
');
# Clear token file
unlink("./judo_token.txt");
# JUDO_LOGOUT($JUDO_TOKEN);
$JUDO_TOKEN = JUDO_LOGIN($JUDO_USERNAME, $JUDO_PASSWORD);
if (JUDO_CONNECT($JUDO_TOKEN, $JUDO_SERNO) == false) {
echo("Fehler: CONNECT fehlgeschlagen!");
exit();
}
#echo('DEBUG: New token "'.$JUDO_TOKEN.'"
');
}
}
else {
#echo('DEBUG: Logging in...
');
$JUDO_TOKEN = JUDO_LOGIN($JUDO_USERNAME, $JUDO_PASSWORD);
if (JUDO_CONNECT($JUDO_TOKEN, $JUDO_SERNO) == false) {
echo("Fehler: CONNECT fehlgeschlagen!");
exit();
}
#echo('DEBUG: New token "'.$JUDO_TOKEN.'"
');
}
if ($JUDO_TOKEN == NULL) {
echo("Fehler: Login war nicht möglich!");
exit();
}
# Try to connect using the token, if not connected try to reconnect.
# if (JUDO_CONNECT($JUDO_TOKEN, $JUDO_SERNO) == false) {
# echo("Fehler: CONNECT fehlgeschlagen!");
# exit();
# }
# Obviously, the connect must have performed well. Store the token...
$handle = fopen("judo_token.txt", "w");
fputs($handle, $JUDO_TOKEN);
fclose($handle);
# Now we are ready to query device data:
echo(time());
?>