Add WIP relays to database and api

This commit is contained in:
Tobias Reisinger 2023-11-26 00:54:03 +01:00
parent 4e3df272c3
commit 734f8b291c
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
14 changed files with 387 additions and 88 deletions
emgauwa-controller/src

View file

@ -10,10 +10,12 @@ use tokio_tungstenite::tungstenite::Error;
use emgauwa_lib::db;
use emgauwa_lib::db::Controller;
use emgauwa_lib::db::types::ControllerUid;
use crate::relay_loop::run_relay_loop;
use crate::settings::Settings;
mod settings;
mod driver;
mod relay_loop;
fn create_this_controller(conn: &mut PoolConnection<Sqlite>, settings: &Settings) -> Controller {
futures::executor::block_on(async {
@ -43,8 +45,9 @@ async fn main() {
let this_json = serde_json::to_string(&this).unwrap();
println!("{:?}", settings.relays);
println!("{:?}", this);
println!("{:?}", this_json);
println!("{}", this_json);
let url = format!(
"ws://{}:{}/api/v1/ws/controllers",
@ -61,10 +64,12 @@ async fn main() {
write.send(Message::text(this_json)).await.unwrap();
let ws_to_stdout = read.for_each(handle_message);
let stdin_to_ws = stdin_rx.map(Ok).forward(write);
ws_to_stdout.await;
//pin_mut!(stdin_to_ws, ws_to_stdout);
//future::select(stdin_to_ws, ws_to_stdout).await;
tokio::spawn(run_relay_loop(settings));
pin_mut!(stdin_to_ws, ws_to_stdout);
future::select(stdin_to_ws, ws_to_stdout).await;
}
// Our helper method which will read data from stdin and send it along the