✨ client server api
This commit is contained in:
parent
164c71ddfe
commit
6e31b95417
6 changed files with 89 additions and 7 deletions
|
@ -1,4 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::Machine;
|
||||
use crate::api::{ClientAction, ClientActions, ServerResponse};
|
||||
use owl::prelude::*;
|
||||
use owl::{Serialize, get, query};
|
||||
use rumqttc::AsyncClient;
|
||||
|
@ -17,12 +20,16 @@ pub async fn handle_mqtt(topic: String, data: Vec<u8>) {
|
|||
.unwrap();
|
||||
|
||||
// TODO : check for recency
|
||||
println!("got raw: {}", String::from_utf8(dec.payload).unwrap());
|
||||
|
||||
match cat {
|
||||
"online" => {
|
||||
log::info!("Device {client} reported ONLINE");
|
||||
}
|
||||
"respond" => {
|
||||
let resp: ServerResponse = serde_json::from_slice(&dec.payload).unwrap();
|
||||
|
||||
log::info!("Got response {:?}", resp);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +60,10 @@ pub async fn listen_to_device(client: &AsyncClient, machine_id: &str) {
|
|||
.subscribe(format!("{machine_id}/online"), rumqttc::QoS::AtMostOnce)
|
||||
.await
|
||||
.unwrap();
|
||||
client
|
||||
.subscribe(format!("{machine_id}/respond"), rumqttc::QoS::AtMostOnce)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Subscibe to incoming messages from all registered machines
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue