-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Hardware:
Board: ESP32 WROOM32
Core Installation/update date: Apr 13 or so
IDE name: Arduino IDE 1.8.5
Flash Frequency: 80Mhz
Upload Speed: 921600
Description:
I wrote a big sketch where I was reading CAN frames from two buses and trying to send them over wifi to connected machines. I've tried this multiple ways. I got it working pretty well by using TCP/IP over port 23 (telnet) and causing the ESP32 to be a softAP. The antenna on the WROOM32 is total trash and couldn't get a signal if you fired a megawatt MASER straight at it. But, with softAP mode and the thing right next to my machine I get a signal strength of about 65% which should be good enough. Anyway, switching to UDP is a total disaster. It drops frames like crazy. So, I made a simple test sketch (below) to do the same basic thing as the complicated sketch did when it comes to UDP but this sketch isn't doing anything else so it ought to rule out my doing anything stupid in the complicated sketch. Well, it still drops frames like crazy. The test sketch tries to send 400 bytes of payload every 1/2 second. Nothing too taxing. Sometimes I'll see 3-4 frames in a row come through. Then nothing for several seconds, then 3-4 come through then nothing then 1 or 2 then nothing for several seconds, and on and on. This is true even of the simple sketch. The WROOM32 is right next to my machine and signal strength isn't bad. There's no excuse for dropping so many packets. I tried doing begin(17222) just once and not doing stop() and that seems to make it even worse. Sometimes 8 or more seconds go by and no UDP message. This is stupid even for UDP messages. The drop rate has got to be trending toward at least 50% for me. Is this sort of result normal for the ESP32 or the WROOM32?
Sure, I can go back to TCP/IP but that's a rather bloated protocol and now I'm thinking it might be hiding this issue. I do sometimes get weird pauses in the TCP/IP stream which could be due to it losing the ability to transmit for a little bit.
Sketch:
#include <WiFi.h>
#include <WiFiMulti.h>
byte i = 0;
byte serialBuffer[2048];
int serialBufferLength = 0; //not creating a ring buffer. The buffer should be large enough to never overflow
uint32_t lastFlushMicros = 0;
WiFiServer wifiServer(23); //Register as a telnet server
WiFiUDP wifiUDPServer;
IPAddress broadcastAddr(192,168,4,255);
void setup()
{
delay(5000); //just for testing. Don't use in production
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.softAP("ESP32DUE", "1234PASSWORD");
Serial.print("Wifi setup as SSID ");
Serial.println("ESP32DUE");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
Serial.print("Done with init\n");
}
void loop()
{
serialBufferLength = 400;
//If the max time has passed or the buffer is almost filled then send a frame out
if ((micros() - lastFlushMicros > 500000) ) {
//Serial.write('*');
wifiUDPServer.begin(17222);
wifiUDPServer.beginPacket(broadcastAddr, 17222);
wifiUDPServer.write(serialBuffer, serialBufferLength);
wifiUDPServer.endPacket();
wifiUDPServer.stop();
lastFlushMicros = micros();
}
}
### Debug Messages:
Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here
Nothing really notable here.
�⸮��⸮⸮⸮�ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13256
entry 0x40078a90
Wifi setup as SSID ESP32DUE
IP address: 192.168.4.1
Done with init
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 13 - AP_START
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 15 - AP_STACONNECTED