Jump to content

Recommended Posts

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

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

 

Visit my repository

  • 2 years later...
Posted (edited)

You can use the mosquitto cmd arguments like shown above.

For me since my mosquitto server is on a linux VM that was not a good solution.

I was using Tasmota for my Sonoff devices and it allows for http control, so I wrote my autoit gui to use http to control those devices.

Node Red also has a lot of powerfull integration capabilities.

I actually put together a couple of YouTube videos on how I did that if you are interested I'll share them.

 

Regards,

Edited by ViciousXUSMC

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...