12 releases

0.4.10 Nov 19, 2024
0.4.7 Oct 28, 2024
0.4.4 Jun 15, 2024
0.4.3 Mar 12, 2024
0.3.0 Nov 29, 2023

#1239 in Network programming

Download history 7/week @ 2024-09-25 6/week @ 2024-10-02 2/week @ 2024-10-09 275/week @ 2024-10-16 145/week @ 2024-10-23 142/week @ 2024-10-30 164/week @ 2024-11-06 123/week @ 2024-11-13 74/week @ 2024-11-20 4/week @ 2024-11-27

402 downloads per month

MIT/Apache

24KB
492 lines

Bambulab API

Docs GitHub workflow status Crates.io Version Crates.io Downloads License

🚧 WORK IN PROGRESS 🚧

This crate is still in development and not ready for production use. Breaking changes may occur at any time.

bambulab is a async Rust crate that provides a channel based client for interacting with Bambu Lab devices over their MQTT broker.

Features

  • Subscribe to printer messages like print progress, temperatures, errors, etc.
  • Publish commands to the printer
  • Support for P1P, P1S and X1C printer

Usage

First, add bambulab to your dependencies:

cargo add bambulab

Then, use the Client struct to create a new client and connect to a printer:

use bambulab::{client::Client, command::Command};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let host = "printer-ip-or-hostname";
    let access_code = "printer-access-code";
    let serial = "printer-serial-number";

    let (tx, mut rx) = tokio::sync::broadcast::channel::<Message>(25);

    let mut client = Client::new(host, access_code, serial, tx);
    let mut client_clone = client.clone();

    tokio::try_join!(
        tokio::spawn(async move {
            client.run().await.unwrap();
        }),
        tokio::spawn(async move {
            loop {
                let message = rx.recv().await.unwrap();
                println!("received: {message:?}");

                if message == Message::Connected {
                    client_clone.publish(Command::PushAll).await.unwrap();
                }
            }
        }),
    )?;

    Ok(())
}

Please note that you need to call subscribe() to allow the API to listen to messages.

More examples available in the examples directory.

FAQ

How do I find the access code?

You can find the access code in the printer settings under "WLAN" -> "Access Code".

How do I find the serial number?

The serial can be found in the printer settings under "SN".

Contributing

See the contributing guidelines for more information.

License

This code is licensed under either of

at your option.

Disclaimer

This project is not officially associated with Bambu Lab. It is a third-party implementation.

Dependencies

~17–23MB
~418K SLoC