summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 40da34e..410c651 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,20 +21,33 @@ async fn main() {
for printer in config.printers {
match printer {
- Printer::Prusa { name, host, api_key } => {
+ Printer::Prusa {
+ name,
+ host,
+ api_key,
+ } => {
tracing::info!(name, host, "Found Prusa");
tokio::spawn(poll_prusa(name, host, api_key, state.clone()));
}
- Printer::Bambu { name, host, serial_number, access_code } => {
+ Printer::Bambu {
+ name,
+ host,
+ serial_number,
+ access_code,
+ } => {
tracing::info!(name, host, "Found Bambu");
- tokio::spawn(poll_bambu(name, host, serial_number, access_code, state.clone()));
+ tokio::spawn(poll_bambu(
+ name,
+ host,
+ serial_number,
+ access_code,
+ state.clone(),
+ ));
}
}
}
- let app = Router::new()
- .route("/", get(root))
- .with_state(state);
+ let app = Router::new().route("/", get(root)).with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
@@ -94,6 +107,24 @@ async fn poll_bambu(
.await
.unwrap();
+ // Send an initial request to push all values to us; otherwise we'll have to wait for the values to come in incremental updates.
+ client
+ .publish(
+ format!("device/{}/request", serial_number),
+ QoS::AtMostOnce,
+ false,
+ r#"{
+ "pushing": {
+ "sequence_id": "0",
+ "command": "pushall",
+ "version": 1,
+ "push_target": 1
+ }
+ }"#,
+ )
+ .await
+ .unwrap();
+
loop {
// eventloop.poll() yields back to Tokio when there's no data
match eventloop.poll().await {
@@ -118,9 +149,7 @@ async fn poll_bambu(
}
}
-async fn root(
- State(state): State<StateMap>,
-) -> Json<HashMap<String, PrinterState>> {
+async fn root(State(state): State<StateMap>) -> Json<HashMap<String, PrinterState>> {
let lock = state.lock().await;
Json(lock.clone())
}