Dear Forum,
I am trying to understand what is the most effective way to stream data from an ESP32 node via WiFi to my PC.
Let me shortly describe the application that I am working on.
I would like to setup a wireless IMU node based on ESP32 and the MPU6050 [https://www.invensense.com/products/mot ... /mpu-6050/] that I have in this convenient board GY-521.
All about the interface and acquiring the data from the MPU6050 is already working.
I am now working on how to transmit the data to my pc.
I thought that an UDP streaming might be a good solution. I would have to transmit 6 Bytes with 100Hz frequency.
Unfortunately the UDP connection does not seem to be extremely reliable and I get come transmission error over serial from time to time.
Do you have any suggestion regarding the best way to stream data that are sampled at 100Hz via WiFi?
Thank you very much in advance!
Real-time data streaming over WiFi
Re: Real-time data streaming over WiFi
Hello,
You should look at the protocol: ESP-NOW https://www.espressif.com/en/products/s ... w/overview
It should cover what you need, for a simple example see https://techtutorialsx.com/2019/10/20/e ... h-esp-now/
Cheers, Ben
You should look at the protocol: ESP-NOW https://www.espressif.com/en/products/s ... w/overview
It should cover what you need, for a simple example see https://techtutorialsx.com/2019/10/20/e ... h-esp-now/
Cheers, Ben
Re: Real-time data streaming over WiFi
Was TCP too slow for your sample rate
Tom Meyers
Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
Re: Real-time data streaming over WiFi
Thank you for the replies
I did not know about the ESP-NOW protocol.
It is very interesting indeed. However, I would need something simple to be integrated with a python script running on a PC that is receiving the data.
That is why I was thinking about UDP.
I also think that TCP might work. However, I have not tried it yet.
I am now scouting which might be the easiest solution to support the mentioned data rate (600 B/s).
Using an higher level protocol (e.g. MQTT) would be helpful in the phase of data collection.
I wonder if MQTT might support a stream of data as I am doing.
Thanks again!
I did not know about the ESP-NOW protocol.
It is very interesting indeed. However, I would need something simple to be integrated with a python script running on a PC that is receiving the data.
That is why I was thinking about UDP.
I also think that TCP might work. However, I have not tried it yet.
I am now scouting which might be the easiest solution to support the mentioned data rate (600 B/s).
Using an higher level protocol (e.g. MQTT) would be helpful in the phase of data collection.
I wonder if MQTT might support a stream of data as I am doing.
Thanks again!
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: Real-time data streaming over WiFi
Do you need low latency? If not, just collect a heap of samples (100 or so) and send them as one packet; if you do it like this, you can happily use whatever protocol you fancy. If not, most protocols probably still are feasible, but you'd need to try. I'd personally just go for an UDP stream if you need low latency, TCP if you need to get all the samples at all cost.
Re: Real-time data streaming over WiFi
Hi, i'm working something similar, but the data is audio signal, which means i need minimum 12 bites resolution by ADC(1), and a sampling rate 441000 Hz, the idea is to listen almost in real time you understand, now i'm using UDP but i got a lot of delay, i don't know if i'm not implementing right or this protocol isn't aproppiedied.
I'm gonna try it with Esp-Now, but what do you recommend for this application, for example i've seen the ESP-CAM send the video low resolution but faster and i don't know what protocol use, i saw the library but i don't understand it.
I'm gonna try it with Esp-Now, but what do you recommend for this application, for example i've seen the ESP-CAM send the video low resolution but faster and i don't know what protocol use, i saw the library but i don't understand it.
Code: Select all
#include <WiFi.h>
#include <WiFiUdp.h>
#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
const char* ssid = ".......";
const char* password = ".......";
uint16_t analog=0;
uint8_t data1[1460]; //data buffer
uint8_t data2[1460]; //data buffer copy
bool ready1=false;
WiFiUDP Udp;
TaskHandle_t Task1, Task2;
//SemaphoreHandle_t baton; //version with semaphore
void setup() {
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
//Serial.print(".");
delay(500);
}
//baton = xSemaphoreCreateMutex(); //version with semaphore
xTaskCreatePinnedToCore(codeForTask1, "Task1", 10000, NULL, 1, &Task1, 1);
delay(500);
xTaskCreatePinnedToCore(codeForTask2, "Task2", 10000, NULL, 1, &Task2, 0);
delay(500);
}
void loop() {
vTaskDelete(NULL);
}
void codeForTask1( void * parameter )
{
for (;;) {
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE; //to avoid use vTasKdelay(1)
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;
int x=0;
for(int i=0; i<730;i++){ //buffer 1460, but real 730 (the analogic data 16 bits)
int old=micros();
analog = analogRead(34); //the audio signal
//analog2=analog;
data1[x]=(uint8_t(analog)); //take 8 bits
data1[x+1]=(uint8_t(analog>>8)); //take the last 8 bits
x=x+2;
while(micros()-old<20); //22uSec = 1Sec/44100Hz - 2uSec almost the sampling rate
}
while(ready1==true); //wait to make a copy data buffer
}
}
void codeForTask2( void * parameter )
{
for (;;) {
ready1==true;
for(int i=0; i<1460;i++){ //copy of buffer
data2[i]=data1[i];
}
ready1==false;
Udp.beginPacket("192.168.0.106", 4321);
for(int i=0; i<1460;i++){ //data to send
Udp.write(data2[i]);
}
Udp.endPacket();
}
}
Who is online
Users browsing this forum: No registered users and 169 guests