use chrono::prelude::Utc; use fundamentum_edge_proto::com::fundamentum::edge::v1::{ state_json_data::SubDevice, states_event_client::StatesEventClient, Qos, StateJsonData, }; use prost_wkt_types::Struct; use serde_json::json; use tonic::Request; async fn publish_states() -> Result<(), Box> { let mut client = StatesEventClient::connect("http://127.0.0.1:8080").await?; let state: Struct = serde_json::from_value(json!({ "status": "OK", "alarms": [], }))?; let sub_devices_state: Struct = serde_json::from_value(json!({ "rssi": 5, "battery_level": 100, "temperature": 26, }))?; let sub_devices = (1..10) .map(|i| SubDevice { serial_number: format!("device{i}"), states: Some(sub_devices_state.clone()), }) .collect(); let request = StateJsonData { timestamp: Some(Utc::now().into()), states: Some(state), sub_devices, qos: Some(i32::from(Qos::AtLeastOnce)), }; let _response = client.publish_json(Request::new(request)).await?; Ok(()) } #[tokio::main] async fn main() -> Result<(), Box> { publish_states().await?; Ok(()) }