Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update connection logic to match what bambu epexcts.
  • Loading branch information
Sticks committed Mar 5, 2024
1 parent 0c2a7af commit b1409a3
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 10 deletions.
125 changes: 124 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src-tauri/Cargo.toml
Expand Up @@ -20,10 +20,12 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.0", features = [ "dialog-confirm", "dialog-ask", "dialog-message", "clipboard-all"] }
dirs = "5.0.1"
reqwest = "0.11.24"
paho-mqtt = "0.12.3"
lazy_static = "1.4.0"
tokio = "1.36.0"
jsonwebtoken = "9.2.0"
rumqttc = "0.24.0"
log = "0.4.21"
paho-mqtt = "0.12.3"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
Expand Down
13 changes: 5 additions & 8 deletions src-tauri/src/handlers/bambu/mod.rs
@@ -1,11 +1,6 @@
use std::{borrow::Borrow, collections::HashSet, sync::Arc};

// Imports
use crate::constants;
use jsonwebtoken::{Algorithm, DecodingKey, Validation};
use paho_mqtt::connect_options;
use reqwest::header::ValueIter;
use serde::de;
use serde_json::{json, Number};
use tokio::sync::Mutex;

Expand Down Expand Up @@ -278,16 +273,15 @@ impl BambuClient {
let mut builder = paho_mqtt::ConnectOptionsBuilder::new();
builder
.keep_alive_interval(std::time::Duration::from_secs(30))
.user_name(jwt_decoded.claims.username)
.user_name(format!("u_{}", jwt_decoded.claims.preferred_username))
.password(token)
.ssl_options(paho_mqtt::SslOptions::new());
builder.finalize()
};

println!(
"[BambuClient::get_device_ips] Connecting to MQTT broker at {} with options: {:?}",
"[BambuClient::get_device_ips] Connecting to MQTT broker at {}",
constants::BAMBU_MQTT_URL,
connect_options
);

// Connect to the MQTT broker
Expand Down Expand Up @@ -326,6 +320,9 @@ impl BambuClient {
);

mqtt_client.subscribe(topic, 1).wait().map_err(|e| {
// Print the error stack
eprintln!("{}", e);

std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to subscribe to topic {}: {}", topic, e),
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Expand Up @@ -9,6 +9,8 @@ use commands::config::{get_config, init_config, save_config};
use commands::util::quit;

fn main() {
log::set_max_level(log::LevelFilter::Debug);

tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
init_config,
Expand Down

0 comments on commit b1409a3

Please sign in to comment.