Is it possible to get information from router?


(ilker Aktuna) #1

Hi,

I would like to write a smart app that would get some information from my router (either via telnet/ssh or http)
and according to the response it should do something.

Is this possible ?
I haven’t written any smart apps yet and I don’t know the guidelines.

Thanks.


(sidjohn1) #2

Yes, http is possible


(ilker Aktuna) #3

is there any simple example which I could check ?

and, ssh/telnet is not possible ?


#4

What information are you trying to get?


(ilker Aktuna) #5

I will write a script on my router which pings a specific device and provide “present” /“absent” status.
The result should be processed as a presence sensor on the ST platform.


(sidjohn1) #6
https://community.smartthings.com/search?q=Router%20presence

Scripting is cool, searchfu is cooler


(ilker Aktuna) #7

thanks. I agree that “searchfu is cooler”

But the DD-WRT example is a little different than what I was looking for. In that example, router triggers the ST platform. I was looking for a way to query router from ST Hub. Because if I do that, I won’t need access to cloud for just pinging something inside my house.
Is there an example for that reverse query mechanism ?

In any case, I would like to try the DD-WRT example.
But I couldn’t understand how to fill up

PHONE1ON=“https://graph.api.smartthings.com/api/…”

What will be the URL to call there ?

Thanks.


(Stuart Buchanan) #8

maybe my instructions in the post below will help you understand better. the URL is built using the standard ST API calls and the oauth app id and key

further reading is available here

http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-cloud-connected-device-types/building-the-service-manager.html


(ilker Aktuna) #9

thanks. That’s really helpful.
But it is based on a smart app.
What about if I want to directly update presence of a virtual presence sensor ?

Where do I get the URL for that ?


(ilker Aktuna) #10

I’m confused. (couldn’t combine the DD-WRT example with Fuzzyligic’s explanation on ASUSWRT Wifi Presence)

I create the DD-WRT example device as a device handler. Then I create a device from it.
How do I get the URL to update it ?

Thanks.


(Stuart Buchanan) #11

you need a smartapp to do the status change of the presence sensor. you cannot configure Oauth derectly on a device type without a smartapp. so you do need a smartapp to enable the mapping for the URL and then trigger the device type.

the smartapp is simple to customise to trigger the action you want.


(ilker Aktuna) #12

thanks.

so I first create a device from example presence sensor codes.
then I create a smartapp (also from example codes)
then , shall I have to add a device from the device handler I create in the first step ?

what will be the network ID to use there ?

and I don’t understand in the DR-WRT example below; there’s only one code for smartthings platform. Which one is that ? device handler or the smart app ?


(Stuart Buchanan) #13

yes you create a device, the Network ID can be anything you want. I just use the same name as the device, it just has to be unique.

the code in that discussion is a device type. the post says

Next, you need to setup OAUTH endpoint access. That is covered elsewhere.

this part is best handled by a smartapp, the one from my post will do this fine


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #14

At the moment and for the – long – indefinite future, you cannot deploy any custom code to your Hub.

So even if you wrote a SmartApp that uses the LAN based hubAction() commands to query the router, this will execute in the SmartThings Cloud.


(ilker Aktuna) #15

@Fuzzyligic thanks. I am trying to use the example in your post.
I installed the virtual presence sensor device handler and then created a device from it with network ID 3000

Then I installed the smart app.
At this point I understand that I should install an instance of it with the virtual presence sensor device I just created.
So I select thet presence sensor and give a name. I don’t select any modes.
When I tap “done” app says : “unexpected error occured”

So, I can’t install the app.

What is the reason ?

Thanks.


(ilker Aktuna) #16

ok; I got it.
It was because I didn’t enable OAuth in the app…


(Stuart Buchanan) #17

Unsure as this doesn’t happen with me, the only way to see is to look at the live logging window in the IDE when you try to save the page


(ilker Aktuna) #18

Ok. I got it.

Now I am trying to add some other features to this.
So I first start by adding a tile to your device handler.

But it doesn’t show up.

I just added :

  		standardTile("right", "device.presence", width: 2, height: 1, canChangeIcon: false,  canChangeBackground: false, decoration: "flat") {
			state "present", label: "IP", icon: "st.thermostat.thermostat-right"
		}

what might be the reason for not showing up ?

I am actually trying to send router’s external IP address to the app to show up on the virtual device.


(ilker Aktuna) #19

figured that as well. I had to add the new tile into “details”.

Now , how can I get a dynamic value from the router script ?

Instead of sending /Phone/home , how can I send a parameter ?
and read it on smartapp ?


(ilker Aktuna) #20

how can I pass a value to the smart app ?
I read on some thread that parameters could be received with a notation like:

path("/devices/:id") {
    action: [
            GET: "getDevice",
            PUT: "updateDevice"
    ]
}

But how can I send the :id from http ?

edit:

I figured out that I have to use format: /Phone/ip/123.456.222.111?access_token=
to send HTTP
and to receive it use:

    path("/Phone/ip/:ip") {
    action: [
      GET:"updateIP"
    ]
  }

but I could not find how to send it to the device here:

def updateIP(ip) {
            virtualPresence.updateIP($ip);
}

so, couldyou help me on this ?