ederhj Posted April 3, 2017 Share Posted April 3, 2017 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 Link to comment Share on other sites More sharing options...
Luigi Posted April 3, 2017 Share Posted April 3, 2017 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 Link to comment Share on other sites More sharing options...
flibustier Posted January 20, 2020 Share Posted January 20, 2020 Maybe someone needs it. You can use https://mosquitto.org/download/ mosquitto_pub.exe mosquitto_sub.exe with run('PATH\Mosquitto\mosquitto_pub.exe -h HOST -t TOPIC -m "MSG", '', @SW_HIDE) read help if you need info mosquitto_pub.exe -- help mosquitto_sub.exe --help Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted January 22, 2020 Share Posted January 22, 2020 (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 January 22, 2020 by ViciousXUSMC Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now