Can't get GET to work

I'm trying to set up a rule to send a command to my Wiim Amp (cheaper version of Sonos). The following command:

https://192.168.0.64/httpapi.asp?command=MCUKeyShortClick:2

works fine when typed into my browser address bar (Safari). It selects Preset 2 on the Amp and plays the linked station. However when I try the same in RM:

I get nothing, it doesn't work. Any ideas? I'm wanting to use a few of the commands from Wiim API in rules.

Could be some issue with using HTTPS from HE.... Not sure what to suggest if that is the issue...

1 Like

might try:

https://192.168.0.64/httpapi.asp?command=MCUKeyShortClick%3A2
1 Like

No joy with that. That command also works from the browser but not from RM.

@Bravenel - is there any reason you can think of as to why the command in the opening post would not work within RM when it works from the browser address bar? Thanks

I guess it's something to do with https, as I cannot get it to work in node-red either (node-red returns an error of 'DEPTH_ZER_SELF_SIGNED_CERT'). I can't understand why it works every time from my browser.

So it is a problem with https according to others on the Wiim forum:

"Confirmed from the command line:

curl --insecure https://192.168.1.184/httpapi.asp?command=MCUKeyShortClick:2 ==> returns OK

curl https://192.168.1.184/httpapi.asp?command=MCUKeyShortClick:2 ==> returns curl: (60) SSL certificate problem: self-signed certificate"

How can I get around this as RM will only let me enter a url - I can't prepend it with "curl --insecure" (and using http instead of https won't work)

Oh, and why do things that are seemingly simple have to be so bloody difficult unless you can code!

So you’re using a self-signed cert… Yeah the groovy API version has a IgnoreSSLIsssues flag for this reason. Doesn’t look like RM is exposing it.

1 Like

That's why God created @thebearmay (at least in my experience). :wink:

3 Likes

Well I've resorted to Chat GPT for a driver and have had it change a few things. At this point the only command added in the driver is the "call preset" and that's what I'm trying to test it with. However regardless of the ignoreSSLIssues = True I'm still getting "connection refused" in the logs. The code is below. Is anything obvious that would cause the "connection refused"? (I realise that this thread has evolved and has sod all to do with RM anymore!)

metadata {
    definition (name: "Wiim Amp", namespace: "John Williamson", author: "Chat GPT") {
        capability "Music Player"
        capability "Actuator"
        
        command "preset", ["number"]
        command "volumeUp"
        command "volumeDown"
        command "mute"
        command "stop"
        command "pause"
        command "play"
        command "setVolume", ["number"]
        
        attribute "volume", "number"
        attribute "muted", "bool"
    }

    preferences {
        input("ipAddress", "string", title: "Device IP Address", description: "Enter the IP address of your media player", required: true)
    }
}

def sendHttpGetRequest(String url) {
    def client = new hubitat.device.HubAction(
        method: "GET",
        path: url,
        headers: [
            HOST: ipAddress,
            Accept: "*/*"
        ]
    )
    client.options = [
        ignoreSSLIssues: true // Always ignore SSL issues
    ]
    sendHubCommand(client)
}

def preset(number) {
    def url = "https://${ipAddress}/httpapi.asp?command=MCUKeyShortClick:${number}"
    sendHttpGetRequest(url)
}

def volumeUp() {
    def url = "https://${ipAddress}/httpapi.asp?command=Volume+"
    sendHttpGetRequest(url)
}

def volumeDown() {
    def url = "https://${ipAddress}/httpapi.asp?command=Volume-"
    sendHttpGetRequest(url)
}

def mute() {
    def url = "https://${ipAddress}/httpapi.asp?command=Mute"
    sendHttpGetRequest(url)
}

def stop() {
    def url = "https://${ipAddress}/httpapi.asp?command=Stop"
    sendHttpGetRequest(url)
}

def pause() {
    def url = "https://${ipAddress}/httpapi.asp?command=Pause"
    sendHttpGetRequest(url)
}

def play() {
    def url = "https://${ipAddress}/httpapi.asp?command=Play"
    sendHttpGetRequest(url)
}

def setVolume(number) {
    def url = "https://${ipAddress}/httpapi.asp?command=VolumeSet:${number}"
    sendHttpGetRequest(url)
}

def playTrack(uri) {
    // Implement playing a specific track if supported
}

I admire your resolve! Going the custom driver route seems like the right call. ChatGPT, on the other hand, requires a lot of prompting work to get decent code out of.

A few tips:

Try replacing your sendHttpGetRequest with this:

def sendHttpGetRequest(String requestURL) {
    Map requestParams =
	[
        uri: requestURL,
        ignoreSSLIssues: true
	]

    try {
        httpGet(requestParams) { resp ->
            //log.debug resp
            if (resp != null) {
                // success
                //log.debug resp.data // uncomment to log the Get response data 
            } else {
                // failure
            }
        }
    }
    catch (e) {
        // exception thrown
        log.error e
    }
}

1 Like

Yes I was having quite the debate last night with ChatGPT. Add this, change that, 'Hubitat reports error'. Each time it apologised, before spitting out some changes for me to try .

I did look at that one but just couldn't fathom how to implement the ignoreSSLIssues as that appeared to be the root of the problem.

Eureka! I put the initial code in pastebin (I did create a Github account years ago but that's a whole world of pain and confusion when you just don't get it). I created another version with that chunk of code replaced with yours and then replaced the code in the Hubitat user driver. Calling the preset from the device page immediately started the Wiim streaming my radio station. I've then tried using RM to run a custom action on the actuator device and that's working too. A little later I will amend the other commands I want and delete those I don't.

Thanks so much for your help, I was beginning to think it wouldn't be possible.

1 Like