arduino / uno-r4-wifi-usb-bridge

26 stars 8 forks source link

Increase bandwidth of Wifi communication #55

Open matthieuvigne opened 2 months ago

matthieuvigne commented 2 months ago

For the context, I want to stream sensor data from the Arduino, using it as a WiFi access point. I was surprised by the low throughput of the connection: sending a 20-bytes packet in a single WiFIClient.write command takes around 6ms...

Digging into the code, I think I found two bottlenecks - unrelated and that can be addressed separately:

The communication speed between ESP32 and the RA4M1

This serial link is hard-coded on both sides at 115200 baud. I couldn't see any reason why this can't be higher - in fact I did a working proof of concept at 1000000 baud, and could see no unwanted side effects in my application. Thus I'm thinking we could either:

I can write either version of the code (both for the ESP32 and the RA4M) depending on what seems best

The task scheduling of the ESP32

The parsing of AT command is done in an FreeRTOS task using vTaskDelay(1);, thus forcing a 1ms delay between the parsing of successive commands. This introduces a fixed 2 to 3ms overhead when using WiFIClient.write (because you have to send two commands and wait for their reply).

Searching online, I found the following project which seems to address this issue: https://github.com/mickeyl/esp-microsleep My idea was to reduce this sleep from 1ms to 100us. This is my first time working with the ESP32, so I didn't manage to integrate it in the compile chain (I feel like this belongs more to the arduino-esp32 project than to this one). I can dig further to get that working, but I wanted to get an opinion first on whether this is the right way to go. Maybe this will mess up other things in the task scheduling or introduce unwanted side effects (like latency on the WiFi side because we have less time to process these events if we dedicate more time to the serial port parsing).

andreagilardoni commented 1 month ago

The reason why that delay is present is to allow the watchdog task to run, thus avoiding the esp32 being stuck. I think the best solution for you is to compile a custom firmware for uno-r4-wifi-usb-bridge with the highest possible baudrate that can be achieved without having any issues in the uart signal

matthieuvigne commented 1 month ago

Thanks for the explanation. Indeed I've realized that just increasing the baudrate to 921600 is enough for my need for now, so I didn't focus on this second point about task scheduling anymore.