summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSerguey Parkhomovsky <xindigo@gmail.com>2026-03-21 00:09:46 -0700
committerSerguey Parkhomovsky <xindigo@gmail.com>2026-03-21 00:09:46 -0700
commit222f1f93e84a149949ffaf5727958357b1d7df27 (patch)
tree39370e6f6e7a2ee6db41c296bcfb06d1ca1d469b /src
parenta0e24a0a10637c620de82f3f3070797e21706338 (diff)
Subscribe and publish in the connack branch, in case we lose connection.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index 410c651..3d019a7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -102,32 +102,33 @@ async fn poll_bambu(
mqttoptions.set_transport(Transport::tls_with_config(connector.into()));
let (client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
- client
- .subscribe(format!("device/{}/report", serial_number), QoS::AtMostOnce)
- .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 {
+ Ok(Event::Incoming(Packet::ConnAck(_))) => {
+ client
+ .subscribe(format!("device/{}/report", serial_number), QoS::AtMostOnce)
+ .await
+ .unwrap();
+ // Send a 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();
+ }
Ok(Event::Incoming(Packet::Publish(p))) => {
tracing::debug!(payload = ?p.payload, "Received Bambu payload");
match serde_json::from_slice::<BambuStatus>(&p.payload) {