toddaustin07 / edgebridge

Forwarding Bridge Server for SmartThings Edge drivers
Apache License 2.0
39 stars 19 forks source link

Forwarding Edge Driver HTTP Requests Post with json payload example #7

Open timttran opened 1 year ago

timttran commented 1 year ago

hi TAustin,

Could you please show me an example how to forwarding Edge Driver HTTP Requests using POST method with a JSON payload? I try to do it with your WebRequestor Edge Driver and include a JSON body payload but it's notworking. I got the forwarding to work with the GET method.

Please take a look at the screenshot attached.-- Thanks

Screenshot 2023-07-24 012408

toddaustin07 commented 1 year ago

Hi - sorry for the delay in responding. Can you provide a screenshot of your webrequestor request settings?

Generally, you don't need to use edgebridge unless you are trying to reach an address outside of your LAN. Here it looks like you are sending something directly to another device on the same subnet as your hub. So you would use something like this as your HTTP request in webrequestor:

Web Request #1: POST:http//192.168.1.69:8080/speak
Web Request #1 - Body:  {"msg":"testing", "vol":90}
Web Request #1 - Headers: Content-Type=application/json
timttran commented 1 year ago

Hi Todd,

I don't know if you could recall but it was me that contacted you awhile back regarding the WebRequestor could not successfully send a POST nor a GET request to my local Rest API server. For this reason, I ended up using your awesome EdgeBridge to overcome this problem. I use it to forward all local calls to my local API server.

Anyway, I manage to get your EdgeBridge to work with my local api server which made me very happy!

Just on a different note, on the WebRequestor, there's a length limit on how much you can enter when using the option POST/GET URL if not using the Pre-configured option. I was wondering if you could make an adjustment for this

Thanks, Tim

toddaustin07 commented 1 year ago

Ahhh, OK. Gotcha. That's pretty strange actually; it may have something to do with network configuration.

Regarding the length limit you are hitting. How are you initiating the request, through an automation or Rule? And what length limit are you seeing? I don't know if this a platform limitation, or something I can adjust for...

timttran commented 1 year ago

I am using the Automation in ST app. If I paste the whole forwarded string from the Pre-configured into either the POST/GET URL, it got cut-off.

Right, I have the same concern that you may not be able to fix this due to ST app platform.

toddaustin07 commented 1 year ago

Can you try it with a Rule? I don't think you'd run into field size limitations there since you are providing the argument as a string.

Example: https://github.com/toddaustin07/webrequestor#using-custom-http-requests-from-automations-or-rules

timttran commented 1 year ago

Yes...I will try that. I saw your example in the guide, but I prefer to use ST app Automation, it's quick and convenient whereas Rules is all JSON based, makes it very hard to code and maintained.

Also on another issue with the WebRequestor, which I believe I already have a ticket open for it. The issue is that the webrequestor body tends to capitalized the very first character as soon as I confirm and save the body. The JSON payload that I work with is case sensitive so it rejected.

timttran commented 1 year ago

Thanks for the hard work Todd. I thought I was going to give up ST app and go with Home Assistant but now with your EdgeBridge and Webrequestor, it changes the game!

toddaustin07 commented 1 year ago

I responded to your other issue with the capitalization. But it sounds like my answer may not help if you are confident that the capitalization is actually being sent to your device. I may have to try reproducing it here.

timttran commented 1 year ago

thanks Todd, I'll take a look at that ticket....Yes, I did confirm it with another tool, it's problem for me.