With some time and effort i have found a way to switch circles with the Strech 2.0 directly, so you can make your own software to switch stuff! there is NO Plugwise software required for these scripts!
I've posted a PHP and Autoit3 example of how to do it!, enjoy!
PHP (dutch): http://phoenixinteractive.mine.nu/websi ... f=27&t=116
Autoit3 (dutch): http://phoenixinteractive.mine.nu/websi ... f=27&t=117
Comments:
PHP script: The PHP window doesn't close after switching
Autoit script: A messagebox will popup if the response <> 200 HTTP OK so you can see the error
If you have any improvements!, let us know!
PHP code:
Code: Select all
<?php
// A PHP script to switch Plugwise Circles with a Stretch 2.0 (tested on firmware 1.0.40)
// v1.0, 2013-04-28 by Sebastiaan Ebeltjes
// Greetings from Deventer, The Netherlands
// Stretch 2.0 setup
$StretchIp = "192.168.1.102"; //The IP adres of the Stretch 2.0, like: 192.168.1.X
$StretchId = "STRETCHID"; //The 8 letters of the Stretch 2.0 ID
// Switch setup (circle)
$ApplianceId = "71abf031c54f400ca77c8ae6957ad7cf"; // The ID of the circle, look in http://[STRETCHIP]/minirest/appliances
$SwitchStatus = "on"; // on/off
// Kernel
$AuthBase64 = base64_encode("stretch:".$StretchId);
$HTTPHandle = fsockopen($StretchIp, 80, $errno, $errstr, 30);
if (!$HTTPHandle) {
echo "$errstr ($errno)<br />\n";
} else {
$Data = "POST /minirest/appliances;id=".$ApplianceId."/power_state=".$SwitchStatus." HTTP/1.1\r\n";
$Data .= "Host: ".$StretchIp."\r\n";
$Data .= "Authorization: Basic ".$AuthBase64."\r\n";
$Data .= "\r\n";
fwrite($HTTPHandle, $Data);
while (!feof($HTTPHandle)) {
echo fgets($HTTPHandle, 128);
}
fclose($HTTPHandle);
}
?>
Code: Select all
; ------------------------------------------------------------------------------
; Autoit3 script to switch Plugwise Circles with a Stretch 2.0 (tested on firmware 1.0.40)
; v1.0, 2013-04-28 by Sebastiaan Ebeltjes
; Greetings from Deventer, The Netherlands
; ------------------------------------------------------------------------------
; Stretch 2.0 setup
Global $StretchIp = "192.168.1.102" ;The IP adres of the Stretch 2.0, like: 192.168.1.X
Global $StretchId = "STRETCHID" ;The 8 letters of the Stretch 2.0 ID
; Switch setup (circle)
Global $ApplianceId = "71abf031c54f400ca77c8ae6957ad7cf" ;The ID of the circle, look in http://[STRETCHIP]/minirest/appliances
Global $SwitchStatus = "on" ;on/off
; Kernel
Global $PostAdres = "http://" & $StretchIp & "/minirest/appliances;id=" & $ApplianceId & "/power_state=" & $SwitchStatus
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $PostAdres, False)
$oHTTP.SetRequestHeader("Host", $StretchIp)
$oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchId))
$oHTTP.Send()
Global $PostResponse = $oHTTP.ResponseText
If $oHTTP.Status <> "200" Then MsgBox(64, "Foutmelding", $PostResponse)
Exit
; Functie voor BASE64 Encoding
Func _Base64Encode($sData)
Local $oXml = ObjCreate("Msxml2.DOMDocument")
If Not IsObj($oXml) Then
SetError(1, 1, 0)
EndIf
Local $oElement = $oXml.createElement("b64")
If Not IsObj($oElement) Then
SetError(2, 2, 0)
EndIf
$oElement.dataType = "bin.base64"
$oElement.nodeTypedValue = Binary($sData)
Local $sReturn = $oElement.Text
If StringLen($sReturn) = 0 Then
SetError(3, 3, 0)
EndIf
Return $sReturn
EndFunc