receive data from sensor on udp at the same time
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have to receive data from multiple sensors at the same time. I have data received on udp ffrom two different sensors. the process have to be time stamped at the same values of time.
Will this require multithreading in matlab. or it can be also done by vectoring the variable.
Please tell how it can done in both ways.
I have considered using parfor and parpool but cannot arrive at the result.
0 comentarios
Respuestas (1)
Electrification Enthusiasts
el 11 de Oct. de 2021
Hello Rashi,
you should focus on processing the data serially (not in parallel) because UDP doesn't support parallel packets. They may have the same time stamps, but they will not be received simultaneously. One will always come in before the other. Also, technically, UDP can drop packets so there is not guarentee you will get data from each sensor for each time step. As for processing data that was generated at the same time, you can use vectors in maltab. Adding threads won't change that the bottlneck is your network adapter which will process everything serially.
You can look for serial to parallel (and vice versa) converters in the file exchange to starting points.
Regards,
Joel
3 comentarios
Mariana Alegria Palacios
el 13 de Mayo de 2024
Hi, did you resolve the issue? I'm triying to use two ESP-32 to receiving data, but it must be at the same time and I can't find how to use parfor or parpool for this
Walter Roberson
el 13 de Mayo de 2024
To have a chance that two udp packets could be received with the same timestamp. it would be necessary that the two were being received over different interfaces -- different wireless connectors or different ethernet connectors. For any one interface, inherently packets are queued and so two packets going to the same interface cannot be received with the same timestamp.
In order for two distinct interfaces to receive packets at the same time, it would be necessary to synchronize the interfaces. The only potential way to synchronize interfaces is to use smpd and use spmdBarrier or the older labBarrier and once through the barrier, ask for the udp packet.
The default udp reading interface, read is buffered, and the timestamp might potentially be the time the packet was actually received. So you will need to use an unbuffered UDP reading, namely the DSP udp receiver https://www.mathworks.com/help/dsp/ref/dsp.udpreceiver-system-object.html
But for unbuffered UDP reading, in order for the two packets to get the exact same timestamp, it would be necessary for the two senders to be such that the "distance" from each UDP sender and the time that the packets were sent was carefully matched -- so if one sender was 17 milliseconds away and the other sender was 18 milliseconds away, that the second sender would have to transmit 1 millisecond earlier than the first sender.
Is it all impossible? I wouldn't say that it is impossible -- I would just say that it is fairly unlikely to work out, and it is not likely at all that the streams would stay in synchronization -- not without going through a bunch of trouble.
All in all, I would say that you should probably give up on getting two UDP packets with the same timestamp . You would be much much better off looking for two UDP packets within a synchronization window .
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!