ederhj

MQTT connection

2 posts in this topic

#1 ·  Posted

Hello,

I'am using MQTT as communication from my smarthome devices to any other device.

Now I want to use a AutoIt-Script als MQTT-Client, where I can see what MQTT-Topic hast changed and so on.

Does anyone have a solution for the AutoIt-Connection to a MQTT-Server?

Thank U

ederhj

Share this post


Link to post
Share on other sites



#2 ·  Posted

Do you try ObjCreate("WinHttp.WinHttpRequest.5.1")?

Something like this:

Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

Global $REMOTE_URL = "http://www.myurl.com"
Global $AUTHORIZATION = "user:pass" ; base64( "user:pass" )

Ajax("hello")

Func Ajax($func = "")
    $oHTTP.Open("POST", $REMOTE_URL, False)
  ;$oHTTP.Open("GET", $REMOTE_URL, False)
    $oHTTP.SetRequestHeader("User-Agent", "AutoIt")
    $oHTTP.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
    ;$oHTTP.SetRequestHeader("Connection", "Keep-Alive")
    $oHTTP.SetRequestHeader("Authorization", "Basic " & $AUTHORIZATION)
;~  $oHTTP.SetCredentials($REMOTE_USER, $REMOTE_PASS, 1)
;~  Local $opt = '{"function":"' & $func & '"' & ($data ? ',"d":' & $data : "") & '}'
    Local $opt = ObjCreate($SD)
    $opt.Add("function", $func)
    If $oSend.Count Then
        $opt.Add("data", $oSend)
        $oSend = ObjCreate($SD)
    EndIf
    $opt = jsmn_encode($opt)
    $oHTTP.Send(StringToBinary($opt, 4))
    $oHTTP.WaitForResponse()
    Local $oAllHeaders = $oHTTP.GetAllResponseHeaders()
    ConsoleWrite($oAllHeaders & @LF)
    If $oHTTP.Status <> 200 Then Return SetError(4, 0, 1)

    Local $json = $oHTTP.ResponseText
    If Not $json Then Return SetError(4, 0, 2)
    If $DEBUG Then _DebugOut($json)
    $oo = Jsmn_decode($json)
    If @error Then Return SetError(4, 0, 3)
    Return $json
EndFunc   ;==>Ajax

 


m(o.O)m

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