Setup:
OV7670 -> STM32F103... --USART--> ESP01 --UDP--> Gateway --> Internet --> Server
I want to achieve a real-time streaming experience.
Here is my analysis:
According to the OV7670 datasheet, the camera supports 30 FPS for a ×ばつ480 image.
Based on the ESP8266 (ESP01) datasheet and using the built-in firmware with AT commands, I can enable transparent mode for UART-WIFI passthrough with UDP. This means any incoming data from the MCU through UART will be directly forwarded to the server through UDP.
The datasheet also states that the AT commands can adjust the baud rate up to a maximum of ×ばつ40 baud.
(削除) If one baud is represented by 9 bits (including 1 stop bit), then the theoretical bit rate is 41.472 Mb/s. (削除ここまで)For safety, use ×ばつ39 baud rate which the theoretical bit rate is 4.4928 Mb/s.Since I’m using UDP as the transport protocol, I need to limit the UDP buffer size. Inspired by YouTube video streams that also use UDP, I found 1357 bytes to be an effective packet size when I Analyzed this with Wireshark.
If I configure the OV7670 in RGB555 (15-bit) format, then 1 pixel = 16 bits = 2 bytes, leaving 1 unused bit as the most significant bit (MSB) of the first byte.
To maximize the unused 1 bit, I plan to use it as a flag to indicate the beginning of a frame. If set to zero, the pixel is not the start of a new frame; if set to one, it indicates the start of a new frame.
Using this bytestream, the MCU's task as a frame buffer (I prefer say byte buffer) is to simply forward per 1357 bytes from the camera (including setting the frame indicator flag) to USART through DMA for faster since it's direct memory access. The MCU waits for the buffer to fill (up to 1357 bytes) before sending it to the ESP8266.
The server will reconstruct this bytestream into image frames, given that it understands the custom protocol.
Each frame would require
(削除) ×ばつ2 (削除ここまで)×ばつ2 bytes for(削除) QVGA (削除ここまで)QCIF, or(削除) 1.2288 (削除ここまで)0.3072 Mbit per frame. Therefore,(削除) 30 FPS = 36.864 Mb/s (削除ここまで)15 FPS = 4.608 Mb/s, which comfortably fits within the ESP8266's USART-WIFI UDP passthrough capability of 4.4928 Mb/s.
Is there anything I missed with my setup/calculation? Assume the network is reliable and UDP packet loss is tolerable (handled by server).
-
If you are looking for performance, why don't replace STM32 host -> ESP8266 modem approach with an ESP32-S3? ESP8266 is a single-core, and UART is very slow...hcheung– hcheung10/30/2024 02:32:40Commented Oct 30, 2024 at 2:32
-
@hcheung cost effectiveness, I saw market use esp8266+stm32f103+ov7670 is cheaper than esp32-cam directly.Muhammad Ikhwan Perwira– Muhammad Ikhwan Perwira10/30/2024 02:34:11Commented Oct 30, 2024 at 2:34
-
@hcheung Can you give me the reason why did you say UART is very slow?Muhammad Ikhwan Perwira– Muhammad Ikhwan Perwira10/30/2024 02:35:36Commented Oct 30, 2024 at 2:35
-
2@MuhammadIkhwanPerwira 115200bps is bits per second, that is 115200 / 10 bits (8 bits + 1 start bit + 1 stop bit) = 11520 bytes per second, whatever streaming rate you are going to have, the serial port is going to be the bottleneck.hcheung– hcheung10/30/2024 07:52:40Commented Oct 30, 2024 at 7:52
-
1Why don't you give it a try? Otherwise this is just a self-fulfilling prophecy.hcheung– hcheung10/30/2024 08:43:50Commented Oct 30, 2024 at 8:43
1 Answer 1
Quote from esp32 docs
Because UART is used for communication between ESP-AT and the host MCU by default, and the baud rate is 115200. On the hardware, the baud rate upper limit is 5 Mbps. Therefore, if the throughput is expected to be less than 5 Mbps, the user can use the default UART as the communication medium with the host MCU, and the following optimization methods can be carried out.
In another word, since the incoming stream is 4Mbps, then just use 115200 baud rate.
But, it was about esp32, perhaps it's similar to esp8266.
Also, consider about transmission interval AT+TRANSINTVL that talking about interval between UDP packet size. I need to set it to 0, which means once the data arrive from host (MCU), just forward to internet.
Also disable AT+SYSMSGFILTER=0 https://docs.espressif.com/projects/esp-at/en/latest/esp32/AT_Command_Set/Basic_AT_Commands.html#cmd-sysmsgfilter
Hi, The throughput we tested with AT UART-WiFi passthrough mode is as below: TCP Throughput: AT TCP passthrough Tx 303 Kbps; Rx 302Kbps @ baudrate 420000 UDP Throughput: AT UDP passthrough Tx 250 Kbps; Rx 250 Kbps @ baudrate 420000
-
1How does a 4 Mbps stream translate to a baud rate of 115200? That is not in the text you quoted.StarCat– StarCat10/31/2024 07:21:28Commented Oct 31, 2024 at 7:21
Explore related questions
See similar questions with these tags.