Hey Guys,
made this little script with snippets that i found. In the comandline works the script fine if there is a Error, but as ShellSwitch pimatic will just say “timeout” or Pimatic is just switching it in without any trouble.
Here the Script:
#!/usr/bin/php
<?php
if(empty($argv[1]) or empty($argv[2])){
die("Arguments missing.");
}
// build URL with IP and the Command
// possible commands are for example: CLEAN_START, PAUSE, HOMING
$URL = "http://$argv[1]:6260/json.cgi?%7b%22COMMAND%22:%22$argv[2]%22%7d";
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
// options for errors
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
// grab URL and pass it to the browser
curl_exec($ch);
// grab Errors
if(curl_exec($ch) === false)
{
$error = curl_error($ch);
die("Error: $error");
curl_close($ch);
}
// close cURL resource, and free up system resources
curl_close($ch);
?>
I got this snippet form the Fritzbox Script from @Swen in his Script it works fine, i just added a 2nd Value
if(empty($argv[1]) or empty($argv[2])){
die("Arguments missing.");
}
If i give no Argument in his script i got this Message in Pimatic:
error [pimatic-shell-execute,ShellPresenceSensor]: Error getting attribute value windowsphone-short.presence: undefined
error [pimatic-shell-execute]: [ShellPresenceSensor#windowsphone-short] Error: unknown state="Arguments missing."!
Here my tests in the commandline:
pi@Leetwerkberry:~ $ ./testphp.php
Arguments missing.
pi@Leetwerkberry:~ $ ./testphp.php 192.178.168.60
Arguments missing.
pi@Leetwerkberry:~ $ ./testphp.php 192.178.168.60 START_CLEAN
Error: Connection timed out after 5001 millisecondsp