Internal Web Request not working


#1

1) Give a description of the problem
I found a project on smartthings forum that allows me to broadcast announcements through google assistant . I’ve setup Node.js on my raspberry pi 3 and everything runs great. I’ve used postman to test out the announcements and works great. I’m currently using it with Tasker for certain things and that works great. The only thing not working is webCore. I’ve made a simple piston that announces if the front gate is open/closed. webCore says it’s sent the post command, but node.js does not announce anything.

I then take the same command and copy and paste it into postman and it works great.

2) What is the expected behavior?
when I make a JSON post (http://192.168.6.64:8801/customBroadcast?text=“Front Gate is Open”) I expected the command to be sent to google via node.js and an announcement be made through google home.

3) What is happening/not happening?
Although the logs says that it sent the command, nothing is really being sent.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
7/13/2018, 5:11:36 PM +240ms
+2ms ╔Received event [Front Outdoor Gate].contact = open with a delay of 689ms
+150ms ║RunTime Analysis CS > 21ms > PS > 59ms > PE > 69ms > CE
+152ms ║Runtime (39601 bytes) successfully initialized in 59ms (v0.3.000.20180224) (150ms)
+153ms ║╔Execution stage started
+162ms ║║Comparison (enum) open is (string) open = true (1ms)
+163ms ║║Cancelling condition #5’s schedules…
+164ms ║║Condition #5 evaluated true (6ms)
+165ms ║║Cancelling condition #1’s schedules…
+166ms ║║Condition group #1 evaluated true (state changed) (8ms)
+168ms ║║Cancelling statement #3’s schedules…
+192ms ║║Executed virtual command [Front Outdoor Gate].sendPushNotification (17ms)
+220ms ║║Executed virtual command [Front Outdoor Gate].sendSMSNotification (23ms)
+226ms ║║Sending internal web request to: 192.168.6.64:8801/customBroadcast?text=“Front%20Gate%20is%20Open”
+229ms ║║Executed virtual command [Front Outdoor Gate].httpRequest (4ms)
+230ms ║║Requesting a wake up for Fri, Jul 13 2018 @ 5:11:56 PM PDT (in 20.0s)
+234ms ║╚Execution stage complete. (81ms)
+236ms ║Setting up scheduled job for Fri, Jul 13 2018 @ 5:11:56 PM PDT (in 19.995s)
+244ms ╚Event processed successfully (244ms)


#2

Put the text in a variable and send that variable with the web call.

Similar to this… {data} will have your custom text message


#3

When you start Assistant Relay, are you getting the welcome message? I have not been able to get the relay to work at all for some time now and I’m not the only one. There are several people on the ST community that aren’t as well. If you do get the “Assistant relay is now running for…” message broadcast over your GH devices when you start the relay, then it is working. If you don’t hear it, then the problem isn’t webcore.

Also remember to include your username that you used when you setup relay. So, it would be:
http://IP:PORT/customBroadcast?text=Message and you don’t have to worry about spaces&user=username

But like i said, the problem is most likely Relay.


#4

When I start it up, it does say that my google assistant is online. I can use it via tasker without any issues. just webCore is a problem…can’t get it to work there.


#5

Thanks for the suggestion. I created a variable with dynamic text (open / Close) but when I inserted into the URL, it doesn’t seem to work. can us show me what I’m supposed to do in the “Make a Post Request” parameter window that pops up? Thanks


#6

I did…did you not want to try that?


#7

I am not familiar with the devices used here but from the description it seems there is some confusion. It looks like the goal is to pass a custom message as a parameter to Assistant Relay. The documentation for that relay server is a bit confusing since it shows POST requests with parameters in the URL rather than the request body, but here are two things to try:

First, Assistant Relay is expecting FORM rather than JSON format and a parameter named text rather than data. Create a variable named text, set it to “Front Gate is Open” then use it in your request

That would be the normal way to do a POST request, but if Assistant Relay only supports the format shown in the documentation you would need to add the message in the URL instead of the request body, like this:


#8

Did you solve the issue? I am having exactly the same problem.


#9

I use the jishi sonos solution on my rasp Pi .

Not sure if it helps I can just use a get request
e.g
192.168.1.100:5000/lounge/say/hello

where
5000=port used by node.js app
lounge=name of sonos device
say=speak command
hello=text to be spoken


#10

When I call a similar internal POST request “192.168.1.100:5000/assistant” from the browser or Postman, I get the response and everything works fine. But when I call it in WebcoRE piston, it does not work. It seems WebcoRE is not able to reach any internal web server.
All my other pistons that don’t involve a web request work just fine!


#11

Does it work with a get request? Can you post the log? Also display the response variable after the get to see what was returned from the get request.

I have had a few problems with webcore get requests, I had a test page on an internal web server created with MS word, that just returned “test page” in a browser. But webcore just timed out when I tried to access it.


#12

Here is the full log for a GET request to a node.js server that I setup. I am logging the $response, which is getting printed as “[:]”. I was expecting something like this “[{“id”:1,“name”:“Lloyd”,“age”:43},{“id”:2,“name”:“Mona”,“age”:34},{“id”:3,“name”:“Francesco”,“age”:24}]”

04/09/2020, 11:24:51 +455ms
+0ms ╔Received event [Motion Sensor].motion = inactive with a delay of 37ms
+53ms ║RunTime Analysis CS > 12ms > PS > 4ms > PE > 37ms > CE
+55ms ║Runtime (39259 bytes) successfully initialized in 4ms (v0.3.110.20191009) (54ms)
+56ms ║╔Execution stage started
+62ms ║║Comparison (enum) inactive changes_to (string) active = false (1ms)
+63ms ║║Cancelling condition #5’s schedules…
+64ms ║║Condition #5 evaluated false (5ms)
+65ms ║║Cancelling condition #4’s schedules…
+65ms ║║Condition group #4 evaluated false (state changed) (6ms)
+67ms ║╚Execution stage complete. (11ms)
+68ms ╚Event processed successfully (68ms)
04/09/2020, 11:24:50 +40ms
+1ms ╔Received event [Home].time = 1599211491688 with a delay of -1648ms
+126ms ║RunTime Analysis CS > 19ms > PS > 6ms > PE > 101ms > CE
+128ms ║Runtime (39258 bytes) successfully initialized in 6ms (v0.3.110.20191009) (126ms)
+129ms ║╔Execution stage started
+140ms ║║[:]
+141ms ║║Executed virtual command log (1ms)
+143ms ║╚Execution stage complete. (13ms)
+144ms ╚Event processed successfully (143ms)
04/09/2020, 11:24:31 +560ms
+1ms ╔Received event [Motion Sensor].motion = active with a delay of 45ms
+67ms ║RunTime Analysis CS > 13ms > PS > 4ms > PE > 50ms > CE
+70ms ║Runtime (39264 bytes) successfully initialized in 4ms (v0.3.110.20191009) (67ms)
+70ms ║╔Execution stage started
+76ms ║║Comparison (enum) active changes_to (string) active = true (0ms)
+78ms ║║Cancelling condition #5’s schedules…
+79ms ║║Condition #5 evaluated true (4ms)
+79ms ║║Cancelling condition #4’s schedules…
+80ms ║║Condition group #4 evaluated true (state changed) (6ms)
+82ms ║║Cancelling statement #1’s schedules…
+92ms ║║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+93ms ║║Calculating (string) command : (string) hello world >> (string)
+97ms ║║Calculating (string) , (string) broadcast >> (string) broadcast
+100ms ║║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+101ms ║║Calculating (string) broadcast : (boolean) true >> (string)
+104ms ║║Calculating (string) , (string) user >> (string) user
+107ms ║║Invalid ternary operator. Ternary operator’s syntax is ( condition ? trueValue : falseValue ). Please check your syntax and try again.
+108ms ║║Calculating (string) user : (string) Himanshu >> (string)
+115ms ║║Sending internal web request to: 192.168.178.27:8000/users
+127ms ║║Executed virtual command httpRequest (16ms)
+128ms ║║Requesting a wake up for Fri, Sep 4 2020 @ 11:24:51 AM CEST (in 20.0s)
+131ms ║╚Execution stage complete. (61ms)
+132ms ║Setting up scheduled job for Fri, Sep 4 2020 @ 11:24:51 AM CEST (in 19.996s)
+139ms ╚Event processed successfully (139ms)


#13

try looking at the $args variable after the call. I think this holds your JSON data
e.g
id=$args.id
name=$args.name
age=$args.age


#14

I don’t see any logs in my server, so I think WebcoRE is not able to reach it. But my browser or any other device in my network seems to do it just fine.


#15

Just rechecked, I think the $response of [:] indicated no response. I use this to check my NAS is running, if I get this response when trying to access its admin page, it indicated the NAS is down.

Are you just using the ip address or http://? I only use the ip. You should see the servers response in $response even if its an error message.

I’m not sure if the invalid ternary operator errors are causing any issues. It might be worth writing a simple piston to check just the web call and posting it, along with the log.


#16

I tested with adding http:// and without. I tested with a simple piston as well, the same issue and same response.
Thanks for your responses, I’ll certainly post here if I am able to solve it.


#17

I’m a bit stumped on this!

I assume your node.js server and hub are on the same network/subnet? Could there be any firewall rules on the server blocking the webcore request?

I’ve had problems sending data back from node.js if the writeHead method was missing/incorrect. In this case it worked through the browser, but webcore just waited 20 secs then timed out. However, this doesn’t appear to be happening for you, but wonder if it could be a similar issue.

Can you access anything else on your network? Anything will do, as I mentioned I just access my NAS’s admin page to check its on. It returns an authorisation error message in $response.


#18

All my devices are in the same network. I even disabled the firewall on the router to test. I don’t see any issues with any devices in my network. For example, I can get the correct response from the noje.js server from my phone browsers.
I am running the server on a Macbook Pro and have not set any custom firewall rules.


#19

Now I setup a node.js server on a Raspberry Pi in the same network and I faced the same problem. So I think there is some issue with either my network router or WebcoRE.


#20

ST or Hubitat?