-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement WebQuery Command #13209
Implement WebQuery Command #13209
Conversation
Thanks that's a smart approach. Did you measure the difference in code size? |
Code size increase is 1k |
Add command ``WebQuery <url> GET|POST|PUT|PATCH [<headers>] <body>`` to extent HTTP requests (#13209)
Implemented today. |
Nice function, I use it extensively :-) |
You can use rules to detect wifi connectivity: By webservice I assume you mean the server you are trying to connect to ? |
Many thanks for your fast answer, I will start to try your solution. I'm using WebQuery in scripting but still newbie ! ;-) My device is looping calls to my web service. To simulate an issue on the web service server side, I remove the web service and watch what happens. The system seems to bufferize something since I always get {"WebQuery":"Done"} even when the web service is no longer responding. 20:35:42.462 SCR: performs "WebQuery http://xxxx?id=test GET" I do not see what's wrong but I get the same behaviour with WebSend. When tasmota is starting with an inexisting web service, it detects correctly when the web service is running. But then, if the web service drops again, tasmota seems to go on with the last answer received and {"WebQuery":"Done"}. Any idea of what should be done ? |
Did a small test with WebQuery, first a working URL (got data), and switching the other device off, I got the expected |
Thanks for your check. On my side I checked what happens when calling the web service which is removed, it returns a 404 error and a system fault string. (I use an ESP8266-based athom board) |
Then the connection was ok, hence no reason for getting a "Connect failed". And it does indeed look like code 404 does not give error symptoms, and still no data with a very short 404 response text. |
Understood ! My script needs to trigger an audible alarm when the tasmota device does not get a correct web service answers after N bad retries. |
One workaround could be to yell if you did not get a valid response within a reasonable time frame. Then, you're also avoiding any dependence of what error symptoms (or not) you may get in varied situations. |
It would be a good solution if I could distinguish a good answer from a bad answer. |
WebQuery is not returning the last answer in case of errors. Any caching you may experience is outside of what Tasmota controls or can act on. Inside of what Tasmota gets, it can work great if you do not worry about trying to detect badness, but only detect good answers. Then you can yell if last good answer was too long ago. |
Description:
Implements new WebQuery command. The command allows for GET, POST, PUT, and PATCH HTTP Queries, complete with Request Headers and request body (when applicable).
Syntax examples:
WebQuery http://192.168.1.1/path GET
: Sends HTTP GET http://192.168.1.1/pathWebQuery http://192.168.1.1/path POST {"some":"message"}
: Sends HTTP POST to http://192.168.1.1/path with body {"some":"message"}WebQuery http://192.168.1.1/path PUT [Autorization: Bearer abcdxyz|Second:Header] potato
: Sends HTTP PUT to http://192.168.1.1/path with authorization header, a second header, and body "potato"WebQuery http://192.168.1.1/path PATCH patchInfo
: Sends HTTP PATCH to http://192.168.1.1/path with body "patchInfo"An unlimited number of headers can be sent per request, and a body can be sent for all command types. The body will be ignored if sending a GET command
This command enables Tasmota to send advanced web queries in addition to GET. It is my vision that this is an open-ended command that can control other SmartHome Devices, such as Philips Hue Hubs, the vacuum cleaner mentioned in #12249, and anything else that can be controlled over HTTP. It is designed to be more flexible than other Tasmota HTTP PRs I've seen
Let me know if you think anything needs changed!
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass