diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 45 |
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) { |
