Agent-free ROS 2 on an ESP32

A Raft board with a multizone depth sensor in front of a laptop showing the live point cloud in Foxglove

Updated 13 October 2026: Brought up to date with the current code – node names, the example's read service and the router address command – and two more things that bit me added to Appendix C. Running it over a USB cable now has its own post.

A Raft board with a multizone depth sensor in front of a laptop, where Foxglove shows the sensor's live point cloud and depth image as a hand moves over it
A depth sensor plugged into a Raft board, streaming straight into Foxglove as ROS 2 topics – with no agent in between.

TL;DR: RaftROS turns an ESP32 running the Raft framework into a genuine ROS 2 node – no micro-ROS, no agent process – talking Zenoh to the standard ROS 2 Zenoh router. Every I2C sensor that Raft auto-detects appears as a typed ROS 2 topic, the node serves ROS 2 services and parameters, and it all runs in well under a millisecond of the main loop on average. It is clean-room MIT-licensed code (RaftROS on GitHub), and it has survived two 12-hour soak tests with the heap flat and zero failures in 3,600 service calls. To check that the clean-room route was worth it, I later built the same node on Eclipse's zenoh-pico library and measured the two head to head: zenoh-pico works, but it doesn't play so nicely with the cooperative multitasking approach that Raft's loop() uses and it costs about 49 kB more flash and 40 kB more RAM, so the clean-room version stays the default (Appendix B has the details). And if WiFi isn't an option, the same node also works over a plain USB cable to the standard router, again with no agent – that has its own post.

Is there anything you'd want from a ROS 2 microcontroller node that this doesn't do? I'd genuinely like to know.

Why is this necessary?

After a fair few ESP32 projects I built a framework – as one does – called Raft, and like most frameworks, Raft has its own way of doing things. It provides interchangeable WiFi, BLE and serial communication paths, it has a REST API, and it has its own publish-subscribe mechanism for getting sensor data off the device (I wrote about building an app with it in Program a Connected Device Using Raft). Another party trick is I2C auto-identification: plug a sensor into the bus and Raft works out what it is, initialises it and starts polling it, without any code being written for that particular device.

That's all very well until you want to talk to someone else's robot. The robotics world has largely standardised on ROS 2 – its tools, its visualisers, its enormous library of nodes – and the pull of plugging straight into that ecosystem has become more and more compelling over time. Raft already knows exactly which sensors are attached and how to decode them. It seemed only reasonable to add to Raft's capabilities by talking ROS 2 natively.

The standard way to put a microcontroller on ROS 2 (especially when using RTSP as middleware) is micro-ROS. It works, but it relies on an agent: a separate process on a host computer that talks a cut-down protocol to the microcontroller and represents it on the ROS network. The microcontroller isn't really a participant in its own right – the agent is the "node" and it owns the entities that are published, and of course the agent needs to be running. I wanted the ESP32 to be the node.

So, the requirements:

  • Appear in ros2 node list and ros2 node info like any other node
  • Publish every device Raft finds as a standard ROS 2 message type (sensor_msgs/Range, Illuminance, Imu and friends), in SI units
  • Hot-plug: unplug a sensor and its topic goes away; plug it back in and it returns – Raft handles any communications issues and fixes them
  • Subscribe to topics, serve ROS 2 services and expose ROS 2 parameters
  • Stay inside Raft's main-loop contract: 10 ms average, 50 ms worst case per pass
  • Only Raft code on the device – no micro-ROS, no ROS client libraries, no third-party protocol stacks and all MIT licensed clean-room implementation

That last one is the kind of self-imposed constraint that makes a project take about three times longer than it should. More on that shortly.

A two-minute ROS 2 primer

For those who haven't used ROS 2: a ROS 2 system is made up of nodes (processes, roughly) which exchange data over named topics using publish-subscribe, make request-response calls to services, and expose settings as parameters. Tools like ros2 topic echo and Foxglove let you see all of this live.

Underneath, ROS 2 has a pluggable middleware layer (the "RMW"). For years that meant DDS – FastDDS or CycloneDDS – which discovers everything by multicasting on the local network. More recently Zenoh has arrived as an alternative, and as of the Kilted release rmw_zenoh is a Tier 1 middleware. I tested with various ROS 2 editions including, Jazzy, Kilted and Lyrical (for Jazzy use apt install ros-jazzy-rmw-zenoh-cpp to add it). The one rule: everyone on the ROS side has to use the same middleware, so a Zenoh device means RMW_IMPLEMENTATION=rmw_zenoh_cpp on the host too.

Using Zenoh and RaftROS to replace microROS

A Zenoh ROS system normally runs a router, rmw_zenohd, and RaftROS makes full use of it. This isn't an agent in disguise, it's the same generic program every rmw_zenoh system runs anyway – one per host – and its main job there is introductions: the ROS nodes on a host find each other through it and then exchange data directly, peer to peer. It never implements anyone's node on their behalf; each ESP32 declares its own node, its own topics and its own services.

RaftROS: three ESP32 Zenoh clients each keep one TCP link to the router; the router provides discovery to the host's ROS nodes and forwards the devices' data to them; host nodes exchange data directly with each other
RaftROS over Zenoh. Each ESP32 is its own ROS node with one link to the router, which fans its data out. The host's nodes use the router to find each other, then talk directly. (With several hosts, each runs a router and the routers connect.)

Where the router does carry data is for clients, and that's what the ESP32 side of RaftROS deliberately is: one TCP connection to one address. Each sample leaves the ESP32 once, however many nodes want it, and the router does the fan-out. Being a full Zenoh peer instead would mean a connection to every ROS process, and as we'll see, on an ESP32 every extra conversation costs loop time.

micro-ROS has its own box in the middle, and it does much more: the agent creates and runs each device's presence on the DDS network. You don't need one agent per board – several WiFi boards can share an agent on one UDP port, though people report throughput suffering with many – but every board behind an agent disappears from ROS if that agent stops. One more practical point the pictures show: the two worlds don't mix. micro-ROS speaks DDS, so its hosts use DDS too; RaftROS over Zenoh needs rmw_zenoh on the host.

micro-ROS: three WiFi ESP32s share one UDP agent, a USB-connected ESP32 has its own serial agent; the agents and the host's ROS nodes all join the DDS network
micro-ROS. The agent is each device's stand-in on the DDS network: one agent per transport channel (several WiFi boards can share a UDP agent; a serial board needs its own), and if an agent stops, every device behind it vanishes from ROS.

So: no agent, but yes, a router. If you want no extra process at all, RaftROS can also speak DDS directly – that was actually my first attempt, and it's described in Appendix A along with the state of micro-ROS on Zenoh.

Digging deeper into Zenoh

Zenoh is a publish/subscribe/query protocol built around hierarchical key expressions – think of a path like 0/raft/range_1_29/... rather than a DDS topic with a pile of discovery metadata attached. From a microcontroller's point of view the important thing is the shape of the conversation: one TCP connection to one router, rather than a multicast free-for-all with everyone on the network.

There is already an excellent small implementation of Zenoh, zenoh-pico, and it even targets ESP-IDF. I didn't use it. Raft has an MIT-licence, Raft-code-only policy, so RaftROS implements just the subset of Zenoh that ROS 2 actually uses, written from the protocol source and from packet captures of the real thing – around 5,000 lines of C++. Is writing your own Zenoh implementation a sensible use of time when a perfectly good one exists? That's the sort of question I've learned not to ask myself – although, as you'll see further down, I did eventually ask it, with a stopwatch in hand (Appendix B).

The method will be familiar to anyone who read my BLE analysis with pyshark post: capture a real rmw_zenoh exchange with tshark, decode it to the byte, keep the capture as a test fixture, and only then write the code to produce the same bytes.

RaftROS architecture: I2C sensors to DeviceManager to AutoPub to the RaftROS SysMod, with a build-time choice of Zenoh or RTPS backend
One SysMod, one application API; the transport is chosen at build time.

The application code is identical for both transports – the example app has no #ifdefs at all – and each firmware image contains only the backend it uses.

Saying hello

When the ESP32 has an IP address it opens a TCP connection to the router and goes through Zenoh's handshake (INIT and OPEN, agreeing a lease – how long the router should wait before assuming we've died). Then it declares things: first itself, then each topic it publishes or subscribes to.

Sequence: TCP connect, INIT and OPEN handshake, liveliness token declarations, then samples and keep-alives
Bringing up a session. Everything happens a step at a time on Raft's main loop – nothing ever blocks.

The declarations are liveliness tokens, and they are how the ROS graph gets built. Each one is a carefully formatted key starting @ros2_lv/ which encodes the domain, the node name, what kind of thing it is (NN for a node, MP for a publisher, MS for a subscription, SS for a service server), the topic, the message type and its QoS. The data itself goes to a key of the form:

<domain>/<topic>/<message type>/<type hash>
0/raft/range_1_29/sensor_msgs::msg::dds_::Range_/RIHS01_b42b6256...

That type hash (RIHS01_...) is a hash of the message definition, and it has to match exactly – which is why the firmware carries the hashes read from the ROS 2 interface packages. Get any of this slightly wrong and nothing complains: your node simply isn't there. Get it right and the standard ROS tools can't tell the ESP32 from any other node:

$ ros2 node info /raftros_adbfb6
  Subscribers:
    /chatter_in: std_msgs/msg/String
  Publishers:
    /chatter: std_msgs/msg/String
    /raft/range_1_29: sensor_msgs/msg/Range

$ ros2 topic info -v /raft/range_1_29
Node name: raftros_adbfb6        Node namespace: /
Topic type hash: RIHS01_b42b62562e93cbfe9d42b82fe5994dfa3d63d7d5c90a317981703f7388adff3a
  Reliability: BEST_EFFORT       Durability: VOLATILE

(Trimmed a little for brevity.) I'll admit to a small thrill the first time that Node name: line came back with my node in it. Every check before that had gone through my own reading of the wire, which could have agreed perfectly with my own misunderstanding. The ROS tools can't be argued with.

When the router isn't there

If the router isn't reachable – wrong address, not started, a different network – the device doesn't just sit there retrying in silence. After three attempts it says what it tried, whether anything answered at that address, where the address came from, and how to change it without a rebuild or even a reboot:

W ROUTER UNREACHABLE: <router-ip>:7447 - 3 attempts over 6s, last: connect refused.
  The host answers but no router is listening there - start one with:
  ros2 run rmw_zenoh_cpp rmw_zenohd  Nothing reaches ROS 2 until this is fixed.
W ROUTER UNREACHABLE: the address is RaftROS.routerHost from SysTypes or posted settings.
W ROUTER UNREACHABLE: to change it, from any host on the network:
  curl 'http://<device-ip>/api/ros/set?routerHost=<router-ip>&persist=1'
  (applied at once; persist=1 keeps it across reboots)

Error messages that tell you what to do next are rarer than they should be. And when the router does come back, the device is reconnected within about half a second – a figure I owe to the zenoh-pico comparison in Appendix B, which showed the original back-off was far too leisurely. (One demo tip learned the hard way: if you start rmw_zenohd from an ssh session, it dies when the ssh session does.)

Plug in a sensor, get a topic

This is the part I actually wanted. Raft's DeviceManager identifies each device on the bus and knows its class – range, light, IMU and so on. RaftROS maps each class to a standard ROS message, converts the readings into SI units (metres, lux, m/s²), picks a QoS profile (a fast sensor stream is best-effort; you'd rather have the latest reading than a late one), serialises it in ROS's CDR format and publishes it. Topic names come from the device and its bus address:

DeviceTopicROS 2 type
VL6180 distance sensor/raft/range_1_29sensor_msgs/msg/Range
VEML7700 light sensor/raft/illuminance_1_10sensor_msgs/msg/Illuminance
AS5600 magnetic angle sensor/raft/angle_1_36std_msgs/msg/Float32
LSM6DS IMU/raft/imu_1_6asensor_msgs/msg/Imu
The VL6180 as Foxglove sees it: /raft/range_1_29, plotted live, nothing written for this sensor.

No code is written for any of these – if Raft can identify it, ROS gets a topic. And because Raft notices devices coming and going, so does ROS:

Sequence: sensor identified, publisher token declared, samples flow, sensor unplugged, token withdrawn
Hot-plug: the topic follows the hardware.
Hot-plug: the topic follows the hardware.

There is something deeply satisfying about unplugging a sensor and watching its topic vanish from a laptop across the room. The repository includes a little terminal dashboard (DemoSimple) that discovers /raft/... topics on its own and shows the latest values – which is also the easiest way to prove the ROS side really is decoding the messages, not just seeing bytes go past.

DemoSimple finding topics as devices are plugged in: two IMUs, two rows, no restart.

Services and parameters

Topics are one-way. For "do this" or "tell me that" ROS 2 has services, and in Zenoh a service is a queryable – something that answers queries on a key – plus an SS liveliness token so the ROS graph knows it's there.

The interesting constraint is Raft's golden rule: nothing blocks the main loop. A service handler runs on the loop, so it either answers immediately or says "I'll get back to you". Here's the example app's read service, which answers with the next reading from every attached device rather than a stale one:

pRaftROS->addService("~/read", "std_srvs::srv::dds_::Trigger_",
    [this](const RaftROS::ServiceRequest& request, RaftROS::ServiceReply& reply)
    {
        noteSampleCounts();                // how many readings each device has sent so far
        _readToken = request.token;        // remember who asked
        _readRequestPending = true;        // loop() finishes it with completeService()
        return RaftROS::ServiceOutcome::Deferred;
    });

(Simplified from the example, which also refuses a second request while one is in progress.) The ~/ makes the name relative to the node, so the code never needs to know what the node is called – and nothing in it knows what the devices are either. Each reading is decoded with the decoder and field list from the device's own type record, the same description Raft's auto-identification found it with, so plugging in a different sensor changes the answer without changing the code:

$ ros2 service call /raftros_adbfb6/read std_srvs/srv/Trigger
success=True, message='APDS9960 1_39: als=3740 red=1055 green=1162 blue=1342 prox=0;
                       MPU6050 1_68: ax=0.6033 ay=0.3812 az=0.5671 temp=28.42 gx=-2.87 gy=0 gz=-0.6718'
Sequence of a deferred ROS 2 service call through the router to the ESP32, answered after the next sensor poll
A deferred service call. The request is parked, the loop carries on, and the reply goes out when the next reading arrives.

If a device has been unplugged, or simply goes quiet, it's listed as having no new reading and the call reports success=False – the caller gets an answer rather than hanging forever.

ROS 2 parameters turn out to be nothing more than six standard services per node, so once services worked, ros2 param list/get/set/describe/dump followed. The node exposes its own settings – chatterPeriodMs changes the rate of the /chatter test topic live, and routerHost is saved to flash – and applications can declare their own, optionally with a callback to refuse silly values:

pRaftROS->declareParameter("gain", 1.5, "Controller gain", false,
    [](const RaftROS::ParamValue& v, const char*& reason) {
        if (v.doubleValue < 0) { reason = "gain must be >= 0"; return false; }
        return true;
    });
$ ros2 param set /raftros_adbfb6 readTimeoutMs 1000
$ ros2 param dump /raftros_adbfb6

Where the milliseconds go

Raft runs its modules (SysMods) from a single main loop, and each one promises to take no more than 10 ms on average and 50 ms at worst per pass – otherwise everything else on the device gets sluggish. So the most important number in this project isn't throughput, it's loop time.

The key measurement: sending one network packet costs about 0.8 ms of main-loop time on an ESP32-S3 over WiFi (up to 1.8 ms), measured across 1,175 sends. That's inherent in lwIP and the WiFi driver, not waiting on a full queue, so non-blocking sockets don't help. The lesson is to budget packets sent per pass, not packets received. The Zenoh backend sends at most one message per loop pass, by construction; RTPS (Appendix A), by its nature, fans out to every peer.

Measured with a ROS subscriber actively consuming the sensor topic:

RTPS (before fix)RTPS (after fix)Zenoh
Worst RaftROS pass82 ms14 ms2.4 ms
Worst whole-loop pass54 ms17 ms3.0 ms
Whole-loop average3.0–5.3 ms2.8–4.3 ms0.60 ms

Zenoh pays for this with about 10 kB more RAM than RTPS, which on an ESP32-S3 with ~147 kB of free heap (with services and parameters) seems a bargain. The firmware image is about 1.28 MB, leaving 28% of the app partition free.

One finding deserves its own paragraph. In the long unattended runs, the worst loop pass was about 13 ms – and it wasn't the protocol at all. It was logging. When nothing is reading the ESP32's USB serial console, each log line stalls for around 10 ms. The most expensive thing my ROS node does is tell me what it's doing. RaftROS now writes at most one log line per loop pass. (Also worth knowing: keep Raft's main task off the core that runs WiFi, or a WiFi reconnect can stall the loop for over a quarter of a second.)

Does it stay up?

Two 12-hour soak tests, sampling the device's status endpoint every minute from the ROS host. The second added a ROS client hammering services and parameters: every minute a device-list call, a deferred range call (the forerunner of today's ~/read), a ping, a parameter get and a parameter set, plus a full parameter dump every ten minutes.

Soak 1: publishingSoak 2: plus services and parameters
Zenoh sessionone, throughoutone, throughout
Samples published238,425256,985
Service and parameter calls–3,600, 0 failures
Free heap trend−2 bytes/hour−174 bytes over 12 hours
Worst loop pass–13.2 ms

A note for fellow embedded developers: the minimum free heap figure is not a leak indicator. It hit its low-water mark within the first 20 minutes and never went lower. The trend of free heap is what matters – and here it's flat. It's the most boring graph I've ever been pleased to see.

Free heap during the 12-hour soak: a flat line at about 147 kB, drifting by 174 bytes over 12 hours
The most boring graph I've ever been pleased to see: free heap across the 12-hour soak.

A note on how this was built

This project was largely written with AI assistance, using Claude (in VSCode). I set the goals and the constraints – clean-room code, MIT licence, the loop budget, verification against the real ROS tools – made the design decisions, and kept a board and sensor on the desk. Claude wrote most of the code, the host tests (several thousand checks across the Zenoh session, the codecs and the firmware pieces) and an extremely detailed development log.

I'd like to claim I hand-decoded every Zenoh frame. I did not. What made it work was insisting on ground truth: packet captures from real ROS processes kept as test fixtures, measurements on real hardware, and the ROS 2 tools as the final judge. Several of the bugs in Appendix C were exactly the kind that tests written from your own output will never catch – which is true whoever, or whatever, writes the tests. AI help also changed what was affordable: the whole zenoh-pico comparison – a third backend, two days of measurements and an overnight soak – is the kind of side quest I'd never have found time for otherwise.

Try it yourself

You'll need an ESP32-S3 board and a Qwiic/STEMMA QT sensor or two (the VL6180, VEML7700, AS5600 and LSM6DS are all supported – as are all of the sensors in the image below), plus a Linux machine with ROS 2.

An overhead view of about twenty Qwiic and STEMMA QT breakout boards spread on a desk beside a Raft board
The menu – anything Raft can identify becomes a ROS 2 topic.

On the ESP32 side, build and flash the example application with the Raft CLI, then set up WiFi from the serial console:

raft run
w/<SSID>/<password>

On the ROS side (you only need the first line on jazzy as zenoh is default on kilted and lyrical)

sudo apt install ros-jazzy-rmw-zenoh-cpp
ros2 run rmw_zenoh_cpp rmw_zenohd              # the router
export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 node list
ros2 topic echo /raft/range_1_29

And point the device at the router – no rebuild or reboot needed, and persist=1 keeps it in flash:

curl 'http://<device-ip>/api/ros/set?routerHost=<router-ip>&persist=1'

To run over a USB cable instead of WiFi, see ROS 2 Down a USB Cable.

If you'd rather use DDS and no router at all, CONFIG_RAFTROS_BACKEND_RTPS=y gets you the RTPS build – just without services and parameters, and with the multicast adventures described in Appendix A.

Conclusions

It works: an ESP32 appears in ROS 2 as a first-class node, its sensors turn into typed topics the moment they're plugged in, it answers services and parameters, and it does all of this in well under a millisecond of the main loop on average. Zenoh versus RTPS comes down to one trade: RTPS needs nothing on the host but talks to everyone; Zenoh needs a router but talks to one – and on an ESP32 that's the difference between 0.6 ms and several milliseconds of every loop. And having measured the obvious alternative, writing my own Zenoh session turns out to have bought 49 kB of flash, 40 kB of RAM and a better worst case – so the clean-room implementation stays the default. And because Zenoh defines its own serial link, the same node also goes down a USB cable to the same stock router without an agent – the case where micro-ROS needs one most (more on that here).

Next on the list are actuators – servos, pumps and LED pixels driven from ROS topics through the same DeviceManager – and then ROS 2 actions and parameter events. Device-side peer mode, which would remove the router, is possible but would give back some of that hard-won loop time.

Is writing your own Zenoh implementation to avoid running an agent a proportionate response to the problem?

Probably not.

Would I do it again?

Probably.

Code

RaftROS is open source under the MIT licence, like the rest of Raft.

Appendix A: RTPS, and micro-ROS on Zenoh

My first attempt: RTPS

RaftROS actually started life speaking DDS directly – a clean-room implementation of RTPS, the wire protocol under DDS. This has the great virtue of needing nothing at all on the host: the ESP32 multicasts its presence, FastDDS or CycloneDDS hear it, and it simply appears. It works, and it is still in the repository as a one-line build option.

It was, however, hard going. DDS discovery relies on UDP multicast, and multicast from an ESP32 into a ROS installation running under linux is the sort of thing that works only after you've added firewall rules and discovered that ROS_LOCALHOST_ONLY changed its meaning between ROS releases. There was a long-running mystery in which the ROS tools listed my node as _NODE_NAME_UNKNOWN_ while happily receiving its data. And, more seriously, DDS expects every participant to chat with every other participant – under load a burst of acknowledgements pushed one RaftROS loop pass to 82 ms, against a contract of 50.

That got fixed (14 ms), but it made me look harder at the alternative – and so Zenoh.

Can micro-ROS use Zenoh?

Not officially, but there are three routes:

  • rmw_zenoh_pico – a community project that keeps micro-ROS's client libraries but swaps the agent-based XRCE-DDS layer for zenoh-pico, so the board talks Zenoh to rmw_zenohd with no agent. Architecturally it's close to RaftROS. Its README is candid that it is "not ready for production use": publish and subscribe work, but services and parameters aren't listed, and without graph information the ROS tools can't list its nodes.
  • A standard micro-ROS agent plus a DDS-to-Zenoh bridge (zenoh-plugin-ros2dds) – but that bridge doesn't interoperate with rmw_zenoh, so it's no help for a normal Zenoh-based ROS system, and you'd be running an agent and a bridge.
  • Skipping micro-ROS altogether – zenoh-pico directly on the board, or a small library on top of it such as Pico-ROS. That's the family RaftROS belongs to.

I found no statement from the micro-ROS maintainers about official Zenoh support (the Open Robotics discussion is community-led), so for now an ESP32 that wants to be a first-class node on a Zenoh ROS system needs something like RaftROS.

Appendix B: The road not taken – zenoh-pico

Having made a point of not using zenoh-pico, it seemed only fair to find out what I'd missed. So, with everything else working, I built a third backend: the same ROS layer – key expressions, liveliness tokens, type hashes, CDR, auto-publishing, services, parameters – with Eclipse's zenoh-pico (version 1.10.1) providing the session underneath instead of my own code.

It's strictly opt-in. zenoh-pico (EPL-2.0 / Apache-2.0) isn't in the repository; a script fetches a pinned version only when you select it, and the default build is unaffected – I built the default firmware with and without the option present and the images were identical apart from the build timestamp.

The first surprise was a pleasant one: it worked first time. My ROS mapping, written and debugged against my own session code, was accepted unchanged by an entirely independent Zenoh implementation – about the best validation of that layer I could have asked for.

The second surprise was structural. On ESP-IDF, zenoh-pico's socket blocks while waiting for data, so it can't be stepped from Raft's main loop the way my code is. It runs as it was designed to: in its own FreeRTOS task (at priority 12 by default, against the loop's 1), with a helper task to open the session because connecting blocks too, and queues to pass messages back to the loop.

Clean-room: all Zenoh work on the main loop. zenoh-pico: its own executor task and a helper task, with queues to the main loop and a shared transmit lock
Where the work happens. The clean-room session lives entirely on Raft's loop; zenoh-pico brings its own tasks – and a lock they share with the loop.

Then the measurements – both builds on the same board, the same load, the same 12-hour soak driver:

Clean-room (default)zenoh-pico
Firmware image1.28 MB+49 kB
Free heap, running~147 kB~107 kB
Heap for the session itself~2.5 kB~54 kB
Main-loop average0.74 ms0.59 ms
Worst sample-publishing pass1.4 ms8.3 ms
12 h soak: calls / failures3,600 / 03,600 / 0
12 h soak: worst loop pass13.2 ms20.8 ms

(These runs streamed the device's log over the network so the serial console wouldn't distort them, which is why the clean-room average is a little above the 0.60 ms quoted earlier.) zenoh-pico's lower average is real but a little flattering: its receiving happens in its own task, so it simply isn't counted against the loop. The worst cases tell the other side – every publish has to take the transmit lock that zenoh-pico's task also uses, and occasionally waits for it. Tuning zenoh-pico's buffers and priorities clawed back about 4 kB and made the worst case worse. Both builds were rock solid over 12 hours: no leaks, one session, no failed calls.

Where zenoh-pico won: after a router restart it was back in about a second, while my code took twelve – its retry back-off doubled during the outage and then sat out the delay. That one I borrowed: the clean-room build now reconnects within about half a second of the router returning.

Where it lost, beyond the memory:

  • Visibility. Asked once a second for 40 seconds which publishers existed, the router left out the zenoh-pico device's publisher 10 times; the clean-room device, never. So fresh ROS tools would intermittently fail to see its topics.
  • Hot-plug leftovers. In early unplug tests, withdrawn sensors sometimes stayed in the ROS graph as ghost publishers.
  • A crash when changing the router address: reopening a session before the old one had fully closed sent zenoh-pico into a null pointer. Easy to avoid once found – but I'd rather find my own bugs than other people's.

Verdict: zenoh-pico is an impressive piece of work, and if I ever need routerless peer-to-peer operation it's where I'd start. For this job the clean-room session is smaller, lighter on RAM and kinder to Raft's worst case, so it stays the default, with zenoh-pico kept in the repository as a measured alternative. The full comparison, warts and all, is in the RaftROS repository's devdocs.

Free heap across 12-hour soaks: the clean-room build flat at about 147 kB, zenoh-pico flat at about 107 kB
Both builds are leak-free; zenoh-pico just starts – and stays – about 40 kB lower.

Appendix C: Things that bit me

In the spirit of the "Errors in the V1 Circuitry" section of my Wordy Watch post, here are some of the better ones:

  • The polite "no" that hung the link An error reply was written without one flag bit, so the router misread the following bytes and dropped the whole session as malformed. Every refusal – busy, bad request, timeout – killed the connection. The test had only checked the first byte.
  • Misaligned doubles. ROS's serialisation aligns 8-byte fields relative to the start of the message body, after a 4-byte header – not relative to the start of the buffer. Every message containing a float64 (temperature, illuminance, IMU…) would have decoded as garbage on a real ROS host. Only the range sensor had been checked against one – and it happens to use float32. The tests had been written from the encoder's own output, so they agreed with it perfectly.
  • The topic that went quiet. The example's original deferred service – a range read from one particular sensor, since replaced by a device-agnostic one – registered its own data callback for the sensor, and Raft kept only one callback per device, so it silently displaced the auto-publisher. /raft/range_1_29 published nothing for a day while every service test passed with flying colours. Raft's DeviceManager now fans readings out to any number of subscribers.
  • The peek that wasn't. Raft's call for reading a device's latest result turned out to consume it: it only returned a reading that had arrived since its previous call, from any caller. So two readers of the same device quietly starved each other. There's now a genuine peek alongside it.
  • Divided twice. Raft's generated decoders applied each field's divisor while decoding and also passed it on to whoever read the result – and the ROS publisher applied it again. So any sensor with a plain record and a divisor was scaled twice on its topic. That includes the AS5600 in the table above, whose angle was divided by about 11.4 twice. It turned up on the USB bench, when an IMU reported gravity as a tiny fraction of a g, and the decoders now pass on only what's still to be applied.
  • Settings that forgot themselves. Posted settings vanished on every reboot. The cause was C++ static initialisation order: the settings were read from flash before the flash storage had been initialised, in a different source file, and nothing guarantees which runs first. The classic "works until you turn it off and on again".

The common thread: a test that only checks your code against itself proves very little. The captures from real ROS processes, and the real ROS tools, were what found these.