Rename some stuff
This commit is contained in:
parent
1c476dac64
commit
49304c70bc
11 changed files with 183 additions and 23 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,5 +6,5 @@
|
||||||
|
|
||||||
/emgauwa-*.sqlite
|
/emgauwa-*.sqlite
|
||||||
/emgauwa-*.sqlite-*
|
/emgauwa-*.sqlite-*
|
||||||
/emgauwa-*.json
|
/emgauwa-*.cfg.*
|
||||||
|
|
||||||
|
|
|
||||||
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -1,6 +1,6 @@
|
||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix"
|
name = "actix"
|
||||||
|
|
@ -766,6 +766,7 @@ dependencies = [
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"simple_logger",
|
"simple_logger",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||||
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
|
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
emgauwa-common = { git = "https://git.serguzim.me/emgauwa/common.git" }
|
emgauwa-common = { git = "https://git.serguzim.me/emgauwa/common.git", tag = "v0.5.2-rc.1" }
|
||||||
|
|
||||||
actix = "0.13"
|
actix = "0.13"
|
||||||
|
|
||||||
|
|
|
||||||
6
Makefile
6
Makefile
|
|
@ -1,14 +1,14 @@
|
||||||
build-rpi:
|
build-rpi:
|
||||||
cross build --target arm-unknown-linux-gnueabihf
|
cross build --target arm-unknown-linux-gnueabihf
|
||||||
|
|
||||||
emgauwa-controller.json: controller.pkl
|
emgauwa-controller.cfg.json: controller.pkl
|
||||||
pkl eval -f json -o $@ $<
|
pkl eval -f json -o $@ $<
|
||||||
|
|
||||||
config:
|
config:
|
||||||
$(MAKE) emgauwa-controller.json
|
$(MAKE) emgauwa-controller.cfg.json
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f emgauwa-controller.json
|
rm -f emgauwa-controller.cfg.*
|
||||||
rm -f emgauwa-controller.sqlite
|
rm -f emgauwa-controller.sqlite
|
||||||
|
|
||||||
emgauwa-controller_%:
|
emgauwa-controller_%:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
amends "package://emgauwa.app/pkl/emgauwa@0.2.1#/controller.pkl"
|
amends "package://emgauwa.app/pkl/emgauwa@0.2.3#/controller.pkl"
|
||||||
|
|
||||||
|
database = "sqlite://emgauwa-controller.sqlite"
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
host = "127.0.0.1"
|
||||||
|
port = 4419
|
||||||
token = "dev token"
|
token = "dev token"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
variable "REG" {
|
variable "REG" {
|
||||||
default = "registry.serguzim.me"
|
default = "rg.nl-ams.scw.cloud/public.serguzim.net"
|
||||||
}
|
}
|
||||||
variable "REPO" {
|
variable "REPO" {
|
||||||
default = "emgauwa/controller"
|
default = "emgauwa/controller"
|
||||||
|
|
|
||||||
75
emgauwa-controller.cfg
Normal file
75
emgauwa-controller.cfg
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 4419,
|
||||||
|
"token": "dev token"
|
||||||
|
},
|
||||||
|
"database": "sqlite://emgauwa-controller.sqlite",
|
||||||
|
"logging": {
|
||||||
|
"level": "DEBUG"
|
||||||
|
},
|
||||||
|
"relays": [
|
||||||
|
{
|
||||||
|
"number": 0,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 0,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 1,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 1,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 2,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 2,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 3,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 3,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 4,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 4,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 5,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 5,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 10,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 10,
|
||||||
|
"inverted": true,
|
||||||
|
"pulse": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 11,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 11,
|
||||||
|
"inverted": true,
|
||||||
|
"pulse": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 20,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 20,
|
||||||
|
"inverted": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 21,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 21,
|
||||||
|
"inverted": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
80
emgauwa-controller.json
Normal file
80
emgauwa-controller.json
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 4419,
|
||||||
|
"token": "dev token"
|
||||||
|
},
|
||||||
|
"database": "sqlite://emgauwa-controller.sqlite",
|
||||||
|
"permissions": {
|
||||||
|
"user": "",
|
||||||
|
"group": ""
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"level": "DEBUG"
|
||||||
|
},
|
||||||
|
"midnight": "00:00",
|
||||||
|
"relays": [
|
||||||
|
{
|
||||||
|
"number": 0,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 0,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 1,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 1,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 2,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 2,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 3,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 3,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 4,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 4,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 5,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 5,
|
||||||
|
"inverted": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 10,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 10,
|
||||||
|
"inverted": true,
|
||||||
|
"pulse": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 11,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 11,
|
||||||
|
"inverted": true,
|
||||||
|
"pulse": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 20,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 20,
|
||||||
|
"inverted": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"number": 21,
|
||||||
|
"driver": "null",
|
||||||
|
"pin": 21,
|
||||||
|
"inverted": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -64,8 +64,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
init_logging(&settings.logging)?;
|
init_logging(&settings.logging)?;
|
||||||
|
|
||||||
let pool = db::init(&settings.database, 5)
|
let pool = db::init(&settings.database, 5)
|
||||||
.await
|
.await?;
|
||||||
.map_err(EmgauwaError::from)?;
|
|
||||||
|
|
||||||
let mut conn = pool.acquire().await.map_err(EmgauwaError::from)?;
|
let mut conn = pool.acquire().await.map_err(EmgauwaError::from)?;
|
||||||
|
|
||||||
|
|
@ -85,8 +84,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
create_this_relay(&mut conn, &db_controller, relay)
|
create_this_relay(&mut conn, &db_controller, relay)
|
||||||
.await
|
.await?;
|
||||||
.map_err(EmgauwaError::from)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +95,8 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
|
|
||||||
let mut this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
|
let mut this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
|
||||||
|
|
||||||
|
conn.close().await.map_err(EmgauwaError::from)?;
|
||||||
|
|
||||||
let now = EmgauwaNow::now(&settings.midnight);
|
let now = EmgauwaNow::now(&settings.midnight);
|
||||||
let initial_states: Vec<bool> = this
|
let initial_states: Vec<bool> = this
|
||||||
.relays
|
.relays
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use tokio_tungstenite::tungstenite::Message;
|
||||||
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
|
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
|
||||||
use emgauwa_common::errors::{DatabaseError, EmgauwaError};
|
use emgauwa_common::errors::{DatabaseError, EmgauwaError};
|
||||||
use emgauwa_common::models::{Controller, Relay};
|
use emgauwa_common::models::{Controller, Relay};
|
||||||
use emgauwa_common::types::{ControllerWsAction, ScheduleUid};
|
use emgauwa_common::types::{ControllersWsAction, ScheduleUid};
|
||||||
|
|
||||||
use crate::app_state::AppState;
|
use crate::app_state::AppState;
|
||||||
use crate::app_state;
|
use crate::app_state;
|
||||||
|
|
@ -48,19 +48,19 @@ pub async fn handle_message(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_action(
|
pub async fn handle_action(
|
||||||
conn: &mut PoolConnection<Sqlite>,
|
conn: &mut PoolConnection<Sqlite>,
|
||||||
app_state: &Addr<AppState>,
|
app_state: &Addr<AppState>,
|
||||||
action: ControllerWsAction,
|
action: ControllersWsAction,
|
||||||
) -> Result<(), EmgauwaError> {
|
) -> Result<(), EmgauwaError> {
|
||||||
let this = AppState::get_this(app_state).await?;
|
let this = AppState::get_this(app_state).await?;
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
ControllerWsAction::Controller(controller) => {
|
ControllersWsAction::Controller(controller) => {
|
||||||
handle_controller(conn, &this, controller).await?
|
handle_controller(conn, &this, controller).await?
|
||||||
}
|
}
|
||||||
ControllerWsAction::Relays(relays) => handle_relays(conn, app_state, &this, relays).await?,
|
ControllersWsAction::Relays(relays) => handle_relays(conn, app_state, &this, relays).await?,
|
||||||
ControllerWsAction::Schedules(schedules) => handle_schedules(conn, schedules).await?,
|
ControllersWsAction::Schedules(schedules) => handle_schedules(conn, schedules).await?,
|
||||||
ControllerWsAction::RelayPulse((relay_num, duration)) => {
|
ControllersWsAction::RelayPulse((relay_num, duration)) => {
|
||||||
handle_relay_pulse(app_state, relay_num, duration).await?
|
handle_relay_pulse(app_state, relay_num, duration).await?
|
||||||
}
|
}
|
||||||
_ => return Ok(()),
|
_ => return Ok(()),
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use actix::Addr;
|
||||||
use emgauwa_common::constants;
|
use emgauwa_common::constants;
|
||||||
use emgauwa_common::constants::WEBSOCKET_RETRY_TIMEOUT;
|
use emgauwa_common::constants::WEBSOCKET_RETRY_TIMEOUT;
|
||||||
use emgauwa_common::errors::EmgauwaError;
|
use emgauwa_common::errors::EmgauwaError;
|
||||||
use emgauwa_common::types::ControllerWsAction;
|
use emgauwa_common::types::ControllersWsAction;
|
||||||
use futures::{future, pin_mut, SinkExt, StreamExt};
|
use futures::{future, pin_mut, SinkExt, StreamExt};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
|
|
@ -67,7 +67,7 @@ async fn run_websocket(
|
||||||
|
|
||||||
let (mut write, read) = ws_stream.split();
|
let (mut write, read) = ws_stream.split();
|
||||||
|
|
||||||
let ws_action = ControllerWsAction::Register(AppState::get_this(app_state).await?);
|
let ws_action = ControllersWsAction::Register(AppState::get_this(app_state).await?);
|
||||||
|
|
||||||
let ws_action_json = serde_json::to_string(&ws_action)?;
|
let ws_action_json = serde_json::to_string(&ws_action)?;
|
||||||
if let Err(err) = write.send(Message::text(ws_action_json)).await {
|
if let Err(err) = write.send(Message::text(ws_action_json)).await {
|
||||||
|
|
@ -104,7 +104,7 @@ async fn read_app_state(
|
||||||
log::debug!("Relay change detected");
|
log::debug!("Relay change detected");
|
||||||
let this = AppState::get_this(&app_state).await?;
|
let this = AppState::get_this(&app_state).await?;
|
||||||
let relay_states = this.get_relay_states();
|
let relay_states = this.get_relay_states();
|
||||||
let ws_action = ControllerWsAction::RelayStates((this.c.uid, relay_states));
|
let ws_action = ControllersWsAction::RelayStates((this.c.uid, relay_states));
|
||||||
|
|
||||||
let ws_action_json = serde_json::to_string(&ws_action)?;
|
let ws_action_json = serde_json::to_string(&ws_action)?;
|
||||||
tx.unbounded_send(Message::text(ws_action_json))
|
tx.unbounded_send(Message::text(ws_action_json))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue