Crates.io | bambulab |
lib.rs | bambulab |
version | 0.4.10 |
source | src |
created_at | 2023-11-25 15:21:18.707034 |
updated_at | 2024-11-19 12:39:12.586125 |
description | API client for Bambu Lab printers |
homepage | |
repository | https://github.com/markhaehnel/bambulab |
max_upload_size | |
id | 1048357 |
size | 63,548 |
🚧 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.
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.
You can find the access code in the printer settings under "WLAN" -> "Access Code".
The serial can be found in the printer settings under "SN".
See the contributing guidelines for more information.
This code is licensed under either of
at your option.
This project is not officially associated with Bambu Lab. It is a third-party implementation.