While... Do loops don't seem to be looping


#1

Hi all

I’m trying to get a camera to take pictures whilst my door is open - the camera points right at it.
My camera can be triggered with a request to username:[email protected]:8080/0/action/snapshot (It’s a webcam, plugged into my router running Motion)

I can navigate to that address (with the right credentials!) from a browser, and I see a .jpg file pop up into my router’s shared storage. All good. However trying to write that into a while loop doesn’t work so well.


(note - nicely, WebCoRE has swapped the URL containing my password with webcore.co - not sure why, but in reality I’ve got that 196.168.0.1 address in there)

I want it to start taking 2-second interval pictures all the time the door is open. What I see in the logs is

9/11/2017, 3:19:12 PM +652ms
+1ms ╔Received event [Front Door].contact = closed with a delay of 593ms
+102ms ║RunTime Analysis CS > 16ms > PS > 28ms > PE > 60ms > CE
+112ms ║Runtime (35274 bytes) successfully initialized in 28ms (v0.2.0e7.20170906) (109ms)
+113ms ║╔Execution stage started
+130ms ║║Comparison (enum) closed is (string) open = false (2ms)
+132ms ║║Cancelling condition #5’s schedules…
+133ms ║║Condition #5 evaluated false (10ms)
+134ms ║║Cancelling condition #1’s schedules…
+135ms ║║Condition group #1 evaluated false (state changed) (12ms)
+138ms ║╚Execution stage complete. (26ms)
+148ms ╚Event processed successfully (148ms)
9/11/2017, 3:18:57 PM +691ms
+2ms ╔Received event [Front Door].contact = open with a delay of 748ms
+158ms ║RunTime Analysis CS > 26ms > PS > 41ms > PE > 91ms > CE
+166ms ║Runtime (35276 bytes) successfully initialized in 41ms (v0.2.0e7.20170906) (163ms)
+167ms ║╔Execution stage started
+186ms ║║Comparison (enum) open is (string) open = true (3ms)
+188ms ║║Cancelling condition #5’s schedules…
+189ms ║║Condition #5 evaluated true (11ms)
+191ms ║║Cancelling condition #1’s schedules…
+192ms ║║Condition group #1 evaluated true (state changed) (14ms)
+195ms ║║Cancelling statement #2’s schedules…
+206ms ║║Sending internal web request to: [MY USERNAME&PASSWORD]@192.168.0.1:8080/0/action/snapshot
+209ms ║║Executed virtual command httpRequest (4ms)
+210ms ║║Requesting a wake up for Mon, Sep 11 2017 @ 3:19:17 PM BST (in 20.0s)
+218ms ║╚Execution stage complete. (51ms)
+220ms ║Setting up scheduled job for Mon, Sep 11 2017 @ 3:19:17 PM BST (in 19.992s)
+241ms ╚Event processed successfully (241ms)

No snapshots are taken, and it only seems to run once even though I had the door open for 20 seconds or so.


#2

Try giving it a go wrapping the while loop inside an If statement.

If contact sensor is open
Then
While contact sensor is open
Do
Make a get request xxxxxxx
Wait x seconds.


#3

Why did you change the actions to asychronus?

Swap that back to synchronous.


#4

Well spotted. I missed that one!


#5

Aaah, I’d changed it as a very technical “let’s just press buttons and see”. I’ve since changed it back and it still doesn’t work.
I’ll try the If loop as a wrapper.

Also - it doesn’t even take one snapshot, even though the log says it runs through the While once. Nothing. Nada.


#6

Nope - still exactly the same, just the logs show a few more steps as the logic navigates the If first and then the While


#7

So when you visit that URL with all your information it then saves the image into a shared folder?

I would suggest starting basic and building from there after you find how things work.

If (simulated switch/something you can easily manipulate) changes to on
Then
Make request to URL
End if


#8

Try it with GET method, JSON content type, don’t send any variables.


#9

I’ll try simplifying the piston to just an if… then and see if that works.

Thanks all


#10

When you get a chance please reply to the PM I sent you on the ST forum… let’s get rid of that nasty red ‘not verified’ flag for you :wink:


#11

Tried JSON/GET, nothing.
Tried just “if the dining room light turns on, take snapshot” (because that’s the room I’m sat in and it saves getting up to open the door) - logs show exactly the same, that HTTP request and then a 20 second timer starts and nothing else.

Weirdly, my other piston (that sends my.web.server:8080/0/detection/pause when SHM disarms, and /start when SHM arms) was working fine two days ago, and now isn’t. Pretty sure I haven’t changed that! Exactly the same, GET/FORM, same web server, but that was just a straight “when SHM changes to armed”.

I know that was working as I sat at my PC, refreshing the camera status page, arming and disarming SHM to see.

Bizarre.


#12

Question: Is this running on a server somewhere, or locally on my ST Hub?

Essentially, is it failing because my snapshot request is 192.168.0.1:8080/0/action/snapshot - ie. a local address? This will work on my home network but I’ll need to use an external IP, and do some port forwarding if WebCoRE is running externally.


#13

You will need to use your wan IP and port

Don’t know why I didn’t think of this sooner.


#14

I was convinced I’d had it working on a local IP address previously, bit clearly not.

I’ll go and do a bit of port forwarding and report back :slight_smile:


#15

Sounds good!