Skip to content

Reach the Crazyflies through crazyflie-connection-server (experimental) - #62

Open
evoggy wants to merge 19 commits into
mainfrom
evoggy/connection-server
Open

evoggy wants to merge 19 commits into
mainfrom
evoggy/connection-server

Conversation

@evoggy

@evoggy evoggy commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

cfcli reaches the Crazyflies through the client API of crazyflie-connection-server (0.2.3 on crates.io). With a connection server running, several programs use the same Crazyflies at once, for example cfcli setting parameters while Swarmkeeper monitors the swarm, and a server on one computer serves cfcli on others. The connection features are marked experimental.

Where cfcli reaches the Crazyflies

--connection, else CRAZYFLIE_CONNECTION, else cfcli settings connection, else auto:

Connection The Crazyradios are driven by
auto (default) a connection server on this computer if one runs, otherwise cfcli itself
direct cfcli itself
local the connection server on this computer (127.0.0.1:7777)
host, host:port a connection server on another computer

Without a server, auto is direct: cfcli runs the server in its own process and nothing else reaches it, so cfcli behaves as before. Swarmkeeper serves its connections on 127.0.0.1:7777, so with Swarmkeeper running cfcli uses its connections instead of competing for the Crazyradios.

New commands

  • cfcli server run: a standalone server holding this computer's Crazyradios. --listen (default 127.0.0.1:7777), --linger (seconds a Crazyflie stays connected after its last client), --toc-cache DIR (TOCs on disk, by default in the cache directory).
  • cfcli server list: the Crazyflies the server holds and the programs attached to them.
  • cfcli settings connection show/set/clear.

Through the client API, in every mode

  • scan (with the programs attached to each Crazyflie), select, param, log, console, platform info/reboot/power-off/sleep/wakeup, debug, deck, lh config, config, mem, loco, hlc (trajectories included).
  • bootload flash of the STM32 and nRF51 runs as a job on the server when one holds the Crazyradios, and the other Crazyflies stay connected. Deck firmware is skipped with a note, and the nRF51 bootloader and softdevice are refused; both need --connection direct.
  • Swarm commands: the server connects the swarm. Crazyflies on channels less than 2 apart share a Crazyradio, all connect at once, and each firmware's TOCs are downloaded once. swarm bootload flash is one job per platform (broadcast when the bootloaders support it), wakes Crazyflies that are asleep first and shows a bar per step, counting the Crazyflies that finished it. swarm rechannel and reprogramming in config add reboot each Crazyflie onto its new link through the server.
  • In direct mode the swarm runner still spreads the Crazyflies over the Crazyradios with cfcli's radio plan. It no longer connects at most 8 per radio at a time: all at once was faster in every test.
  • A Crazyflie that is starting is waited for: the server waits up to 5 s for a firmware that is silent while the nRF51 acks, and in direct mode bootload flash/info (single and swarm) return once the Crazyflie runs its firmware again (at most 15 s), so the next command finds it running. bootload flash of one Crazyflie takes 26 s instead of 21 s, and one that another program put to sleep takes 5 s to be reported as asleep.

Direct mode only

test, platform dfu, bootload other than flash, bootload flash --cold, swarm bootload info and swarm bootload flash --unicast. With a server holding the Crazyradios they stop with exit code 10 and say to use --connection direct.

--preserve-console does nothing through a server, which keeps each Crazyflie's console for cfcli console, and says so.

Docs

docs/connection-server.md (new, with an experimental warning), a section in docs/settings.md, and the README's command list, options and doc index.

Found while testing: the hlc stop help said it disables the motors, but the Crazyflie stays armed (a brushless one idles its motors); the trajectory examples and hlc trajectory display pointed at cfcli trajectory upload/run.

Testing

  • cargo test: 103 pass.
  • One Crazyflie at the desk, direct mode: scan, platform info, param get/list, log once and streaming. param list output is byte-identical to cfcli 0.17.0.
  • One Crazyflie through cfcli server run, from separate processes: log stream, console, scan, server list and param set at the same time. Attaching took 7 ms. Unported commands exit with 10. bootload flash of a release (STM32 and nRF51) through the server: 29 s.
  • 9 Crazyflie 2.1 Brushless through a server on a Raspberry Pi with 3 Crazyradios:
    • swarm scan 9 of 9 in 0.44 s; swarm platform info, param get, log print --once 9 of 9 in 3–4 s with connecting, 0.4 s while the connections lingered
    • swarm debug assert, swarm platform reboot (9 of 9 back in 6 s), platform sleep/wakeup
    • swarm bootload flash: 9 of 9 by broadcast in 47 s, and later with 3 of 5 asleep (woken first) in 54 s
    • swarm rechannel: 4 Crazyflies moved from channel 88 to 90
    • swarm config add --scan; config (an EEPROM write of the same values) and lh config write on one Crazyflie
  • 25 Crazyflies on one Crazyradio through the same server: swarm param get in 1.6 s.
  • Direct mode on a Crazyradio: swarm bootload flash, and the performance comparison below.

Performance, direct mode

Against cfcli 0.18.0 built from main (5e5917b), on this computer's Crazyradios, each with its own scratch settings, runs alternating, median of 3 to 10 runs. Outputs are identical.

Command 0.18.0 this PR
param get, one Crazyflie 0.28 s 0.29 s
param get, no TOC cache 2.27 s 2.27 s
param list 4.21 s 4.22 s
log print, 4 variables at 10 ms for 10 s 989 samples, max gap 10 ms 988 samples, max gap 10 ms
swarm scan, 9 Crazyflies 0.09 s 0.09 s
swarm param get, 9 0.81 s 0.64 s
swarm param get, 9, no TOC cache 16.44 s 3.07 s
swarm log print --once, 9 1.09 s 0.62 s

With crazyflie-connection-server 0.2.0 a command on one Crazyflie took 40 ms longer (0.32 s) and 300 ms longer without the TOC cache (extra round trips while connecting); 0.2.1 fixes that. With 0.2.0 on 25 Crazyflies on two Crazyradios: swarm scan 0.33 → 0.16 s, swarm param get 1.40 → 1.33 s, swarm log print --once 1.70 → 1.34 s. Peak memory is about 2.5 MB higher for one Crazyflie and 5–12 MB for a swarm.

Hardware, direct and local

The fishtank (9 Crazyflie 2.1 Brushless, release 2026.10, Lighthouse and Color LED decks, channel 90) on this computer's 2 Crazyradios, once in direct mode and once through cfcli server run on this computer (--connection local):

  • hlc arm (motors to idle), disarm, stop, trajectory upload of figure8 and square to two offsets, read back with mem verify and identical to the YAML; trajectory display of memory and of a file. No takeoff, land, goto or trajectory run.
  • platform info, reboot, sleep, wakeup, single and swarm; asleep Crazyflies are reported as asleep. Direct only: platform dfu (no USB: clear error, platform reboot brings it back).
  • config display/set (same values), lh config read/write/check and swarm lh write/check (a changed calibration written, checked, written back), deck list, mem, loco, debug assert, console, swarm param/log.
  • bootload flash of the STM32 and nRF51 from the 2026.10 zip: direct 21 s, through the server 26 s; swarm bootload flash of 2 through the server by broadcast in 52 s, one of them asleep and woken first; direct only: swarm bootload flash --unicast (2 in 42 s), bootload info, swarm bootload info.
  • swarm rechannel (90 → 88 → 90) and swarm config add --set-channel in both modes.
  • Direct-only commands through the local server stop with exit code 10.

Found and fixed (crazyflie-connection-server 0.2.2 and this PR):

  • Server 0.2.1 left answers to its version questions for crazyflie-lib to read when the firmware answered slowly: "Wrong version answer" on every connect 3 s after swarm bootload info (0.17.0: none), and now and then on the first connect after a few idle minutes, in both modes. Fixed in 0.2.2: no "Wrong version answer" since, in three repeats of that sequence and the reboots and flashes in both modes, and no slower (one Crazyflie 0.316 → 0.318 s, 9 Crazyflies 0.730 → 0.738 s, 3 Crazyflies 0.450 → 0.454 s).
  • A connect while a Crazyflie was starting failed as "asleep or in its bootloader": the server gave up when the firmware was silent for 600 ms, where 0.17.0 waits (3 s after swarm bootload info on 9, 0.17.0 reached 8 and the PR none). After a reboot a Crazyflie 2.1 Brushless here acks at its address at 2.7 s (once its STM32 has set it) and its firmware answers at about 5.1 s. With 0.2.2 and the waits above, a command right after bootload info, a flash (single, unicast, broadcast) or platform wakeup connects (0.3 s once the restart was waited for), a connect as soon as a rebooting Crazyflie acks waits 2.7 s and connects, a Crazyflie that is off still fails in 1.2 s, and an asleep one after 5.1 s.
  • With a server holding the Crazyradios, --connection direct with radio://0/… said the Crazyflie doesn't answer; now that the Crazyradio is in use.

Open:

  • platform reboot of a Crazyflie that comes back at another address (recovering from the nRF51 lost-address bug at E7E7E7E7E7) reports after 15 s that it didn't come back, although it did.
  • Not tested: HLC flights (no flying), bootload flash --cold and platform power-off (need someone at the Crazyflies).

evoggy added 17 commits October 18, 2026 22:23
Scan, select, param, log, console, platform info and hlc go through the
connection server's client API, so they work directly with this
computer's Crazyradios or through a connection server, chosen with
--connection, CRAZYFLIE_CONNECTION or 'settings connection'. The default,
auto, uses a server on this computer if one runs, else the Crazyradios.

'cfcli server run' runs a standalone connection server and 'cfcli server
list' shows the Crazyflies it holds and the programs attached to them.

The swarm runner keeps its own connecting and hands each connection to an
in-process server, so swarm param, log and platform info share the code of
the single Crazyflie commands. Commands not ported yet use crazyflie-lib
directly and fail with a clear error while a server holds the Crazyradios.

crazyflie-connection-server is a path dependency for now.
bootload flash sends the STM32 and nRF51 firmware to the server's flash job.
Deck firmware is skipped with a note; the nRF51 bootloader+softdevice and
--cold still need --connection direct.
The swarm runner attaches through the client API in every mode; in
direct mode it still plans the radios and pins each Crazyflie. Through a
server swarm scan, platform (also reboot, power off, sleep, wake up),
param, log, debug assert, config add --scan and bootload flash (one job
per platform) work. Deck list, lh, rechannel, bootload info and
reprogramming stay direct only, with a clear error. The single-Crazyflie
platform commands and debug assert use the client too, server list shows
the radio, and log print reports why its stream ended.
deck list, lh config, config, mem, swarm deck list and swarm lh use the
client's memories, so they work through a connection server too. The
EEPROM writes of rechannel and reprogramming go through the client;
both stay direct only for the reboot onto the new link. Displaying a
deck memory still uses crazyflie-lib.
hlc trajectory and loco use the client's trajectory and Loco memories
and LPP packets, so they work through a connection server too.
The swarm runner no longer handles 8 Crazyflies per radio at a time:
the ones already connected keep polling the radio while the next ones
connect, so all at once is faster (25 on one radio: 21.6 s to 1.6 s for
swarm param get through a server, with the server changes). The
bootloader and deck steps keep their own limits. Whether a param is
persistent is asked for, through the client API.
cfcli server run caches TOCs in a directory, by default
~/.cache/cf-cli/server-toc-cache, rather than in memory, so a restart
doesn't download them again. Not in cfcli's config file: a long-running
server would write back the whole config it loaded.
swarm rechannel and the reprogramming in swarm config add reboot each
Crazyflie onto its new URI with Client::reboot_to, which returns once
the firmware answers there, so they no longer need direct mode. The
runner's own wait for a rebooted Crazyflie is gone.
swarm bootload flash connects to each Crazyflie to read its platform.
One the server reports asleep is now powered on and attached again,
since flashing restarts it anyway.
It connects a Crazyflie with fewer round trips: a command on one Crazyflie
takes as long as with crazyflie-lib directly again.
The server keeps each Crazyflie's console and `cfcli console` prints it, so
the flag was ignored without a word there.
`hlc stop` cuts the thrust but leaves the Crazyflie armed, so a brushless
one keeps its motors at idle; the help said it disabled the motors. The
trajectory examples and `hlc trajectory display` still pointed at
`cfcli trajectory upload` and `cfcli trajectory run`.
It waits for a Crazyflie that is starting instead of calling it asleep, and no longer leaves answers to its version questions for crazyflie-lib to read ("Wrong version answer" right after a restart).
`bootload flash` and `bootload info` (and their swarm versions) in direct
mode returned as soon as the Crazyflie had left its bootloader. Its address
only answers once its STM32 has started (2.7 s after a restart here) and its
firmware a few seconds later, so a command run right after failed. Now they
return once it runs its firmware again, or fail after 15 s saying it isn't
back. The swarm commands wait for all their Crazyflies at once. A flash
through a connection server waited already.

`bootload flash` of one Crazyflie takes 21 -> 26 s; the next command then
connects in 0.3 s instead of failing.
@evoggy
evoggy marked this pull request as ready for review October 29, 2026 21:19
A flash job on a server printed a line for every Crazyflie at every step,
which for a swarm scrolled by without saying how far it was. Servers from
0.2.3 count the Crazyflies that finished each step, so swarm bootload flash
now shows a bar per step, as it does without a server. Writing an image keeps
its byte bar; steps of a single Crazyflie, and those from older servers,
stay lines. bootload flash prints each step once instead of again when it is
done.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant