ESP-IDF等效于Arduino的Wificlient.Write()fucntionality

发布于 2025-02-11 00:39:53 字数 1682 浏览 2 评论 0原文

我使用ESP32-CAM使用ESP-IDF框架进行视频流。我能够在ESP32-CAM上创建服务器,并能够成功地流视频。对于流媒体,我将使用content-type的HTTP协议:Multipart/X-Mixed-Replace; boundard =“ part_boundary” \ r \ n标题,它运行良好:)

现在,我想在相机中添加一个伺服电机以远程调整锅。我想到了两种方法。

  1. 为伺服器创建另一个端点,但是为此,我需要断开视频流启用伺服请求。这在视频中产生了重要的滞后。

  2. 在视频流连接之间发送数据并在视频中获取最小滞后。

我能够在Arduino IDE中使用第二个选项WebServer,我们有一个选项

// only showing the relevent code ...
// create server.
WebServer server(80);
// then register different endpoint handlers ...
// ...
// ...

void video_stream_handler(){
  // initilize camera stuff, nothing to worry here
  camera_fb_t * fb = NULL;
  esp_err_t res = ESP_OK;
  size_t _jpg_buf_len = 0;
  uint8_t * _jpg_buf = NULL;
  char buf[32];
  sensor_t* sensor_settings = esp_camera_sensor_get();
  sensor_settings->set_framesize(sensor_settings, FRAMESIZE_VGA);
  sensor_settings->set_quality(sensor_settings, 20);
  
  // get client handle
  WiFiClient client = server.client();

  // now we can write headers as well as data to client. this works in ESP-IDF as well :)
  client.write(<some-headers>, <header-length>); 

  // now this is interesting.
  // we can read from client as well
  client.read(); // gives bytes read from client 

是,ESP-IDF是否可以做类似的事情? 还是还有其他更好的选择?我希望在视频流中最小的滞后,同时仍在进行伺服动作之间。

Hardware: ESP32-CAM(single core) with 4MB PSRAM

ESP-IDF HTTP_SERVER参考

PS我正在使用Python套接字来读取/处理视频流并在正在进行的连接中发送二进制数据。

I'm using ESP32-CAM for video streaming using ESP-IDF framework. I was able to create server on ESP32-CAM and stream video sucessfully. For streaming I'm using HTTP protocol with Content-Type: multipart/x-mixed-replace; boundary=" PART_BOUNDARY "\r\n headers and it's working great :)

Now, I want to add a servo motor to the camera to adjust pan remotely. I think of 2 ways to do it.

  1. Create another endpoint for servo, but for that I need to disconnect video streaming untill servo request is completed. This gives significant lag in video.

  2. send data in between video streaming connection and get minimum lag in video.

I was able to use 2nd option in Arduino IDE for WebServer, there we have an option of reading binary data from client in an ongoing request. Example below

// only showing the relevent code ...
// create server.
WebServer server(80);
// then register different endpoint handlers ...
// ...
// ...

void video_stream_handler(){
  // initilize camera stuff, nothing to worry here
  camera_fb_t * fb = NULL;
  esp_err_t res = ESP_OK;
  size_t _jpg_buf_len = 0;
  uint8_t * _jpg_buf = NULL;
  char buf[32];
  sensor_t* sensor_settings = esp_camera_sensor_get();
  sensor_settings->set_framesize(sensor_settings, FRAMESIZE_VGA);
  sensor_settings->set_quality(sensor_settings, 20);
  
  // get client handle
  WiFiClient client = server.client();

  // now we can write headers as well as data to client. this works in ESP-IDF as well :)
  client.write(<some-headers>, <header-length>); 

  // now this is interesting.
  // we can read from client as well
  client.read(); // gives bytes read from client 

My question is, is it possible with esp-idf to do something like this?
Or if there is any other better alternative than all of it? I want minimum lag in video streaming while still performing servo action in between.

Hardware: ESP32-CAM(single core) with 4MB PSRAM

ESP-IDF http_server reference

P.S. I'm using Python socket to read/process the video stream and to send binary data in ongoing connection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文