Skip to content

About

The CheerLights color in Rust: the palette, colors named in a sentence, the live feed, and MQTT, with a no_std core for microcontrollers.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

CheerLights for Rust

The CheerLights color in Rust: the palette, the color named in a sentence, the live feed, and live changes over MQTT.

crates.io docs.rs CI License: MIT

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.

Quick start

Rust 1.87 or later:

cargo add cheerlights --features http
fn 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.

Examples

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.

Features

  • 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_in and first_color.
  • The current color and the last 1 to 8000 changes, oldest first, from ThingSpeak channel 1417: current() and history(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: feed and mqtt.
  • 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.

Limits

  • It reads the color; it does not set it. To set it, see cheerlights.com.
  • The no_std core has no networking. On a board, fetch feed::LAST_URL or subscribe to mqtt::TOPIC_NAME with 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 with cargo +esp build --target xtensa-esp32s3-none-elf -Zbuild-std=core.
  • The no_std builds 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.

Documentation

Development

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 broker

The 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.

License

MIT, see LICENSE.

About

The CheerLights color in Rust: the palette, colors named in a sentence, the live feed, and MQTT, with a no_std core for microcontrollers.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages