Help with sendHubCommand

I currently have the folowing code:

	def unformattedURL="http://wanIP:portNum/Dev/setHASensor.php?entity=$entity&fname=$friendly&unit=$unit&icon=$icon&state=$state"
    def url=unformattedURL.replaceAll("\\s","%20")

Works fine but I would prefer to use the sendHubCommand function. I have found examples but none seem to fit what I am trying to do. This is what I have so far:

def lanIP = ""
def rawParameters= "entity=$entity&fname=$friendly&unit=$unit&icon=$icon&state=$state"
def formatParameters=rawParameters.replaceAll("\\s","%20")
sendHubCommand(new physicalgraph.device.HubAction("""GET /Dev/setHASensor.php/?$formatParameters HTTP/1.1\r\nHOST: $lanIP\r\n\r\n""", physicalgraph.device.Protocol.LAN))

No errors but it does not work. Anyone know what I am doing wrong???

It needs to look more like the following, I believe. This is untested

        sendHubCommand(new physicalgraph.device.HubAction(
            method: "GET",
            path: "/Dev/setHASensor.php/?${formatParameters}",
            headers: [ HOST: "${lanIP}:${lanPORT}" ]

EDIT: I modified my sample code above to include the Port as @philh30 properly pointed out. Im my code, I actually use a function to return the IP:PORT combination for the HOST field above.

1 Like

This thread has code that has a similar sendHubCommand structure that was reported to be working. He has port appended to the end of the IP address, so you might try that. Not sure if there are other differences.


You are scholars and gentlemen :slight_smile:

Here is the final working function

def lanIP = ""
def lanPORT = "80"
def rawParameters = "entity=$entity&fname=$friendly&unit=$unit&icon=$icon&state=$state"
def formattedParameters=rawParameters.replaceAll("\\s","%20")
sendHubCommand(new physicalgraph.device.HubAction(
    method: "GET",
    path: "/Dev/setHASensor.php/?${formattedParameters}",
    headers: [ HOST: "${lanIP}:${lanPORT}" ]
) )

Notice the change I made to lanIP. Prefixing the IP with "http://’ does not work.

Anyhooo thanks to all

1 Like