How can I send a slider value from JavaScript to a Python motor controller?

0
1
Asked By VelvetMango42 On

I'm building a local web interface for an over-engineered desk fan. The page has two buttons and a slider, and the browser-side controls are already working. Now I need to send the slider's current value from JavaScript to a Python script that controls the fan motor. The page is currently being served as static content by Nginx in a container. What's the right way to connect the browser code and the Python process? Is this an inter-process communication problem, or should I use another approach?

1 Answer

Answered By QuietCedar7 On

The usual solution is to run a small Python web server alongside the static page. Have the JavaScript call an endpoint on that server with fetch(), sending the slider value whenever it changes or when the user releases the slider. The Python handler can validate the value and pass it to the motor-control code. You don’t need to duplicate the webpage—the static Nginx server can continue serving the HTML, CSS, and JavaScript while the Python service acts as a separate API.

VelvetMango42 -

So the browser would keep loading the page from Nginx, but send the control values to a separate local Python endpoint? I was assuming the Python service would have to serve the same page too.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.