Using PUT requests

LanManMike
Posts: 7
Joined: Fri Jan 11, 2019 4:21 am

Using PUT requests

Postby LanManMike » Sat Apr 27, 2019 8:23 am

Hi all,
I am developing light controller using an ESP32 in Arduino (I am using the Platform IO IDE).

My controller serves a web page including some javascript that attaches to the the 'oninput' method of a Slider (range) control. This javascript sends HTTP PUT requests back to the ESP32 to change the intensity of LED on any change of the slider (range) control.

This all works well, however I can see that there are some issues when I look in the Chrome Debug Console. I can see that some of the PUT requests aren't getting a return and eventually timeout. Whist this isn't a major issue, if you move the slider fast enough, you can easily outstrip the ability of the system to return a response and you may end up with a value that wasn't the last value 'slid' to.

My basic questions is: Am I doing this in the wrong way ... HTTP Requests are cumbersome and time consuming at a network level. Should i be using some more direct method such as UDP. If so, can I send this from a HTML/CSS/Javascript webpage?

Thanks for your time
Regards
Mike

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: Using PUT requests

Postby boarchuz » Sat Apr 27, 2019 1:46 pm

On the browser side of things, you probably want to wait for a response (or timeout) from the last PUT before sending the next. Buffer any slider changes in the interim. Spamming is a bad idea.

On the ESP32 side, could you improve response times? Most notably, are you parsing the request, responding immediately, and then handing off the actual work to a separate task (efficient)? Or are you waiting until the work is done before responding to the http request (might be very inefficient depending on time taken to complete)?

LanManMike
Posts: 7
Joined: Fri Jan 11, 2019 4:21 am

Re: Using PUT requests

Postby LanManMike » Mon Apr 29, 2019 8:13 am

Hi boarchuz,
Thanks for getting back to me. Your ideas are well founded. I will look into using a synchronous (rather than async) web request so I always wait for a response, but this may result in 'jerky' controls.

I will also try sending a response straight away from the ESP32 and then handling the "work" which is really just to set the intensity of the LED in question.

I am not sure how to buffer requests at the web client end, but I'll have a look at that as well.

Thank you
Regards
Mike

LanManMike
Posts: 7
Joined: Fri Jan 11, 2019 4:21 am

Re: Using PUT requests

Postby LanManMike » Mon Apr 29, 2019 8:32 am

Hi All,
So I have cleaned up my code and put the HTML response right after it is received in the code.
I also changed to using Sync PUT requests rather than async.

No more issues with stray PUT requests timing out, however the controls do feel a little bit 'sticky'. It is good enough for what I want, so thanks to boarchuz for showing me the path to follow.

Regards
Mike

Who is online

Users browsing this forum: Google [Bot] and 45 guests