Hub originated REST request?

I have a rental house with a v2 hub in it. A few days ago the DDNS service on a different device quit working, and I no longer can find the IP the router currently has.

I was hoping to build a quick SA or DT that would allow me to simply send a REST command to an outside web server that would return the JSON encoded IP. I’ve tried using HubAction, but nothing ever seems to happen. The web server logs show no connection, and parse() never gets called. I would even settle for creating the connection from the hub to the web server and then manually checking the web server logs on the receiving end for the IP, but would prefer to get the IP back and display it in the DT or SA.

All of the documentation I’ve found on this site show that this should work, but I’ve found several posts that indicate it was broken by the v2 platform changes last fall.

Is there an alternative to doing what I want to do? Thanks for any insight.

You need to use the HttpRequest, HubAction is for local networks only. I will add a “WEB request” task to CoRE :wink: thanks for the idea :wink:


Can you point me to the docs for that method? Doing some quick googling, I’m not finding anything. I checked here:

and didn’t see it. I’ve already tried httpGet and that appears to originate from the cloud rather than the hub itself.

Thanks again.

Go to my in the HomeCloudHub repository, under smart apps, that app uses lots of them. Look through the source code. Currently driving, can help more when I land home. Sorry, arrive :))

Officer pulls over a speeding Ferrari. What’s wrong officer? Was I going too fast? Oh no, not at all, but you were flying too low…

1 Like

Oh I see where the problem is. You want to figure out your external IP… Find a non-password-protected page on your router that gives you the broadband status and use HubAction on it, then try to parse the return to extract the IP?

Yeah, so doing httpGet or some of those other methods doesn’t work, the request comes from the cloud. I really need the request to come from the hub, but I need for it to hit an external IP in order to do so.

I played around with a few things I saw in your code, like using httpGet from within a sendHubCommand, but even though the request gets sent, it still comes from the cloud and not the hub.

Perhaps there’s a better way to get the public IP than what I’m trying, and I’d certainly try any other suggestions.

Read my updated comment above. Router status page? Is it password protected?

I like that idea, but I’m pretty sure all of the pages on the router are protected, and without something to hit against and play, I can’t get anywhere there.

A LAN device like a ddwrt router, a raspberry pi, a Synology NAS can provide you with the means to use HubAction… They would check your external IP for you…

My AT&T Uverse router exposes the IP when I visit and there is no password for that page…

I’m trying to get my HubAction to return something, then I’ll see if I can find a public page on my router. I’m apparently not writing this device type properly, however. Can you just look this over and see if you see any glaring mistakes? The parse function never gets called:

// parse events into attributes
def parse(description) {
log.debug “Parsing ‘${description}’”
// def msg = parseLanMessage(description)

// handle commands
def poll() {
log.debug “Executing ‘poll’”

// sendHubCommand(
def hubAction = new physicalgraph.device.HubAction(
method: “GET”,
path: “/”,
headers: [
HOST: “”
query: []
//log.debug hubAction
// )

Your response will come in the parse method, nothing there? Also, HubAction is not able to do HTTPS :frowning:

No, that first line of parse writes to the log, and it never writes anything to the log except for: “executing poll”:

06ab63f6-56af-4eab-b0f5-02d800568524 3:24:54 PM: debug Executing 'poll’
06ab63f6-56af-4eab-b0f5-02d800568524 3:24:49 PM: debug Executing 'poll’
06ab63f6-56af-4eab-b0f5-02d800568524 3:18:20 PM: debug Executing ‘poll’

I don’t know if the router will respond to non-https requests, so that could possibly be the underlying issue. As long as there’s nothing glaringly wrong with the code, I’ll keep trying.

Just try without the 443, baby steps. See if you get anything back…

No dice. I’ve also tried a few other IPs on the network that may be running web servers as well, nothing calls the parse method, which I assume means nothing is responding, or something isn’t right with my device type.

May just have to give up and wait until I physically get up there to fix things.

This is what I used with success:

private sendLocalServerCommand(ip, command, payload) {
    sendHubCommand(new physicalgraph.device.HubAction(
        method: "GET",
        path: "/${command}",
        headers: [
            HOST: "${ip}:42457"
        query: payload ? [payload: groovy.json.JsonOutput.toJson(payload).bytes.encodeBase64()] : []

Oh you need these:

subscribe(location, null, lanEventHandler, [filterEvents:false])

def lanEventHandler(evt) {
    def description = evt.description
    def hub = evt?.hubId
    def parsedEvent = parseLanMessage(description)	

The subscribe line (I believe) is throwing a null pointer exception when trying to get the ID property: “Cannot get property ‘id’ on null object”

I use that in a SmartApp. Not sure if it works in a device?

Okay, the device type handler gets the response into parse()… getting nothing?

Look at this