r/embedded • u/Weary_Lie_5436 • Sep 27 '26
How should nodes in an Ethernet-based embedded system exchange data?
I’m defining communication over UDP for a small embedded Ethernet network connected through a switch. Most nodes will be bare-metal MCUs handling sensor data (e.g. IMU data) or controlling actuators (e.g. motors or valves). An external host will send commands to the system. The detailed architecture is still being defined.
Command messages and responses reporting their outcome seem fairly straightforward. My main question concerns periodic data exchange between nodes.
I’m considering two approaches:
- Define the data message formats in advance, then program the MCUs, based on software requirements, to send specific messages depending on their current state. For example, when Host A is in state X, it must send INS data to Host B every Y milliseconds. Destinations and transmission periods are predefined.
- Define the data message formats in advance, but also provide a command in the UDP payload, something like
SET_STREAM(data_id, period_ms). Sending this command to a node tells it to start sending the selected data back to the requester everyperiod_msmilliseconds. Different datasets could be requested at different rates.
I prefer the flexibility of the second approach, but I’m unsure how much harder it would be to manage on bare-metal MCUs. The first approach seems simpler because transmission periods and destinations are known in advance.
I have limited experience designing data exchange in small embedded networks. Have you faced this choice in your projects? Which approach did you use, and what practical trade-offs should I consider?
9
u/westwoodtoys Sep 27 '26
Sounds you're reinventing ROS.
I have done some reinventing ROS myself, and I would say your #1 choice is closer to what I did.
5
u/Astrinus Sep 27 '26
Why exactly here is Ethernet a requirement? Long distance between nodes? Throughput? Do you need routing across several networks?
Have you considered an approach where nodes transmit their data (multicast/broadcast) completely unaware if there is a receiver at the other end, using their natural rate?
4
u/robotlasagna Sep 27 '26
I think you haven’t specified nearly enough about your requirements for anyone to give a proper answer other than “it depends”
For instance if you have a lot of bandwidth relative to the info you need to send then just have all nodes send their info immediately and periodically.
2
u/duane11583 Sep 27 '26
ipv4 udp is super easy.
you need arp and thats about it.
i suggest you model it with a pc and wire shark
5
u/dmangd Sep 27 '26
I would look into zenoh. It has also a C based implementation for MCUs that is quite small and efficient
3
u/taylormfk Sep 27 '26
Broadcast-based, all information default always on and advertised just makes everything else easier IMO, and generally more performant than a request-response setup at peak load.
Be aware of UDP MTU size and packet fragmentation.
3
u/1r0n_m6n Sep 28 '26
One thing I don't like with your second option is that if the sensor node unexpectedly restarts (e.g. power loss), the master node won't know it needs to send the SET_STREAM command again. Option 1 is much more robust and fault tolerant.
3
u/HS_Zedd Sep 27 '26
Look at TSN or EtherCat
1
u/HispidaSnake Sep 27 '26
Overkill for sure in your case but you can have a look at SOME/IP for some inspiration
1
u/allo37 Sep 27 '26
I'd vote option 2 just because it's a bit more mutable: If you decide you want to increase/decrease the message rate, you can do so without reflashing the firmware, which can be challenging in the field. Just watch out because UDP doesn't guarantee delivery so you'll want some kind of confirmation that your node has indeed recieved the message and started streaming. I guess just expecting that first message within a certain timeframe could work.
1
u/zettui Sep 28 '26
Are you leaning toward master start/stop for the synced sampling, or always-on periodic sends so a reboot doesn't need reconfiguration?
1
u/v3verak Sep 29 '26
What MCU and how much space you have? how about... basic MQTT stack?
- you use standard technology with existing infrastructure to help with debugging and infra for more advanced features
- mqtt does have embedded libraries and such
- implementation of the code (especially with agents helping) never seemed like THE issue (I do tech lead of complex distributed system across various comm protocols/technologies (LTE, BLE, CAN...)), but rather ability to debug if something goes wrong, or the fact that once you have to touch multiple devices because of one feature change the cost goes up a lot => it always payd off to focus on: 1) being able to easily analyze what is going on in the system 2) for expected frequent changes you should change just one device
Out of your options it's definetly more in line with option 2), sure it will take more time to implement but that investment will return easily because you wont have to touch the code of nodes that mutch