toddaustin07 / webrequestor

Web Requestor Edge Driver
Apache License 2.0
21 stars 8 forks source link

Can't get it to work in ST app #7

Closed timttran closed 1 year ago

timttran commented 1 year ago

Hi,

This is an awesome feature for Samsung ST app! I've been waiting for this feature since WebCore went away.

However, I can't get this to work at all. I try to get it to send a simple GET method URL "http://192.168.1.69:8080/speak/100/test" to my local REST API server but it's not taking it. I tested the same URL on the device's Safari browser and it's working fine.

Please take a look at the files attached and advise how to get this working on SmartThings app.

Thanks and appreciate it much, Tim

IMG_0335 Safari

toddaustin07 commented 1 year ago

Could be a few things.

I'm not sure what your screenshot is showing me. What HTTP code is being displayed on the webrequestor device Controls screen? Where are you seeing this message "{"status":"successful"} ??

timttran commented 1 year ago

Thank you Tod for getting back with me. I really need this feature for my ST app, and hopefully you can help me get this fixed up.

I don't think it ever made it to my local server (on the same subnet) from the WebRequestor, however when I paste the same URL "http://192.168.1.69:8080/speak/100/test", onto my iPhone Safari (2nd image) and it works fine, which is the response result "{"status":"successful"} it got back, meaning nothing is blocking on the server from receiving it from the mobile device. I even turn off the Windows firewall and vpn. I wonder if the SmartThings hub is blocking the WebRequestor from sending it out to my server. I also tried it with the headers as "Content-Type=text/html, Accept=application/json" and it's still not working.

Is there a log on the hub that I can review?

I really need this feature, please advise how to get this working.

Thanks, Tim

toddaustin07 commented 1 year ago

I'd recommend you download the SmartThings CLI - that way you can run logs for the driver to confirm if your requests are being sent or if any errors are happening. You can download it from here: https://github.com/SmartThingsCommunity/smartthings-cli/releases

It is a command line interface so don't try to run it from your desktop, but rather open a command prompt or terminal window, navigate to where you installed it, and use this command to start logging:

smartthings edge:drivers:logcat

The first time you run a CLI command, you may get a browser window opened where you will have to log in to your SmartThings account and give permissions. Once you complete that step, you can close the browser window and return to your terminal window, and the CLI command should continue.

You'll be prompted for your hub's IP address and to select the driver.

Once the logging is started, try invoking your request and monitor the log.

You can post the results here if you want me to look at it.

timttran commented 1 year ago

Thank you Todd for your guidance.

I follow your instructions and put together a small video clip of my test for you to see. As you will see in the video, I did a manual web request from Chrome browser and the API responded with a JSON string and my API server also logs what it'd received. However, when I run the SmartThings CLI tool and send the request from my iPhone ST app, the CLI log shows no response received. and my API server shows it doesn't receive anything.

Please pause the video and you can review the CLI log.....a BIG thanks for looking into this.

https://user-images.githubusercontent.com/25288383/232616548-c6591ccf-5e84-4ada-84d0-acf3e0dafae6.mp4

toddaustin07 commented 1 year ago

Well something is receiving the HTTP request because an HTTP 1.1 200 OK response is being sent back. It's just that the server doesn't seem to be doing anything with the request, as no data is returned, and of course there is no log on your server console.

It may be just a video resolution issue (I can't zoom in) and maybe I'm not seeing it right, but it looks like the parameter you are sending in the url is:

speak?msg-test

Whereas I think you are intending to send an equals sign (=), instead of a minus sign (-):

speak?msg=test

Could that be the issue or am I seeing that wrong?!

timttran commented 1 year ago

Thank you Todd for taking the time to help me out.
However, I am giving up. I've tried everything from turning off all firewalls, changing the web server's port and even changing its binding to a different NIC card, nothing is helping, I even tried it using Rules API and still same problem. Funny thing is that it did manage to send a couple of success randomly but no more after that, not consistent. I successfully calling the API with "curl.exe" on a different machine as well as from a any web browser. I believe something's on the ST hub is blocking it from sendin Random and seldom success, not consistent test with curl g out the request. You can take a look at the success test the files attached.

toddaustin07 commented 1 year ago

Well I'm really sorry we couldn't figure this one out. I see in the log you posted above that it was in fact successful, with an 200 OK returned. No additional body data was received though.

The only thing left to try is to run wireshark to capture the TCP packets between the hub and your server to see what exactly is going on, but that takes a bit more work to do.

What kind of device is your server? The reason I ask is there IS a known issue with some devices that don't handle multiple-packet messages correctly, and communications to those devices can fail using the built-in Lua HTTP library in Edge. But that is usually a problem with cheap-o IOT devices, not proper servers.

I'm glad you at least have the API approach to meet your need. I guess this one will have to remain a mystery!

Go ahead and close the issue if appropriate.