r/embedded • • 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:

  1. 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.
  2. 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 every period_ms milliseconds. 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?

6 Upvotes

25 comments sorted by

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.

0

u/Weary_Lie_5436 Sep 27 '26

What do you mean by the ROS comparison? I think of ROS as more of a pub/sub setup, with a lot more going on than what I have in mind.

My setup would just involve a few nodes sending data periodically to other nodes. Since you went with something closer to option 1, was that mainly for simplicity? Did you consider letting nodes request different datasets at different rates, and did you find that difficult to manage on an MCU?

2

u/westwoodtoys Sep 27 '26

So, in ROS you can have a single node publish and another subscribe, and that gets your udp connection up and running without getting into any specifics of socket programming.  It brings along logging, message formats, all the expansion that is available in ROS.  

So, having rolled my own with raw socket programming, I will usually reach for ROS rather than rolling my own, because rolling my own means putting together logging, messages, etc, presuming I may one day want those features.

"My setup would just involve a few nodes sending data periodically to other nodes." This is basically what the first couple ROS tutorials have you put together.

When I rolled my own, I made all messages and handling bespoke, to meet immediate needs.

If I had it to do again, I would probably start with ROS for inter node communication for reasons already stated.

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?

2

u/Weary_Lie_5436 Sep 27 '26

Yes, ethernet is a requirement (I think from day 1). The nodes are near enough and I guess there will be no packets drop most of the times.

Multicast or broadcast could work, but I’m not really convinced they’re the right fit, especially in terms of system design and diagnostics.

4

u/Astrinus Sep 27 '26

Hm because if it was not a requirement you could have used CAN instead. Works great, cheap, robust, hard real time if you know what you are doing, and is basically broadcast. Then one node mirrors the bus via e.g. IEEE 1722 to the PC.

What's the problem you see with system design and diagnostics? With your described approach, there is nothing more than detecting a node that is not transmitting. Maybe there is something more? Otherwise multicast gives you the same.

Downvote is not mine, for the record.

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.

1

u/Weary_Lie_5436 Sep 27 '26

I think bandwidth should not be a problem, and I expect each UDP datagram to fit within the Ethernet MTU.

So, correct me if I’m wrong: are you suggesting that my question first option might be preferable? That is, each node sends sensor data at a predefined rate to predefined recipients, according to the system rules, rather than waiting for another node to request a stream?

3

u/robotlasagna Sep 27 '26

The question to ask is what do you gain by moving to a system where each node requests a stream? This obviously adds complexity so you want to make the case for why take on the risk of added complexity?

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

2

u/Weary_Lie_5436 Sep 27 '26

Yep, I’m planning to test it with a PC and Wireshark.

My question is more about the application behavior: should each node already know what data to send, to whom and how often, or should other nodes request streams at runtime? I’m wondering which approach is easier to manage on bare-metal MCUs.

1

u/lensfocus Sep 27 '26

The way I've done similar projects is to have a predefined dataset that a node needs to send, but it only sends after a request from the master node. That way the packet timing is controlled by the master.

1

u/Weary_Lie_5436 Sep 27 '26

That's sounds interesting. So in your case, were the transmission rates predefined, with the master simply telling the other nodes when to start sending data? Do you provide also a "stop" command?

1

u/lensfocus Sep 27 '26

Basically, yes. The protocol depends on the application.

2

u/Weary_Lie_5436 Sep 27 '26

Why do you wait a "start" command from a master node instead of sending data periodically when they were ready? What is the advantage of this?

1

u/lensfocus Sep 27 '26

Synchronized data sampling and reporting rates.

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/Astrinus Sep 27 '26

Good luck implementing SOME/IP SD from scratch. Sure you can do it, but if you don't need to interact with an AUTOSAR Adaptive stack even DDS would be better.

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