Some help please with a HttpGet piston


#21

no problem! glad it’s working! This was a good learning experience for me as well. Win win!


#22

I don’t suppose you could explain what the bottom “log info” section is doing.
I understand the 1st one but that ones thrown me :frowning:


#23

From the wiki:

indexOf
Syntax
integer indexOf(string haystack, string needle)
Returns
Returns the character index of the first occurrence of needle inside haystack
Examples
indexOf(“hello world”, ‘l’) outputs 2

Basically, it was a double check that it actually found something. If it finds the string we specify, it returns the character index of where exactly it found it. We’d know if something was wrong if the contains() function returned false, but a non-negative number from the indexOf() function.

Not that I don’t trust the functions… more that I don’t trust myself to use them correctly :slight_smile:


#24

Can’t wait until I understand all this some more :slight_smile:
Hopefully if I keep reading up and messing with pistons ill get there.
One last thing :slight_smile:
How does the “IsNathanhome” variable become true or false I can’t seem to figure that part out.
It’s just that I see …
Ifnathanhome is not true
Then set variable to true
Else
Set false
So if it’s not true set it true otherwise set it false lol


#25

image

It gets set right after the arrived() or departed() actions get executed. You don’t want to set it up in the define section or it will get set to true/false every time the piston spins up.


#26

Ah right just re read it I think I’ve got a better grasp now.
So if line 29 isn’t true it can’t move on to the variables :slight_smile:
I’ll leave you alone now , Sorry for all the questions :slight_smile:
Thanks again for all your help.


#27

no worries! Gotta pay it forward for all the help I’ve gotten in the past. Not necessarily here, but plenty of other places.


#28

Hi
Sorry to bother you again but the piston is acting strange for some reason :frowning:
When I first set it up I tested it a few times with my Mac address and it worked fine so then i renamed everything and put my Son’s Mac address and it worked the 3 times he came home and left but then last night (UK time) about 5.30pm it just set it to away and I checked and the piston kept saying false for the Mac address being found but it was there as I checked.
So I left it and checked this morning and it detected it once but at this moment in time it’s showing on SmartThings as present but WebCore is saying it’s false but not changing it but it looks like it’s not getting any data from the router.
Do you have any ideas
I put the trace on but I’m not sure how that works :frowning:
Thanks




#29

Yeah, I could see where that could be a problem if the variable and the presence ever got out of sync. Let’s simplify.

Note, I added a log action to just see what a response looks like from your router… Make sure it looks like what you’re expecting.


#30

I was literally coming in then to delete my post :blush: as I know what’s happened.
And it’s all my fault lol.
What it was is with it being a simulated presence sensor when it was set as away on the list of things it displayed “Not present” unlike my normal presence that say "away"
And it won’t let me modify the device handler so I created a new device handler from template and selected the simulated presence sensor and then modified the text.
And I thought it worked ok but WebCore is obviously unable to change it now as when I realised just now and changed it back it works great again lol
But do you think this new piston is better anyway?
Sorry about that


#31

That’s great!

The new piston is probably still better because it does away with some complexity. However, make sure that status on the presence sensors match up to what your DTH reports. Also, if you do end up importing this one, delete the full $response logging. No need to spam the logs with that. In fact, get rid of the indexOf() logging as well.

Then again… if it ain’t broke… :slight_smile:


#32

Thanks i’ve changed that and it seems to be working great now :slight_smile:
When you say delete the full $response logging do you mean to delete the line >
"Log info "{$response,macaddress)}"
I thought the contains function searched in that for the mac address or does that look in the first GET request.


#33

The logging actually doesn’t do anything functional for the piston, it just provided some additional feedback as to whether or not we were on the right track. Now that it’s working, you shouldn’t need it. That said, it’s useful for future troubleshooting if the need ever arises. However, the line for log info "{$response}" is just completely unnecessary so I would delete it.


#34

Thanks done now
Do you think the every 45 seconds is ok for the router ?
didn’t want to put too much stress on it so thought about every 5 mins but wasn’t sure how much a issue it would be.


#35

It all really kind of depends on the router. I doubt that 45 seconds would be really that stressful for a modern router. 5 minutes is definitely ok.


#36

Rube Goldberg has got nothing on you two guys! LOL I’m just glad you got it working. :slight_smile: