📝 docs

This commit is contained in:
JMARyA 2025-04-30 10:02:04 +02:00
parent a567214f58
commit 164c71ddfe
9 changed files with 36 additions and 2 deletions

View file

@ -4,20 +4,31 @@ use std::time::Duration;
use tokio::time::sleep;
#[derive(Deserialize, Serialize)]
/// Join Request
pub struct JoinParams {
/// Optional join token
pub join_token: Option<String>,
/// Machine ID
pub machine_id: String,
/// Hostname
pub hostname: String,
/// Public Key Identity
pub identity: (String, String),
}
#[derive(Deserialize, Serialize)]
pub struct JoinResponse {
/// Server Token
pub token: String,
/// Server Identity
pub identity: (String, String),
/// MQTT endpoint
pub mqtt: String,
}
/// Setup a MQTT connection for `machine_id` on `mqtt`.
///
/// This will connect either over `ws://` or `wss://` depending on the scheme of `mqtt`. By default it will use `wss://`.
pub fn mqtt_connect(machine_id: &str, mqtt: &str) -> (rumqttc::AsyncClient, rumqttc::EventLoop) {
let mqttoptions = if mqtt.starts_with("ws://") {
log::warn!("Using unencrypted WebSocket connection");
@ -46,6 +57,7 @@ pub fn mqtt_connect(machine_id: &str, mqtt: &str) -> (rumqttc::AsyncClient, rumq
AsyncClient::new(mqttoptions, 10)
}
/// Run the async MQTT event loop
pub async fn run_event_loop<F, Fut>(mut eventloop: EventLoop, handle_payload: F)
where
F: Fn(String, Vec<u8>) -> Fut + Send + Sync + 'static,
@ -77,6 +89,7 @@ where
}
#[derive(Deserialize, Serialize)]
/// Generic JSON API result
pub struct Result {
pub ok: u32,
}