The CheerLights color in Rust: the palette, the color named in a sentence, the live feed, and live changes over MQTT.
CheerLights is a network of lights around the world that all show the same color, and anyone can set it.
This crate reads that color and finds the color named in a sentence, using the same rule as the CheerLights app and the Bluesky bridge.
Its core is no_std and allocates nothing, so the same code builds for an ESP32-C3 or a Raspberry Pi Pico and for a PC.
Fetching over the network is in two optional features, http and mqtt, which need the standard library.
Rust 1.87 or later:
cargo add cheerlights --features httpfn main() -> Result<(), cheerlights::Error> {
let now = cheerlights::current()?;
let rgb = now.rgb().unwrap_or_default();
println!("{} {rgb} since {}", now.name.as_deref().unwrap_or("?"), now.set_at);
Ok(())
}Output from version 0.1.0 on 2026-11-29 (UTC):
orange #ffa500 since 2026-11-29T03:23:23Z
rgb.r, rgb.g, and rgb.b are the values an RGB LED or a NeoPixel takes.
Find the color in a sentence, with no network and no allocator:
use cheerlights::{Color, colors_in, first_color};
assert_eq!(first_color("green with envy"), Some(Color::Green));
assert_eq!(colors_in("red and green for the holidays").as_slice(), &[Color::Red, Color::Green]);
assert!(colors_in("evergreen trees").is_empty());Follow every change the moment it happens (--features mqtt):
fn main() -> Result<(), cheerlights::Error> {
for color in cheerlights::mqtt::follow()? {
match color {
Ok(color) => println!("{color} {}", color.hex()),
Err(e) => eprintln!("{e}; reconnecting"),
}
}
Ok(())
}The first color is the current one, because the broker keeps it.
Run the three examples in this repository with cargo run --example current --features http, history, or follow --features mqtt.
- The 11 CheerLights colors with their names, HEX values, RGB values, palette index, and the ink that reads on each:
Color. - Names and HEX values in any case:
Color::from_name("Old Lace"),Rgb::from_hex("#FFA500").warmwhite, oldlace's original name in the feed's older history, reads as oldlace. - The colors named in a sentence, in order, matched by whole words:
colors_inandfirst_color. - The current color and the last 1 to 8000 changes, oldest first, from ThingSpeak channel 1417:
current()andhistory(count)(http). - Every change as it happens from
mqtt.cheerlights.com, reconnecting after outages:mqtt::follow()(mqtt). - Parsers for the feed's JSON, its plain-text endpoints, and every MQTT topic, for boards that bring their own HTTP or MQTT client:
feedandmqtt. - Times as the feed records them, parsed and compared without the standard library:
Timestamp. - Builds with no features for the ESP32-C3 (
riscv32imc-unknown-none-elf), the ESP32 and ESP32-S3 (xtensa-esp32-none-elf,xtensa-esp32s3-none-elf), the RP2350 (thumbv8m.main-none-eabihf), and the RP2040 (thumbv6m-none-eabi), checked in CI on every push.
- It reads the color; it does not set it. To set it, see cheerlights.com.
- The
no_stdcore has no networking. On a board, fetchfeed::LAST_URLor subscribe tomqtt::TOPIC_NAMEwith the board's own stack and pass the bytes to the parsers. - The original ESP32 and the ESP32-S3 use Xtensa cores, which need Espressif's toolchain: install it with
espup, then build withcargo +esp build --target xtensa-esp32s3-none-elf -Zbuild-std=core. - The
no_stdbuilds are checked by compiling them; the crate has not been run on a board yet. - MQTT uses plain port 1883, the broker's only port.
- What counts as a letter in a sentence follows Unicode 16.0, the version Python 3.14 uses, so the crate agrees with the Bluesky bridge.
- API reference on docs.rs: every type and function, with examples.
- CheerLights: the project, the feeds, and how to build a light.
git clone https://github.com/cheerlights/cheerlights-rust-crate
cd cheerlights-rust-crate
cargo test --all-features # offline, against the CheerLights spec files in tests/data
cargo test --all-features -- --ignored # against the live feed and brokerThe tests read copies of the CheerLights spec files in tests/data: the palette, the 23 shared sentences, and 4,068 generated ones.
CI fails when a copy differs from the spec.
uv run tools/word_table.py regenerates the Unicode tables in src/word_table.rs.
MIT, see LICENSE.