I tried with SmartThings.
Internal Web Request not working
If you’re using POST, you must be sending data? What does that look like? You might have to escape some special webcore characters, that’s usually where the invalid ternary operator error shows up.
Try npx http-echo-server
on your MBP and point a piston at your laptop’s IP with the port that the echo server uses. That should just respond to any request with all of the request headers so that you can see the response both in the terminal and the piston. In your case it sounds like it may show nothing.
I’m on the 192.168 local subnet as well and my hub doesn’t have any trouble connecting to other devices on the network, so I don’t think it’s a clear-cut webCoRE problem as long as your smart app is up-to-date.
I tried npx http-echo-server
with a GET request, but the same problem. Worked fine with Postman as it logged:
Blockquote
[server] event: connection (socket#1)
[socket#1] event: resume
[socket#1] event: data
–> GET / HTTP/1.1
–> User-Agent: PostmanRuntime/7.26.3
–> Accept: /
–> Cache-Control: no-cache
–> Postman-Token: 3efbbebe-1ac0-41d2-98b8-3eebd6a69d3f
–> Host: 192.168.178.27:3000
–> Accept-Encoding: gzip, deflate, br
–> Connection: keep-alive
–>
–>
[socket#1] event: prefinish
[socket#1] event: finish
[socket#1] event: readable
[socket#1] event: end
[socket#1] event: close
But no logging when run from WebCore.
Here are the full logs:
+1ms ╔Received event [Home].time = 1599234211962 with a delay of -1933ms +39ms ║RunTime Analysis CS > 18ms > PS > 4ms > PE > 16ms > CE +41ms ║Runtime (38390 bytes) successfully initialized in 4ms (v0.3.110.20191009) (39ms) +42ms ║╔Execution stage started +43ms ║╚Execution stage complete. (1ms) +44ms ╚Event processed successfully (44ms) 04/09/2020, 17:43:28 +919ms +1ms ╔Received event [Motion Sensor].motion = inactive with a delay of 29ms +27ms ║RunTime Analysis CS > 11ms > PS > 3ms > PE > 12ms > CE +29ms ║Runtime (38386 bytes) successfully initialized in 3ms (v0.3.110.20191009) (27ms) +30ms ║╔Execution stage started +36ms ║║Comparison (enum) inactive changes_to (string) active = false (0ms) +37ms ║║Cancelling condition #2’s schedules… +38ms ║║Condition #2 evaluated false (4ms) +38ms ║║Cancelling condition #1’s schedules… +39ms ║║Condition group #1 evaluated false (state changed) (6ms) +41ms ║╚Execution stage complete. (12ms) +42ms ╚Event processed successfully (42ms) 04/09/2020, 17:43:11 +876ms +1ms ╔Received event [Motion Sensor].motion = active with a delay of 50ms +46ms ║RunTime Analysis CS > 22ms > PS > 5ms > PE > 19ms > CE +48ms ║Runtime (38391 bytes) successfully initialized in 5ms (v0.3.110.20191009) (46ms) +49ms ║╔Execution stage started +55ms ║║Comparison (enum) active changes_to (string) active = true (1ms) +56ms ║║Cancelling condition #2’s schedules… +57ms ║║Condition #2 evaluated true (5ms) +58ms ║║Cancelling condition #1’s schedules… +59ms ║║Condition group #1 evaluated true (state changed) (7ms) +62ms ║║Cancelling statement #4’s schedules… +72ms ║║Sending internal web request to: 192.168.178.27:3000 +84ms ║║Executed virtual command httpRequest (17ms) +85ms ║║Requesting a wake up for Fri, Sep 4 2020 @ 5:43:31 PM CEST (in 20.0s) +89ms ║╚Execution stage complete. (40ms) +90ms ║Setting up scheduled job for Fri, Sep 4 2020 @ 5:43:31 PM CEST (in 19.996s) +98ms ╚Event processed successfully (98ms)
Web Requests are not working, can't access API's etc?
Do you see a counter going up if you trace the execution?
Your log (17:43:11) looks as though its setting an event to wake up in 20 secs, so maybe the request is timing out? Before that happens, the motion stops, cancelling the piston and running the no motion code.
Can you try a piston with just the web calland a log of the $response variable, and hit the test button.
Here is the log:
+1ms ╔Received event [Home].time = 1599237252727 with a delay of -1682ms +38ms ║RunTime Analysis CS > 22ms > PS > 5ms > PE > 11ms > CE +41ms ║Runtime (36384 bytes) successfully initialized in 5ms (v0.3.110.20191009) (38ms) +41ms ║╔Execution stage started +50ms ║║[:] +51ms ║║Executed virtual command log (1ms) +53ms ║╚Execution stage complete. (12ms) +54ms ╚Event processed successfully (54ms) 04/09/2020, 18:33:52 +664ms +1ms ╔Received event [Home].test = 1599237232664 with a delay of 0ms +43ms ║RunTime Analysis CS > 24ms > PS > 6ms > PE > 13ms > CE +46ms ║Runtime (36372 bytes) successfully initialized in 6ms (v0.3.110.20191009) (44ms) +47ms ║╔Execution stage started +51ms ║║Cancelling statement #1’s schedules… +58ms ║║Sending internal web request to: 192.168.178.27:3000 +61ms ║║Executed virtual command httpRequest (3ms) +62ms ║║Requesting a wake up for Fri, Sep 4 2020 @ 6:34:12 PM CEST (in 20.0s) +84ms ║╚Execution stage complete. (38ms) +91ms ║Setting up scheduled job for Fri, Sep 4 2020 @ 6:34:12 PM CEST (in 19.973s) +98ms ╚Event processed successfully (98ms)
Is it possible that your hub is on a guest network or otherwise prohibited by your router from connecting to other devices on the network? This seems to be outside of webCoRE, but maybe someone knows of another smart app that could test sending local web requests from the hub to rule out webCoRE?
It looks as though a request is send, then 1682ms later, webcore responds in some way.
Can you put a log in your node.js to see if its being called?
I’m no jode.js expert, but I had trouble getting webcore to see a response from my node.js app, although it worked fine putting the same URL in a browser. I ended up using the following to reply
res.writeHead(200, {‘Content-Type’: ‘text/html’});
res.write(reply);
res.end();
I already have logging enabled in the node.js server that works for all the other requests but not with webcore
I used SharpTools + Tasker App to get the internal web request working with ST. But this is not the ideal solution as my phone needs to be connected to my home network. So the issue is pin-pointed to my webCoRE. I removed and reinstalled webCoRE, still no luck.
I admit, I have not read all of the posts two years old, but I agree with @eibyer here:
Also worth noting is the potential mis-spelling on line 13
I am curious… Instead of dumping data into variables
, have you tried testing the GET using one long URL? (exactly like the single line you use in a web browser, that works)
Yes, I have tried that. The web request does not reach the server, hence no response.
So, here is the final update. Removing the ST hub, Location and re-setting everything up solved the issue. I still could not figure out what went wrong before, something with the ST hub, I think.
Thank you all for your response. Cheers!