High frequency messages with ESP_NOW
Posted: Wed Aug 28, 2024 2:48 pm
Hello, I am working on a project that requires multiple devices to transmit IMU data at 20Htz. I need multiple transmitters sending their IMU data that will need to end up on a PC.
I am using multiple (4-8) ESP32-S3 as the data transmitters and another ESP32-S3 as a receiver. The transmitters are sending the data using ESP_NOW and the receiver is connected to a web-socket server and passes on the received data to the PC. This setup works ok with up to 4 transmitters but once I introduce a 5th transmitter my receiver stops responding after a minute or so.
Here is the relevant code of the receiver device:
I would appreciate it if someone can tell me if I can optimize any of the above code in order to avoid my receiver device crashing.
Furthermore, could I achieve the functionality of sending data from multiple ESP32 (at 20Htz) that will end up on a PC using a different, more efficient approach? I have tried using Serial print from the receiver and reading the serial data on the PC but that is much slower than the web-socket solution.
Thank you in advance.
I am using multiple (4-8) ESP32-S3 as the data transmitters and another ESP32-S3 as a receiver. The transmitters are sending the data using ESP_NOW and the receiver is connected to a web-socket server and passes on the received data to the PC. This setup works ok with up to 4 transmitters but once I introduce a 5th transmitter my receiver stops responding after a minute or so.
Here is the relevant code of the receiver device:
Code: Select all
struct IMUReading {
int deviceID;
float accelX;
float accelY;
float accelZ;
float gyroX;
float gyroY;
float gyroZ;
float magX;
float magY;
float magZ;
};
bool isWebSocketConnected = false;
const int IMU_READINGS_PER_BATCH = 5;
IMUReading imuReadings[IMU_READINGS_PER_BATCH];
void onReceiveData(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
if (isWebSocketConnected) {
memcpy(imuReadings, incomingData, sizeof(imuReadings));
String output = "Msg from: d" + String(imuReadings[0].deviceID) + " ";
for (int i = 0; i < IMU_READINGS_PER_BATCH; i++) {
output += "Accel: (" + String(imuReadings[i].accelX) + ", " + String(imuReadings[i].accelY) + ", " + String(imuReadings[i].accelZ) + "), ";
output += "Gyro: (" + String(imuReadings[i].gyroX) + ", " + String(imuReadings[i].gyroY) + ", " + String(imuReadings[i].gyroZ) + "), ";
output += "Mag: (" + String(imuReadings[i].magX) + ", " + String(imuReadings[i].magY) + ", " + String(imuReadings[i].magZ) + ") - ";
}
webSocket.sendTXT(output);
}
Furthermore, could I achieve the functionality of sending data from multiple ESP32 (at 20Htz) that will end up on a PC using a different, more efficient approach? I have tried using Serial print from the receiver and reading the serial data on the PC but that is much slower than the web-socket solution.
Thank you in advance.