Some help please with a HttpGet piston


#1

1) Give a description of the problem
(Hi I’m trying to extract text from my routers status page using HttpGet)

2) What is the expected behavior?
(I have a sky router (UK) and what I’m trying to do is create a piston that will read it’s status page which is a local IP address Http://192.168.0.1
Then i want to try and read the text that’s taken from the page to see if it contains a certain Mac address)

3) What is happening/not happening?
(I’m not actually sure on which way to create the piston and read the info from it.
This is how I have it at the moment I’ve got it set to save to a string variable is this correct?, I know the http get works ok with the page as I use it on my phone with tasker I didn’t realise you could do it on this
Thanks for any help)

4) Post a Green Snapshot of the pistonimage
(

)


#2

Watching this one…


#3

My first question though is, will your router respond to a GET request and return that data? What router are you using?

But to answer your question, the first thing you would need to do is have a trigger. So, you have to use a timer and then decide how often you want this piston to run to your router to check if the device has a mac address. So, right there you can see the problem with what you are proposing. You’re talking about tying up the router’s resources for what won’t change 99% of the time. Why not simply use the ST iOS or Android virtual presence sensor? I use it on my phone and it works really well.

But, if you do want to poll your router every so often AND your router can actually return the data, then it is possible. In order to help you though I would need to know what url you have to request to your router and what is the name of the value it would return. But it would look something like this:

I’d be really interested to see what url you are requesting to get the data and how the router is going to return the data you want. Also, I’m curious to see how this affects the speed of the rest of your internet connection have a GET request run to it every minute.

Like I said though, I don’t think you really want to do what you are proposing to do. There are a lot better methods of having a presence sensor. Like I said, the ST app can act like one. It’s really reliable to easy to set up. It can be slow to respond if you’re not actively updating your location but that is true of any phone-based system.


#4

Given the example above, shouldn’t this piston set the value of jsonTest to the time returned by the http://time.jsontest.com API?

{
   "time": "04:48:57 AM",
   "milliseconds_since_epoch": 1517892537134,
   "date": "02-06-2018"
}


Solved: Access JSON that is a reply to a HTTP post request
#5

Hi thanks @Ryan780 @hmin03
Yeah my router definitely responds to it as I’m actually doing it already but with tasker on a android tablet.
On tasker I do the http get then save it to a text file but then tasker allows me to read that text file and then it changes my virtual presence.
The reason I’m doing this is because my son is always running out of data on his phone so the SmartThings presence never works right and I can’t install software on his phone :frowning: (hes 22 lol)
So this at least this gives me some indication if he’s home or not , I don’t need it to run constantly, every 20 mins would be fine.
How could your example above allow me to trip a virtual sensor depending what’s in the variable.
Thanks for the help


#6

If he’s connected to your router then he’s not using his data but your wifi so the presence sensor should work fine.


#7

If we can get the $args to pull in, you could probably use the SmartApp/DTH combination provided here.

Once you go through the steps for the SmartApp and DTH (skip the router specific instructions), you could then get webcore to send GET requests to the URLs below based on whether or not your son’s MAC address shows up in the router response. Usually a script on the router does that, but the source of the request doesn’t really matter.

https://your-shard.api.smartthings.com/api/smartapps/installations/AppID/Phone/home?access_token=AccessToken
https://your-shard.api.smartthings.com/api/smartapps/installations/AppID/Phone/away?access_token=AccessToken

Of course, it all hinges on whether or not we can pull in and parse the JSON object. In my testing, I haven’t found a way to do this.

Note: I do this with my router and the script, while not a HTTP service, runs every 15 seconds with no obvious detrimental effects. This was also much more reliable than the ST phone presence (at least back when I installed it).


#8

Thanks for that @hmin03 that gives me some good info.
Not sure I understand it all :slight_smile: I’m still learning the basics for now lol
But that’s great.
That’s what I thought also @Ryan780 but no it always stays on home if he leaves with no data


#9

Got it! The GET request populates the $response variable and you can access the values via the $response.key expression. Example below:


#10

Hi thanks again.
Could you break it down a little for me :frowning:
Are you saying for me to use it I create my own dynamic variable and then do a get request to my local IP like you did for the jsontest.com url.
Where does the response.key come into it and I’m not sure what the response.time is for.
So like this…


#11

Well, to be honest, now that we know that a web response will populate the $response variable, we may be able to just skip the particulars about JSON.

Not knowing exactly what’s returned by your router, I can only really give you ideas on how to accomplish what you’re looking for.

I’m assuming that somewhere on the http://192.168.0.1 status page, it lists connected MAC addresses. If so, then we can just take the $response from your web call and simply see if it contains the MAC you’re looking for. To do this, use the contains() function in an expression (there are other string related functions provided in the webcore wiki if you need them). Your tasker task may be doing something similar.

It should look something like this:

if {contains($response,'A1:B2:C3:D4:E5:F6')} is true
  then
    your action here

I hope that helps get you on your way.


#12

Ah yeah I’m starting to understand what you mean now.
That’s great I’ll try that when I get home from work.
Yeah the status page just has basic info with a text list of connected devices with their Mac addresses
Thanks again for the help I’ll let you know


#13

Hi Harold @hmin03
Thanks so much for that.
I’ve got it more or less working great now
It scans it great and puts it into the variable and its correctly setting the virtual presence sensor the present.
But I can’t get it to change the virtual presence sensor to “Not present” when the Mac address isn’t found.
Which is the best way to do it instead of the “Else” I chose.
(That’s not my real Mac address btw)


#14

2 things. It doesn’t look like you’re referencing the $response variable and you don’t have an actual condition in your if statement.

Try importing this piston and see if it works for you.


#15

Sorry, I keep editing it and reposting… make sure you get the latest one…


#16

Thanks I did try adding the $response but it was telling me that it couldn’t find the variable.
So I thought oh I’ll just create my own lol
I just added your last piston but have just noticed you’ve updated it so I’ll add this one now


#17

I’ve added that but again it’s changing it to present correctly but not the other way when I turn my Wi-Fi off.
I checked my router page and the Mac was no longer there.
This is what the log shows.
It seems like it’s detecting the Mac isn’t there but it didn’t update the simulated presence.


#18

I changed the time to execute to every 30 seconds just for testing


#19

Can you flip the trace switch and see if that else block ever gets executed?


#20

Sorry back
I think I was too hasty :slight_smile:
I’ve just left it for 5 mins to see and it has changed now .
I’ve realised the router page is slow to update so is causing a delay flipping the presence.
But tried a few times now and it’s working.
I don’t mind the delay as I want planning on running it about set 30 mins anyway.
Thanks so much for your help I really appreciate it :slight_smile: