diff --git a/src/printer/bambu_mqtt.rs b/src/printer/bambu_mqtt.rs index 6635d46..30b16f3 100644 --- a/src/printer/bambu_mqtt.rs +++ b/src/printer/bambu_mqtt.rs @@ -86,6 +86,20 @@ const REQUEST_TIMEOUT: Duration = Duration::from_secs(10); /// 1MB has real headroom for that. const MAX_PACKET_SIZE: usize = 1024 * 1024; +/// Every `sequence_id` this crate generates gets this prefix - a printer +/// runs its own independent counter for unsolicited messages (confirmed +/// live: `print.push_status`'s was already in the 500s at the start of a +/// session, climbing steadily), and that counter has only ever been +/// observed as a plain unprefixed integer string. An earlier version of +/// this just started our own counter from a large offset instead of +/// prefixing it, to dodge the same range a printer's counter climbs +/// through - confirmed live (with an ISO-timestamp-prefixed sequence_id) +/// that `sequence_id` isn't required to be numeric at all, so a +/// non-numeric prefix rules out collision outright instead of merely +/// making it improbable, and the counter itself can go back to starting +/// at 1 each session. +const SEQUENCE_ID_PREFIX: &str = "cxproxy-"; + enum BambuMqttClient { V1(rumqttc::AsyncClient), V2(rumqttc::v5::AsyncClient), @@ -292,7 +306,10 @@ impl BambuMqttSession { /// `PrintStatusCache`. Not for a command with no reply at all either, /// like `gcode_line` - use `publish` (fire-and-forget) for those. pub async fn request(&self, category: &str, mut body: Value) -> Result { - let sequence_id = self.next_sequence_id.fetch_add(1, Ordering::Relaxed).to_string(); + let sequence_id = format!( + "{SEQUENCE_ID_PREFIX}{}", + self.next_sequence_id.fetch_add(1, Ordering::Relaxed) + ); body["sequence_id"] = Value::String(sequence_id.clone()); let (tx, rx) = oneshot::channel();