📝 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,6 +4,7 @@ use owl::{Serialize, get, query};
use rumqttc::AsyncClient;
use sage::PersonaIdentity;
/// Handle herd MQTT
pub async fn handle_mqtt(topic: String, data: Vec<u8>) {
log::info!("Received client request from {topic}");
let (client, cat) = topic.split_once('/').unwrap();
@ -26,6 +27,7 @@ pub async fn handle_mqtt(topic: String, data: Vec<u8>) {
}
}
/// Send a message to a registered `machine`
pub async fn send_msg<T: Serialize>(client: &AsyncClient, machine: &Model<Machine>, request: T) {
let data = serde_json::to_string(&request).unwrap();
let pk = &machine.read().identity;
@ -44,6 +46,7 @@ pub async fn send_msg<T: Serialize>(client: &AsyncClient, machine: &Model<Machin
.unwrap();
}
/// Subscribe to all `device->server` topics
pub async fn listen_to_device(client: &AsyncClient, machine_id: &str) {
// Online Presence
client
@ -52,6 +55,7 @@ pub async fn listen_to_device(client: &AsyncClient, machine_id: &str) {
.unwrap();
}
/// Subscibe to incoming messages from all registered machines
pub async fn listen_to_devices(client: &AsyncClient) {
let machines: Vec<Model<Machine>> = query!(|_| true);
for machine in machines {