My use case is an ESP32-cam that serves two purposes:
- HTTP feed (accessed by a Raspberry Pi 5 which processes stream and provides a response)
- Servo Motor microcontroller: Receives response from Raspberry Pi 5 and signals servo.
I am using arduino libraries and can accomplish task 1) easily with the wifi library and esp_camera library.
I have spent hours trying to accomplish 1) and 2) simultaneously. Is there a protocol or library I am unaware of? I know a lot about coding, but know little about principles of servers and wifi. Any keywords or advice on how to use the esp32 to serve up the http stream and receive a response from the Raspberry Pi would be helpful.
1 Answer 1
I assume the ESP is the HTTP server and the Raspberry Pi is the client.
What you plan to do is typically achieved by having the server provide multiple "endpoints". And endpoint is typically an URL path that elicits a specific response, often depending on the HTTP method. For example:
The request
GET /
would provide the home page. This is a static HTML file served by the ESP from its file system. It defines the UI of your Web application, and may reference external resources (images, CSS, JavaScript) that are also served statically. The JavaScript code is the client-side of the application, and it issues the other requests.GET /stream
would provide the raw video stream.POST /servo
would instruct the ESP to move the servo. The request payload may look something likeangle=42
. Some people use GET requests for this type of interaction: this would not conform to the HTTP semantics, but may be useful if your libraries make it hard to handle POST requests.
The way you implement this depends on the libraries you use. An HTTP
library would typically let you write a callback for an endpoint, and
then you tell it "whenever you get a POST
request for the path
"/servo"
, please call this function of mine to handle the request".
Check the API documentation of your libraries for details.
From the Raspberry Pi, you can test a POST endpoint with the -d
(like
"payload data") option of the curl
command-line program:
server=... # IP address of the ESP server
curl $server/servo -d 'angle=42'
-
Thank you so much for the thoughtful response. I’ll jump into it and explorejmarywien– jmarywien2025年05月30日 02:04:46 +00:00Commented May 30 at 2:04
HTTP feed (accessed by a Raspberry Pi 5
... think about it, the Pi is already sending data to the ESP32