I am trying to make an mqtt dashboard with Tauri. to be able to do that, I want to connect to the broker in the setup hook and then save the client and connection in the tauri::app so I can use it in my custom tauri commands. Any sugestions to make this to work?
.setup(|app| {
//connect to mqtt broker
let device_key = "device-key";
let broker_url = "localhost";
let broker_port = 1883;
let mqtt_key = "mqtt-key";
let mqtt_secret = "mqtt-secret";
let mut mqttoptions = MqttOptions::new(device_key, broker_url, broker_port);
let will = LastWill::new(
format!("lastwill/{}", device_key),
"disconnected",
QoS::AtLeastOnce,
false,
);
mqttoptions.set_last_will(will);
mqttoptions.set_credentials(mqtt_key, mqtt_secret);
mqttoptions.set_keep_alive(Duration::from_secs(5));
let (mut client, mut connection) = Client::new(mqttoptions, 10);
let mut ctx = app.context();
ctx.data.insert(client);
Ok(ctx)
})