Plugwise Stretch 2.0 – Commandline interface
Ik heb een programma in elkaar gezet voor het schakelen via de commandline van de PlugWise Circles met de Stretch 2.0. Zodoende kun je je eigen programma’s gebruiken (bijvoorbeeld excel, phpscript of homeseer) en zo een “shell” command gebruiken om je PlugWise Circles te schakelen zonder daar enige programeer kennis voor nodig te hebben.
Getest en werkend op:
– Windows XP 32-bit
– Windows Vista/7/8 32/64-bit
* Werkt niet op Windows 95 / 98 / ME i.v.m. unicode compile.
* Werkt niet op Windows Server 2000 (crash)
Het gebruik van dit programma is als volgt: PWScli.exe switch [stretchIP] [stretchID] [applianceID/CircleNaam] [on/off]
[stretchIP] = Het IP adres van de Stretch 2.0
[stretchID] = De Stretch 2.0 ID code (8 letters)
[applianceID/CircleNaam] = De 32 karakters van het ApplianceID, of de naam van een Circle
[on/off] = Schakel de circle aan of uit
Schakel voorbeelden
Schakelt een circle met de juiste applianceID aan, via de Stretch 2.0 op IP adres 192.168.1.101
PWScli.exe switch 192.168.1.101 abcdefgh 71abf031c54f400ca77c8ae6957ad7cf on
Schakelt een circle met de naam “woonkamer” uit, via the Stretch 2.0 on IP adres 192.168.1.101
PWScli.exe switch 192.168.1.101 abcdefgh woonkamer off
Screens
1 2 3 4 5 6 7 8 9 10 11 12 |
[7adf2ef4b16b41ffad98eb9d] name=keuken state=off power=0 [71abf031c54f400ca77c8ae6] name=keukentafel state=off power=0 [2ef525453c764b2db87061ad] name=logeerkamer state=off power=0 |
Informatie
CHANGELOG:
v2.1 (2013-10-17)
– Bug opgelost met het achterhalen van het verbruik van de Circles.
– Men kan nu ook schakelen op een naam van een Circle.
v2.0 (2013-10-10)
– Programma aangepast voor stretch 2.0 met firmware 2.0.x
– Let op: Deze versie is niet compatible met een stretch met firmware 1.0.x
v1.2 (2013-05-05)
– ApplianceID en StetchID zijn case sensitive, de input wordt nu altijd naar lowercase geconverteerd!
– De check’s voor de applist waren in de vorige versie niet aanwezig, deze zijn nu toegevoegd!
– Ingebouwde mode om een lijst weer te geven uitgebreid met status en vermogen.
– Dump van ApplianceID’s, status en vermogens mogelijk naar txt of ini bestand!
v1.1 (2013-05-04)
– True CLi mode (geen messageboxes meer, alles nu naar de prompt)
– Ingebouwde mode om een lijst weer te geven met de namen en de daarbijbehorende appliance codes
– Statusweergave bij het schakelen van een Circle
– Alles naar het Engels geconverteerd.
Voor contact, melden van bugs of verbeterideeen etc. kun je mij mailen.
PWcli door Sebastiaan Ebeltjes
DISCLAIMER:
* Het gebruik van dit programma is op eigen risico!, de auteur is niet verantwoordelijk voor enige schade aan apparaten en computer door gebruik van dit programma!
* Plugwise heeft niets met ‘PWScli.exe’ te maken, en zal elke verantwoordelijkheid afwijzen.
* Het PlugWise logo is en blijft eigendom van http://www.plugwise.com
Download
Download PWScli v2.1 voor Stretch 2.0 met firmware 2.0.x (zie onderaan deze pagina)
Download PWScli v1.2 voor Stretch 2.0 met firmware 1.0.x (zie onderaan deze pagina)
PWScli v2.1 (voor stretch 2.0 met firmware 2.0.x) source:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=PWScli.ico #AutoIt3Wrapper_outfile=PWScli.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Comment=PWScli #AutoIt3Wrapper_Res_Description=PlugWise Stretch 2.0 CLI #AutoIt3Wrapper_Res_Fileversion=2.1 #AutoIt3Wrapper_Res_LegalCopyright=2013 Phoenix Interactive #AutoIt3Wrapper_Res_Field=PWScli v2.1 (2013-10-17) X86 Win32|Sebastiaan Ebeltjes #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;PlugWise Stretch 2.0 commandline interface gemaakt door: Sebastiaan Ebeltjes (Phoenix Interactive) #include <array.au3> #include <String.au3> ;Variabelen definieren Global $StretchIP, $StretchID, $ApplianceID, $SwitchStatus Global $PostResponse, $PostStatus, $GetResponse, $GetStatus, $StretchPath Global $FlagAppList, $NameSearch = False ConsoleWrite("PWScli v2.1 (2013-10-17) X86 (Win32) by Sebastiaan Ebeltjes" & @CRLF) ConsoleWrite("For switching the PlugWise Stretch 2.0 with firmware 2.0.x" & @CRLF & @CRLF) If $CmdLine[0] >= 5 And $CmdLine[1] = "switch" Then ;Er zijn 5 of meer commando's opgegeven, we gaan aan de slag! $StretchIP = $CmdLine[2] $StretchID = StringLower($CmdLine[3]) ;Case sensitive!, all must be lower strings! $ApplianceID = StringLower($CmdLine[4]) ;Case sensitive!, all must be lower strings! $SwitchStatus = $CmdLine[5] ;Controle & checks If StringIsDigit(StringReplace($StretchIP, ".", "")) = False Then Melding("The StretchIP can only contain numbers!") If StringLen(StringReplace($StretchIP, ".", "")) > 12 Then Melding("The given StretchIP is invalid, expected max 12 numbers!") If StringIsAlpha($StretchID) = False Then Melding("The StretchID can only contain letters!") If StringLen($StretchID) <> 8 Then Melding("The StretchID is invalid, expected 8 letters!") If StringLen($ApplianceID) > 32 Then Melding("The ApplianceID or is invalid, expected less then 32 characters!") If StringLen($ApplianceID) < 32 Then $NameSearch = True If $SwitchStatus <> "on" And $SwitchStatus <> "off" Then Melding("The switch command can only be 'on' or 'off'!") ConsoleWrite("Stretch @ " & $StretchIP & @CRLF) If $NameSearch = True Then ConsoleWrite("Switching Circle with name " & Chr(34) & $ApplianceID & Chr(34) & " to status: " & StringUpper($SwitchStatus) & @CRLF & "busy...") Else ConsoleWrite("Switching ApplianceID: " & $ApplianceID & " to status: " & StringUpper($SwitchStatus) & @CRLF & "busy...") EndIf Schakelen($StretchIP, $StretchID, $ApplianceID, $SwitchStatus) If $PostStatus <> "200" And $PostStatus <> "" Then ConsoleWrite("error " & $PostStatus & " occured!, Stretch response:" & @CRLF & $PostResponse) Exit Else ConsoleWrite("switched!" & @CRLF) EndIf Exit EndIf If $CmdLine[0] >= 4 And $CmdLine[1] = "applist" Then $FlagAppList = $CmdLine[2] $StretchIP = $CmdLine[3] $StretchID = StringLower($CmdLine[4]) ;Case sensitive!, all must be lower strings! If StringIsDigit(StringReplace($StretchIP, ".", "")) = False Then Melding("The StretchIP can only contain numbers!") If StringLen(StringReplace($StretchIP, ".", "")) > 12 Then Melding("The given StretchIP is invalid, expected max 12 numbers!") If StringIsAlpha($StretchID) = False Then Melding("The StretchID can only contain letters!") If StringLen($StretchID) <> 8 Then Melding("The StretchID is invalid, expected 8 letters!") If $FlagAppList <> "show" And $FlagAppList <> "txt" And $FlagAppList <> "ini" Then Melding("The flag for the applianceID list can only be 'show', 'txt' or 'ini'!") ConsoleWrite("Stretch @ " & $StretchIP & @CRLF) ConsoleWrite("retrieving appliances list...") GetData($StretchIP, $StretchID, "/core/appliances") If $Getstatus <> "200" Then ConsoleWrite("error " & $Getstatus & "occured!, Stretch 2.0 response:" & @CRLF & $GetResponse) Exit Else ConsoleWrite("ok...reading values..." & @CRLF & @CRLF) ; No fancy XML readers in this place! ;-) $ApplianceID = _StringBetween($GetResponse, "<appliance id='", "'>") $GivenName = _StringBetween($GetResponse, "<name>", "</name>") $SwitchState = _StringBetween($GetResponse, "<state>", "</state>") $PowerUsage_temp1 = _StringBetween($GetResponse, "<type>electricity_consumed</type>" & @CRLF & @TAB & @TAB & @TAB & @TAB & "<unit>W</unit>" , "rement>") If $FlagAppList = "show" Then Consolewrite("Name:" & @TAB & @TAB & "State:" & @TAB & "Power:" & @TAB & "ApplianceID:" & @CRLF & @CRLF) For $loop = 1 to Ubound($ApplianceID) -1 $PowerUsage_temp2 = _StringBetween($PowerUsage_temp1[$loop], "<measurement log_date=", "/measu") $PowerUsage = _StringBetween($PowerUsage_temp2[0], ">", "<") If StringLen($GivenName[$loop]) <= 6 Then Consolewrite($GivenName[$loop] & @TAB & @TAB & StringUpper($SwitchState[$loop]) & @TAB & $PowerUsage[0] & @TAB & $ApplianceID[$loop] & @CRLF) If StringLen($GivenName[$loop]) > 6 Then Consolewrite($GivenName[$loop] & @TAB & StringUpper($SwitchState[$loop]) & @TAB & $PowerUsage[0] & @TAB & $ApplianceID[$loop] & @CRLF) Next EndIF If $FlagAppList = "txt" Then Global $TxtFile = @Scriptdir & "\" & StringTrimRight(@ScriptName, 4) & "_list.txt" Global $FileHandle = FileOpen($TxtFile, 2) FileWriteLine($FileHandle, "Name:" & @TAB & @TAB & "State:" & @TAB & "Power:" & @TAB & "ApplianceID:" & @CRLF & @CRLF) For $loop = 1 to Ubound($ApplianceID) -1 $PowerUsage_temp2 = _StringBetween($PowerUsage_temp1[$loop], "<measurement log_date=", "/measu") $PowerUsage = _StringBetween($PowerUsage_temp2[0], ">", "<") If StringLen($GivenName[$loop]) <= 6 Then FileWriteLine($FileHandle, $GivenName[$loop] & @TAB & @TAB & StringUpper($SwitchState[$loop]) & @TAB & $PowerUsage[0] & @TAB & $ApplianceID[$loop] & @CRLF) If StringLen($GivenName[$loop]) > 6 Then FileWriteLine($FileHandle, $GivenName[$loop] & @TAB & StringUpper($SwitchState[$loop]) & @TAB & $PowerUsage[0] & @TAB & $ApplianceID[$loop] & @CRLF) Next FileClose($FileHandle) Consolewrite("ApplianceID's dumped in file: " & $TxtFile) EndIf If $FlagAppList = "ini" Then Global $IniFile = @Scriptdir & "\" & StringTrimRight(@ScriptName, 4) & "_list.ini" For $loop = 1 to Ubound($ApplianceID) -1 $PowerUsage_temp2 = _StringBetween($PowerUsage_temp1[$loop], "<measurement log_date=", "/measu") $PowerUsage = _StringBetween($PowerUsage_temp2[0], ">", "<") IniWrite($IniFile, $ApplianceID[$loop], "name", $GivenName[$loop]) IniWrite($IniFile, $ApplianceID[$loop], "state", $SwitchState[$loop]) IniWrite($IniFile, $ApplianceID[$loop], "power", $PowerUsage[0]) Next Consolewrite("ApplianceID's dumped in file: " & $IniFile) EndIf EndIf Exit EndIf ;Show commandline usage ConsoleWrite("There are none or not enough commands given!" & @CRLF & @CRLF & "This is the usage of this program: " & @CRLF) ConsoleWrite(@ScriptName & " switch [stretchIP] [stretchID] [ApplianceID/CircleName] [on/off]" & @CRLF & @CRLF & @CRLF) ConsoleWrite("To give or dump a list of the appliance ID's: " & @CRLF & @ScriptName & " applist [show/txt/ini] [stretchIP] [stretchID]" & @CRLF) Exit Func Schakelen($StretchIP, $StretchID, $ApplianceID, $SwitchStatus) If $NameSearch = True Then GetData($StretchIP, $StretchID, "/core/appliances") $GivenName = _StringBetween($GetResponse, "<name>", "</name>") $ApplianceID_search = _StringBetween($GetResponse, "<appliance id='", "'>") For $loop = 1 to Ubound($GivenName) -1 If $GivenName[$loop] = $ApplianceID Then $ApplianceID = $ApplianceID_search[$loop] ExitLoop EndIf Next EndIf Global $PostAdres = "http://" & $StretchIP & "/core/appliances;id=" & $ApplianceID & "/relay" Global $PostGegevens = "<relay><state>" & $SwitchStatus & "</state></relay>" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $PostAdres, False) $oHTTP.SetRequestHeader("Host", $StretchIP) $oHTTP.SetRequestHeader("Connection", "Close") $oHTTP.SetRequestHeader("Content-Type", "application/xml") $oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchID)) $oHTTP.Send($PostGegevens) $PostResponse = $oHTTP.ResponseText EndFunc ;Schakelen Func GetData($StretchIP, $StretchID, $StretchPath) Global $GetAdres = "http://" & $StretchIP & $StretchPath $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", $GetAdres, False) $oHTTP.SetRequestHeader("Host", $StretchIP) $oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchID)) $oHTTP.Send() $GetResponse = $oHTTP.ResponseText $GetStatus = $oHTTP.Status EndFunc ;GetData 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 ;_Base64Encode Func Melding($BerichtTekst) ConsoleWrite($BerichtTekst & @CRLF) Exit EndFunc ;Melding |
PWScli v1.2 (voor stretch 2.0 met firmware 1.0.x) source:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=PWScli.ico #AutoIt3Wrapper_outfile=PWScli.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Comment=PWScli #AutoIt3Wrapper_Res_Description=PlugWise Stretch 2.0 CLi #AutoIt3Wrapper_Res_Fileversion=1.2.0.0 #AutoIt3Wrapper_Res_LegalCopyright=2013 Phoenix Interactive #AutoIt3Wrapper_Res_Field=PWScli v1.2 (2013-05-05) X86 Win32|Sebastiaan Ebeltjes #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;PlugWise Stretch 2.0 commandline interface gemaakt door: Sebastiaan Ebeltjes (Phoenix Interactive) #include <array.au3> #include <String.au3> ;Variabelen definieren Global $StretchIP, $StretchID, $ApplianceID, $SwitchStatus Global $PostResponse, $PostStatus, $GetResponse, $GetStatus, $StretchPath Global $FlagAppList ConsoleWrite("PWScli v1.2 (2013-05-05) X86 Win32 by Sebastiaan Ebeltjes" & @CRLF & @CRLF) If $CmdLine[0] >= 5 And $CmdLine[1] = "switch" Then ;Er zijn 5 of meer commando's opgegeven, we gaan aan de slag! $StretchIP = $CmdLine[2] $StretchID = StringLower($CmdLine[3]) ;Case sensitive!, all must be lower strings! $ApplianceID = StringLower($CmdLine[4]) ;Case sensitive!, all must be lower strings! $SwitchStatus = $CmdLine[5] ;Controle & checks If StringIsDigit(StringReplace($StretchIP, ".", "")) = False Then Melding("The StretchIP can only contain numbers!") If StringLen(StringReplace($StretchIP, ".", "")) > 12 Then Melding("The given StretchIP is invalid, expected max 12 numbers!") If StringIsAlpha($StretchID) = False Then Melding("The StretchID can only contain letters!") If StringLen($StretchID) <> 8 Then Melding("The StretchID is invalid, expected 8 letters!") If StringLen($ApplianceID) <> 32 Then Melding("The ApplianceID is invalid, expected 32 characters!") If $SwitchStatus <> "on" And $SwitchStatus <> "off" Then Melding("The switch command can only be 'on' or 'off'!") ConsoleWrite("Stretch @ " & $StretchIP & @CRLF) ConsoleWrite("Switching ApplianceID: " & $ApplianceID & " to status: " & StringUpper($SwitchStatus) & @CRLF & "busy...") Schakelen($StretchIP, $StretchID, $ApplianceID, $SwitchStatus) If $PostStatus <> "200" Then ConsoleWrite("an error occured!, Stretch response:" & @CRLF & $PostResponse) Exit Else ConsoleWrite("switched!" & @CRLF) EndIf Exit EndIf If $CmdLine[0] >= 4 And $CmdLine[1] = "applist" Then $FlagAppList = $CmdLine[2] $StretchIP = $CmdLine[3] $StretchID = StringLower($CmdLine[4]) ;Case sensitive!, all must be lower strings! If StringIsDigit(StringReplace($StretchIP, ".", "")) = False Then Melding("The StretchIP can only contain numbers!") If StringLen(StringReplace($StretchIP, ".", "")) > 12 Then Melding("The given StretchIP is invalid, expected max 12 numbers!") If StringIsAlpha($StretchID) = False Then Melding("The StretchID can only contain letters!") If StringLen($StretchID) <> 8 Then Melding("The StretchID is invalid, expected 8 letters!") If $FlagAppList <> "show" And $FlagAppList <> "txt" And $FlagAppList <> "ini" Then Melding("The flag for the applianceID list can only be 'show', 'txt' or 'ini'!") ConsoleWrite("Stretch @ " & $StretchIP & @CRLF) ConsoleWrite("retrieving appliances list...") GetData($StretchIP, $StretchID, "/minirest/appliances") If $Getstatus <> "200" Then ConsoleWrite("an error occured!, Stretch 2.0 response:" & @CRLF & $GetResponse) Exit Else ConsoleWrite("ok...reading values..." & @CRLF & @CRLF) ; No fancy XML readers in this place! ;-) $GivenName = _StringBetween($GetResponse, "<name>", "</name>") $SwitchState = _StringBetween($GetResponse, "<power_state>", "</power_state>") $PowerUsage = _StringBetween($GetResponse, "<current_power_usage>", "</current_power_usage>") $ApplianceID = _StringBetween($GetResponse, "<appliance id=" & Chr(34), Chr(34) & ">") If $FlagAppList = "show" Then Consolewrite("Name:" & @TAB & @TAB & "State:" & @TAB & "Power:" & @TAB & "ApplianceID:" & @CRLF & @CRLF) For $loop = 1 to Ubound($GivenName) -1 If StringLen($GivenName[$loop]) <= 6 Then Consolewrite($GivenName[$loop] & @TAB & @TAB & StringUpper($SwitchState[$loop]) & @TAB & StringUpper($PowerUsage[$loop]) & @TAB & $ApplianceID[$loop] & @CRLF) If StringLen($GivenName[$loop]) > 6 Then Consolewrite($GivenName[$loop] & @TAB & StringUpper($SwitchState[$loop]) & @TAB & StringUpper($PowerUsage[$loop]) & @TAB & $ApplianceID[$loop] & @CRLF) Next EndIF If $FlagAppList = "txt" Then Global $TxtFile = @Scriptdir & "\" & StringTrimRight(@ScriptName, 4) & "_list.txt" Global $FileHandle = FileOpen($TxtFile, 2) FileWriteLine($FileHandle, "Name:" & @TAB & @TAB & "State:" & @TAB & "Power:" & @TAB & "ApplianceID:" & @CRLF & @CRLF) For $loop = 1 to Ubound($GivenName) -1 If StringLen($GivenName[$loop]) <= 6 Then FileWriteLine($FileHandle, $GivenName[$loop] & @TAB & @TAB & StringUpper($SwitchState[$loop]) & @TAB & StringUpper($PowerUsage[$loop]) & @TAB & $ApplianceID[$loop] & @CRLF) If StringLen($GivenName[$loop]) > 6 Then FileWriteLine($FileHandle, $GivenName[$loop] & @TAB & StringUpper($SwitchState[$loop]) & @TAB & StringUpper($PowerUsage[$loop]) & @TAB & $ApplianceID[$loop] & @CRLF) Next FileClose($FileHandle) Consolewrite("ApplianceID's dumped in file: " & $TxtFile) EndIf If $FlagAppList = "ini" Then Global $IniFile = @Scriptdir & "\" & StringTrimRight(@ScriptName, 4) & "_list.ini" For $loop = 1 to Ubound($GivenName) -1 IniWrite($IniFile, $ApplianceID[$loop], "name", $GivenName[$loop]) IniWrite($IniFile, $ApplianceID[$loop], "state", $SwitchState[$loop]) IniWrite($IniFile, $ApplianceID[$loop], "power", $PowerUsage[$loop]) Next Consolewrite("ApplianceID's dumped in file: " & $IniFile) EndIf EndIf Exit EndIf ;Show commandline usage ConsoleWrite("There are none or not enough commands given!" & @CRLF & @CRLF & "This is the usage of this program: " & @CRLF) ConsoleWrite(@ScriptName & " switch [stretchIP] [stretchID] [ApplianceID] [on/off]" & @CRLF & @CRLF & @CRLF) ConsoleWrite("To give or dump a list of the appliance ID's: " & @CRLF & @ScriptName & " applist [show/txt/ini] [stretchIP] [stretchID]" & @CRLF) Exit Func Schakelen($StretchIP, $StretchID, $ApplianceID, $SwitchStatus) 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() $PostResponse = $oHTTP.ResponseText $PostStatus = $oHTTP.Status EndFunc ;Schakelen Func GetData($StretchIP, $StretchID, $StretchPath) Global $GetAdres = "http://" & $StretchIP & $StretchPath $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", $GetAdres, False) $oHTTP.SetRequestHeader("Host", $StretchIP) $oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchID)) $oHTTP.Send() $GetResponse = $oHTTP.ResponseText $GetStatus = $oHTTP.Status EndFunc ;GetData 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 ;_Base64Encode Func Melding($BerichtTekst) ConsoleWrite($BerichtTekst & @CRLF) Exit EndFunc ;Melding |
[#/plugwise/stretch20/stretch20-cli” ]