Finding Public IP Address of Cable Modem serving the SmartHub


(William Bondy) #1

Hi,

I use my Smartthings system to monitor a rental property. I’m trying to see if there is a way to develop an application that would report the external/public IP address of the cable modem that serves by SmartThings Hub. I looked into DynamicDNS but that now requires a recurring fee which I’d like to avoid. I would like to use the Public IP to remotely monitor/configure by Cable Modem. My modem is setup to NAT. I was thinking that the the Smarthings web portal might have access to this public IP and maybe there is a way to retrieve it?

Thanks!


(Convinced ST will never be unbroken…) #2

There are a couple of ways to do this… one way would be if your router supports remote management, the other would be to put a php script someplace that could return the host IP.

What is it exactly you want to do remotely, and is there a computer there that is running, or only the SmartThings hub?


#3

I use http://no-ip.com. It’s free as long as you don’t mind clicking a link in an email every 30 days so that it doesn’t expire. It’s also a supported service on my Verizon router.


(William Bondy) #4

Thanks, since this is a rental properly I don’t have any computers there. I’m monitoring smoke/CO alarms, thermostat and door openings (when there is no one in the unit). I want to be able to manage my cable modem/Wifi to change Wifi passwords and things like that. The modem only offers using a dynamic DNS service that charges $50/year which I’d like to avoid. I have no place to run a script so that it why I was hoping I could somehow use the smarthings setup.


(William Bondy) #5

Thanks for the info, unfortunately my cable modem hard codes only one dynamic DNS service which is not cheap, so I can’t use this one.


(Convinced ST will never be unbroken…) #6

If you create a php script with the following line on a web server some place, calling that script from an HTTP GET will return the WAN IP of your modem.

<?php echo $_SERVER['REMOTE_ADDR'];?>

You could create a SmartApp that would issue the GET on a schedule, and return the response to you in either a notification or text message.

However, if you have no internet presence in which to park the script, you’ll need to use one of the existing pages out there to do it, and this will dramatically increase the amount of work to be done in parsing the response.


(Patrick Stuart [@pstuart]) #7

http://www.myipaddress.com/show-my-ip-address/

Try my scraping website app for Ubi a wrote as a starting point. Should be pretty straightforward.

Just won’t need to the auth part, or all the funky code work…

https://github.com/pstuart/smartthings/blob/master/Get%20Ubi%20Sensors

Errr. Problem. this will probably give you the public ip of the cloud server, not your Cable modem…

You will need to use a localhubaction…


(Patrick Stuart [@pstuart]) #8

Threw this together…

https://github.com/pstuart/smartthings/blob/master/GetPublicIP


Any way to find the external IP of my Smartthings hub?
(William Bondy) #9

Wow, I really appreciate this, thank you. As I’m a bit of novice to how this code gets installed and executed, can you point me to posts/instructions that explain how I do it?


(Patrick Stuart [@pstuart]) #10

Well, it should be a well documented function, but in reality the docs are lacking around here.

You need IDE access, https://graph.api.smartthings.com/

Then click devicetypes https://graph.api.smartthings.com/ide/devices

New SmartDevice

Fill out the fields, get to the code editor…

Paste in the code from my github.

Save and Publish, for me…

Then go to devices https://graph.api.smartthings.com/device/list

New device

Fill out the fields, choose the devicetype ps_GetPublicIp

Save

and now you should have a “Thing” on your phone app that will display the Public IP, you can open it and click refresh to get the latest one.


(William Bondy) #11

You rock! Thank you. This is very very cool. Straightforward too! I need to get my coding books out again, what language is this?


(Patrick Stuart [@pstuart]) #12

Groovy. Based on java


(Fytos) #13

Hi,
Also new to ST. So, how would one use the above code inside an actual application that needs to trigger a local action? For example, when a given door opens, then trigger a rapberry pie which exposes a web interface for speech to a speaker. I can see other application examples calling a well known website, but still need a way to find the correct address of my server. Also, is there a way for this info to be stored and reused after periodic refreshes?

Thanks for all the code sharing and advice! I’m looking forward to sharing something useful pretty soon…


(Fytos) #14

Ooops. Sorry, my answer is in this thread. You really don’t need the address if you can directly access any server in the home network…


(Satinder) #15

Hi,

I tried the above code from pstuart’s github - created a new device type and a device. However, log only shows the poll routine running. I cannot see any responses being received in the parse routine.

I have looked at the postings - have definitely create a device of type ps_GetPublicIp. Did anyone else have this working? I know I am doing something wrong - have a similar problem with another app (vlc) that I have copied and used - it works sending http commands but not processing any responses back.

Thanks,


(William Bondy) #16

I had this working when Patrick first posted it, but since it has stopped working. From searching the posts it appears the DeviceNetworkId needs to be set appropriately to get responses back however everything I’ve tried does not work, so clearly I’m missing something.


(Patrick Stuart [@pstuart]) #17

It still works for me. What are you getting in your ide logs when you press the refresh button?


(William Bondy) #18

Nothing, it never calls the parse() function which I assume means the response is not being handled….


(Patrick Stuart [@pstuart]) #19

The networkDeviceID must be set to d8922646:0050 which is the endpoint for the api call to get the public ip, you can’t set it to anything else or it won’t work.

The code is supposed to do this automatically, but if you went in and changed the NDI then you would have broken the code functionality.


(William Bondy) #20

When I just copy of the code you posted above and just create a device WITHOUT specifying the deviceNetworkId in the create form, its does not work as it did the first time I created it. But now, when I put the deviceNetworkId of d8922646:0050 in the create form, it does work. So something has changed on the platform where either the code above no longer sets the deviceNetworkId properly or we have to know in advance what the deviceNetworkID is so it can provisioned on the create device form.

One other thing that is strange, I added a line into your code to print out the deviceNetworkID (using sendEvent(…)). When I did that it did print out the event with the correct deviceNetworkId, however the remainder of the code stopped working, i.e. it never printed out the IP address. Just curious why this would affect how this app works, this environment seems very non-deterministic.

Thanks for all of your help!