Sign in to follow this  
Followers 0
Xenobiologist

[SOLVED] HttpRequest Webservice Loxone - How does it work?

2 posts in this topic

#1 ·  Posted (edited)

Hello,

I am using Loxone as the central "technology" for controlling my SmartHome. Now, I'm curious whether it is possible to use the webservice to get/set information in the Loxone miniserver.

Anyone tried that already, or anyone who has got an idea what code to use?

Thanks!

Describtion of the webservice can be found here: https://www.loxone.com/enen/kb/web-services/

Getting the mac address is working. The result looks the way it is described on the website.

<?xml version="1.0" encoding="utf-8"?>
<LL control="dev/cfg/mac" value="59:9F:99:90:89:C9" Code="200"/>

All other stuff like getting the version - is not working.

;https://www.loxone.com/enen/kb/web-services/
#include <Crypt.au3>

_Crypt_Startup() ; To optimize performance start the crypt library.

Global Const $HTTP_STATUS_OK = 200

Global $user = 'xxx'
Global $password = 'xxx'
Global $ip = '192.168.178.77'
Global $port = '50666'

;~ Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/mac', "password=" & _Crypt_HashData($password, $CALG_MD5))
Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/version', "password=" & _Crypt_HashData($password, $CALG_MD5))
;~ Global $MD5 = HttpGet('http://' & $user & ':' & $password & '@' & $ip & ':' & $port & '/dev/cfg/version') ;, "password=WeWantThisAsMd5")
;~ Global $MD5 = HttpGet('/dev/cfg/gateway') ;, "password=WeWantThisAsMd5")

ConsoleWrite($MD5 & @CRLF)

Func HttpPost($sURL, $sData = "")
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

    $oHTTP.Open("POST", $sURL, False)
    If (@error) Then Return SetError(1, 0, 0)

    $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

    $oHTTP.Send($sData)
    If (@error) Then Return SetError(2, 0, 0)

    If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0)

    Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc   ;==>HttpPost

Func HttpGet($sURL, $sData = "")
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

;~  $oHTTP.Open("GET", $sURL & "?" & $sData, False)
    $oHTTP.Open("GET", $sURL & "?" & $sData, False)
    If (@error) Then Return SetError(1, 0, 0)

    $oHTTP.Send()
    If (@error) Then Return SetError(2, 0, 0)

    If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0)

    Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc   ;==>HttpGet

So long,

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites



Nevermind, I've found a solution.

 

;https://www.loxone.com/enen/kb/web-services/
#include <Crypt.au3>
#include <WinHttp.au3>
Opt("MustDeclareVars", 1)
Global $user = 'xxx'
Global $password = 'xxx'
Global $ip = '192.168.178.77'
Global $port = '50666'

; Open needed handles
Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, 'http://' & $user & ':' & $password & '@' & $ip & ':' & $port)
; Specify the reguest:
;~ Local $hRequest = _WinHttpOpenRequest($hConnect, Default, '/dev/cfg/mac')
;~ Local $hRequest = _WinHttpOpenRequest($hConnect, Default, '/dev/cfg/versiondate')
Local $hRequest = _WinHttpOpenRequest($hConnect, Default, 'dev/cfg/ip')

; Set credentials
_WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $user, $password)

; Send request
_WinHttpSendRequest($hRequest)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header
ConsoleWrite($sHeader & @CRLF  & _WinHttpReadData($hRequest) & @CRLF)

; Clean
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0