From 444e5bb7fda411b1d7792889649a03a60bad8ac3 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 10:56:04 +0100 Subject: [PATCH 01/59] =?UTF-8?q?small=20try=20with=20Haust=C3=BCr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/haustuer.rs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/main.rs | 15 +++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/haustuer.rs diff --git a/Cargo.lock b/Cargo.lock index 7bef3b3..68f0fd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1416,7 +1416,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "opensesame" -version = "0.8.3" +version = "0.8.4" dependencies = [ "async-ssh2-tokio", "bme280", diff --git a/Cargo.toml b/Cargo.toml index 309d858..203045d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opensesame" -version = "0.8.3" +version = "0.8.4" authors = ["Opensesame Contributors"] edition = "2021" readme = "README.md" diff --git a/src/haustuer.rs b/src/haustuer.rs new file mode 100644 index 0000000..f103c15 --- /dev/null +++ b/src/haustuer.rs @@ -0,0 +1,81 @@ +use futures::never::Never; +use systemstat::Duration; +use tokio::{sync::mpsc::Sender, time::interval}; +use i2cdev::core::*; +use i2cdev::linux::LinuxI2CDevice; +use i2cdev::linux::LinuxI2CError; + +use crate::{ + buttons::CommandToButtons, + config::Config, + nextcloud::NextcloudEvent, +// nextcloud::{NextcloudChat, NextcloudEvent, NextcloudStatus}, + types::ModuleError, +}; + +const MOD_IO_I2C_ADDR: u16 = 0x58; + +const READ_COMMAND_FOR_IO_OPTO_PINS: u8 = 0x20; + + +#[derive(PartialEq, Debug)] +pub enum HaustuerChange { + None, + + Pressed(u8), + + Err (String), +} + +pub struct Haustuer { + board: LinuxI2CDevice, +} + +impl Haustuer { + pub fn new(_config: &mut Config) -> Self { + Self { + board: LinuxI2CDevice::new("/dev/i2c-2", MOD_IO_I2C_ADDR).unwrap() + } + } + + fn set_relay(&mut self, which: u8) -> Result<(), LinuxI2CError> { + self.board.smbus_write_byte_data(0x10, which)?; + Ok(()) + } + + pub fn handle(&mut self) -> HaustuerChange { + let epins = self.board.smbus_read_byte_data(READ_COMMAND_FOR_IO_OPTO_PINS); + if let Err(error) = epins { + return HaustuerChange::Err(format!("Board 58 with error {}", error)); + } + + let pins = epins.unwrap(); + self.set_relay (pins).unwrap(); + + if pins != 0 { + return HaustuerChange::Pressed(pins); + } + + HaustuerChange::None + } + + pub async fn get_background_task( + mut haustuer: Haustuer, + _command_sender: Sender, + _nextcloud_sender: Sender, + ) -> Result { + let mut interval = interval(Duration::from_millis(10)); + loop { + match haustuer.handle() { + HaustuerChange::None => (), + HaustuerChange::Pressed(epins) => { + println!("Pressed {}", epins); + } + HaustuerChange::Err(err) => { + println!("Pressed {}", err); + } + } + interval.tick().await; + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 4c050bd..a0d5792 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ pub mod clima_sensor_us; pub mod config; pub mod environment; pub mod garage; +pub mod haustuer; pub mod mod_ir_temp; pub mod nextcloud; pub mod ping; diff --git a/src/main.rs b/src/main.rs index 6ea2b2a..8700ee8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use opensesame::clima_sensor_us::ClimaSensorUS; use opensesame::config::Config; use opensesame::environment::{EnvEvent, Environment}; use opensesame::garage::Garage; +use opensesame::haustuer::Haustuer; use opensesame::mod_ir_temp::ModIR; use opensesame::nextcloud::{Nextcloud, NextcloudChat, NextcloudEvent}; use opensesame::ping::{Ping, PingEvent}; @@ -53,6 +54,7 @@ async fn main() -> Result<(), ModuleError> { let buttons_enabled = config.get_bool("buttons/enable"); let garage_enabled = config.get_bool("garage/enable"); + let haustuer_enabled = config.get_bool("haustuer/enable"); let sensors_enabled = config.get_bool("sensors/enable"); let modir_enabled = config.get_bool("ir/enable"); let env_enabled = config.get_bool("environment/enable"); @@ -83,6 +85,19 @@ async fn main() -> Result<(), ModuleError> { ))); } + if haustuer_enabled { + /* TODO, allow for now + if !buttons_enabled { + panic!("Haustuer depends on buttons!"); + } + */ + tasks.push(spawn(Haustuer::get_background_task( + Haustuer::new(&mut config), + command_sender.clone(), + nextcloud_sender.clone(), + ))); + } + if buttons_enabled { let time_format = config.get::("nextcloud/format/time"); let location_latitude = config.get::("location/latitude"); From 3da4c5f4da02d9ea350f7a4a71a8e6af355493ce Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 11:20:13 +0100 Subject: [PATCH 02/59] reformat --- src/haustuer.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index f103c15..9d53459 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -1,15 +1,15 @@ use futures::never::Never; -use systemstat::Duration; -use tokio::{sync::mpsc::Sender, time::interval}; use i2cdev::core::*; use i2cdev::linux::LinuxI2CDevice; use i2cdev::linux::LinuxI2CError; +use systemstat::Duration; +use tokio::{sync::mpsc::Sender, time::interval}; use crate::{ buttons::CommandToButtons, config::Config, nextcloud::NextcloudEvent, -// nextcloud::{NextcloudChat, NextcloudEvent, NextcloudStatus}, + // nextcloud::{NextcloudChat, NextcloudEvent, NextcloudStatus}, types::ModuleError, }; @@ -17,14 +17,13 @@ const MOD_IO_I2C_ADDR: u16 = 0x58; const READ_COMMAND_FOR_IO_OPTO_PINS: u8 = 0x20; - #[derive(PartialEq, Debug)] pub enum HaustuerChange { None, Pressed(u8), - Err (String), + Err(String), } pub struct Haustuer { @@ -34,7 +33,7 @@ pub struct Haustuer { impl Haustuer { pub fn new(_config: &mut Config) -> Self { Self { - board: LinuxI2CDevice::new("/dev/i2c-2", MOD_IO_I2C_ADDR).unwrap() + board: LinuxI2CDevice::new("/dev/i2c-2", MOD_IO_I2C_ADDR).unwrap(), } } @@ -44,13 +43,15 @@ impl Haustuer { } pub fn handle(&mut self) -> HaustuerChange { - let epins = self.board.smbus_read_byte_data(READ_COMMAND_FOR_IO_OPTO_PINS); + let epins = self + .board + .smbus_read_byte_data(READ_COMMAND_FOR_IO_OPTO_PINS); if let Err(error) = epins { return HaustuerChange::Err(format!("Board 58 with error {}", error)); } let pins = epins.unwrap(); - self.set_relay (pins).unwrap(); + self.set_relay(pins).unwrap(); if pins != 0 { return HaustuerChange::Pressed(pins); From 1de728e6ab561bb8c5d2da40c1a3a39868f95024 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 11:23:25 +0100 Subject: [PATCH 03/59] slower for debugging --- src/haustuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 9d53459..7b97a5a 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -65,7 +65,7 @@ impl Haustuer { _command_sender: Sender, _nextcloud_sender: Sender, ) -> Result { - let mut interval = interval(Duration::from_millis(10)); + let mut interval = interval(Duration::from_millis(1000)); loop { match haustuer.handle() { HaustuerChange::None => (), From f53d2cf762a85da3ad03cdda12f138f172fb2f7f Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 15:39:59 +0100 Subject: [PATCH 04/59] remove dev setup --- .../dev-setup/opensesame_dev_setup_inv.yaml | 8 -- .../dev-setup/opensesame_dev_setup_pb.yaml | 82 ------------------- ansible/dev-setup/run.sh | 6 -- 3 files changed, 96 deletions(-) delete mode 100644 ansible/dev-setup/opensesame_dev_setup_inv.yaml delete mode 100644 ansible/dev-setup/opensesame_dev_setup_pb.yaml delete mode 100755 ansible/dev-setup/run.sh diff --git a/ansible/dev-setup/opensesame_dev_setup_inv.yaml b/ansible/dev-setup/opensesame_dev_setup_inv.yaml deleted file mode 100644 index fa1f85b..0000000 --- a/ansible/dev-setup/opensesame_dev_setup_inv.yaml +++ /dev/null @@ -1,8 +0,0 @@ -all: - hosts: - 192.168.0.10 - -olimex_dev_boards: - hosts: - 192.168.0.10: - ansible_user: olimex \ No newline at end of file diff --git a/ansible/dev-setup/opensesame_dev_setup_pb.yaml b/ansible/dev-setup/opensesame_dev_setup_pb.yaml deleted file mode 100644 index cbf2276..0000000 --- a/ansible/dev-setup/opensesame_dev_setup_pb.yaml +++ /dev/null @@ -1,82 +0,0 @@ ---- -- name: Install required packages - hosts: olimex_dev_boards - gather_facts: yes - become: true - - tasks: - - name: Install build-essential - apt: - name: build-essential - state: present - - - name: Install curl - apt: - name: curl - state: present - - - name: Install rustup - become_user: olimex - shell: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.67.1 - args: - executable: /bin/bash - creates: /home/olimex/.cargo/bin/rustup - - - name: Add Rust to PATH - become_user: olimex - lineinfile: - dest: /home/olimex/.bashrc - line: 'export PATH="$HOME/.cargo/bin:$PATH"' - state: present - - - name: Install pkg-config - apt: - name: pkg-config - state: present - - - name: Install libmodbus-dev - apt: - name: libmodbus-dev - state: present - - - name: Install autoconf - apt: - name: autoconf - state: present - - - name: Install libtool - apt: - name: libtool - state: present - - - name: Install clang - apt: - name: clang - state: present - - - name: Install git - apt: - name: git - state: present - - - name: Create GitHub folder - become_user: olimex - file: - path: /home/olimex/github - state: directory - mode: '0755' - - - name: Check for existing repository - become_user: olimex - stat: - path: /home/olimex/github/opensesame - register: opensesame_folder_stat - - - name: Clone the repository - become_user: olimex - git: - repo: https://github.com/ElektraInitiative/opensesame.git - dest: /home/olimex/github/opensesame - clone: yes - when: not opensesame_folder_stat.stat.exists - diff --git a/ansible/dev-setup/run.sh b/ansible/dev-setup/run.sh deleted file mode 100755 index 8eee2ce..0000000 --- a/ansible/dev-setup/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -myplace=`dirname $0` - -ssh-add -ansible-playbook -i $myplace/opensesame_dev_setup_inv.yaml $myplace/opensesame_dev_setup_pb.yaml --ask-become-pass From 2cdbfd95e25024300ca39af84e06e1e4d7ded16d Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 15:40:18 +0100 Subject: [PATCH 05/59] 4 pins --- src/haustuer.rs | 86 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 9 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 7b97a5a..6e36b0a 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -8,8 +8,7 @@ use tokio::{sync::mpsc::Sender, time::interval}; use crate::{ buttons::CommandToButtons, config::Config, - nextcloud::NextcloudEvent, - // nextcloud::{NextcloudChat, NextcloudEvent, NextcloudStatus}, + nextcloud::{NextcloudChat, NextcloudEvent}, types::ModuleError, }; @@ -21,19 +20,32 @@ const READ_COMMAND_FOR_IO_OPTO_PINS: u8 = 0x20; pub enum HaustuerChange { None, - Pressed(u8), + LightOutdoor, + LightFarOutdoor, + BellFarOutdoor, + LightIndoor, Err(String), } pub struct Haustuer { board: LinuxI2CDevice, + + light_outdoor: bool, + light_far_outdoor: bool, + bell_far_outdoor: bool, + light_indoor: bool, } impl Haustuer { pub fn new(_config: &mut Config) -> Self { Self { board: LinuxI2CDevice::new("/dev/i2c-2", MOD_IO_I2C_ADDR).unwrap(), + + light_outdoor: false, + light_far_outdoor: false, + bell_far_outdoor: false, + light_indoor: false, } } @@ -53,8 +65,49 @@ impl Haustuer { let pins = epins.unwrap(); self.set_relay(pins).unwrap(); - if pins != 0 { - return HaustuerChange::Pressed(pins); + if pins & 1 == 1 { + if ! self.light_outdoor { + self.light_outdoor = true; + return HaustuerChange::LightOutdoor; + } + } else { + self.light_outdoor = false; + } + + if pins & 1 == 1 { + if ! self.light_outdoor { + self.light_outdoor = true; + return HaustuerChange::LightOutdoor; + } + } else { + self.light_outdoor = false; + } + + if pins & 2 == 2 { + if ! self.light_far_outdoor { + self.light_far_outdoor = true; + return HaustuerChange::LightFarOutdoor; + } + } else { + self.light_far_outdoor = false; + } + + if pins & 4 == 4 { + if ! self.bell_far_outdoor { + self.bell_far_outdoor = true; + return HaustuerChange::BellFarOutdoor; + } + } else { + self.bell_far_outdoor = false; + } + + if pins & 8 == 8 { + if ! self.light_indoor { + self.light_indoor = true; + return HaustuerChange::LightIndoor; + } + } else { + self.light_indoor = false; } HaustuerChange::None @@ -63,17 +116,32 @@ impl Haustuer { pub async fn get_background_task( mut haustuer: Haustuer, _command_sender: Sender, - _nextcloud_sender: Sender, + nextcloud_sender: Sender, ) -> Result { let mut interval = interval(Duration::from_millis(1000)); loop { match haustuer.handle() { HaustuerChange::None => (), - HaustuerChange::Pressed(epins) => { - println!("Pressed {}", epins); + HaustuerChange::LightOutdoor => { + println!("LightOutdoor Pressed"); + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Default, + String::from("🔒 LightOutdoor pressed."), + )) + .await?; + } + HaustuerChange::LightFarOutdoor => { + println!("LightFarOutdoor Pressed"); + } + HaustuerChange::BellFarOutdoor => { + println!("BellFarOutdoor Pressed"); + } + HaustuerChange::LightIndoor => { + println!("LightIndoor Pressed"); } HaustuerChange::Err(err) => { - println!("Pressed {}", err); + println!("Error {}", err); } } interval.tick().await; From c59e5a5b15002ab37033f363aac739db0575006c Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 15:45:48 +0100 Subject: [PATCH 06/59] fix formatting --- src/haustuer.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 6e36b0a..fecb8ca 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -66,7 +66,7 @@ impl Haustuer { self.set_relay(pins).unwrap(); if pins & 1 == 1 { - if ! self.light_outdoor { + if !self.light_outdoor { self.light_outdoor = true; return HaustuerChange::LightOutdoor; } @@ -75,7 +75,7 @@ impl Haustuer { } if pins & 1 == 1 { - if ! self.light_outdoor { + if !self.light_outdoor { self.light_outdoor = true; return HaustuerChange::LightOutdoor; } @@ -84,7 +84,7 @@ impl Haustuer { } if pins & 2 == 2 { - if ! self.light_far_outdoor { + if !self.light_far_outdoor { self.light_far_outdoor = true; return HaustuerChange::LightFarOutdoor; } @@ -93,7 +93,7 @@ impl Haustuer { } if pins & 4 == 4 { - if ! self.bell_far_outdoor { + if !self.bell_far_outdoor { self.bell_far_outdoor = true; return HaustuerChange::BellFarOutdoor; } @@ -102,7 +102,7 @@ impl Haustuer { } if pins & 8 == 8 { - if ! self.light_indoor { + if !self.light_indoor { self.light_indoor = true; return HaustuerChange::LightIndoor; } From 00933bd459fc8e7d91ea2bb956f952cb8a4f4064 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 12 Dec 2023 20:01:04 +0100 Subject: [PATCH 07/59] add comments, remove not needed relays --- src/haustuer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index fecb8ca..a878a91 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -20,10 +20,10 @@ const READ_COMMAND_FOR_IO_OPTO_PINS: u8 = 0x20; pub enum HaustuerChange { None, - LightOutdoor, - LightFarOutdoor, - BellFarOutdoor, - LightIndoor, + LightOutdoor, // IN1 + LightFarOutdoor, // IN2 + BellFarOutdoor, // IN3 + LightIndoor, // IN4 Err(String), } @@ -49,7 +49,7 @@ impl Haustuer { } } - fn set_relay(&mut self, which: u8) -> Result<(), LinuxI2CError> { + fn _set_relay(&mut self, which: u8) -> Result<(), LinuxI2CError> { self.board.smbus_write_byte_data(0x10, which)?; Ok(()) } @@ -63,7 +63,7 @@ impl Haustuer { } let pins = epins.unwrap(); - self.set_relay(pins).unwrap(); + // self.set_relay(pins).unwrap(); if pins & 1 == 1 { if !self.light_outdoor { From 825321d7d4926358c343e947bdca7cdfd19b64f5 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 06:45:14 +0100 Subject: [PATCH 08/59] =?UTF-8?q?first=20implementation=20of=20new=20Haust?= =?UTF-8?q?=C3=BCr=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "doc/Haust\303\274re.md" | 13 +++++-- src/buttons.rs | 3 +- src/haustuer.rs | 81 ++++++++++++++++++++++------------------ src/main.rs | 2 - 4 files changed, 56 insertions(+), 43 deletions(-) diff --git "a/doc/Haust\303\274re.md" "b/doc/Haust\303\274re.md" index b61c880..393a6fa 100644 --- "a/doc/Haust\303\274re.md" +++ "b/doc/Haust\303\274re.md" @@ -55,13 +55,18 @@ Insgesamt: 6 Mod_IO2: 6xOUT für LEDs (Mod_IO: 4xOUT mit Relay) +## Input -# sonstiger Input +- IN1 Lichttaster bei Glocke außen (orange/weiß) Taster Lampe ganz aussen (Taster unten) +- IN3 Taster Glocke ganz außen (obiger Taster) +- IN4 Taster Eingang Innen + +# Further Input -- Lichttaster bei Glocke außen (orange/weiß) orange -> GND, weiß -> Board21 GPIO0 (Taster Lampe ganz aussen) - Button Taster aussen Lampe grün/violett -> Board21 GPIO0 (Doppelbelegung!) -- Taster Eingang Innen -> Board21 GPIO2 (schwarz) -- Taster Glocke außen -> Board21 GPIO3 (braun, needs 47kΩ pull-up) +- (OLD, UNUSED) Lichttaster bei Glocke außen (orange/weiß) orange -> GND, weiß -> Board21 GPIO0 (Taster Lampe ganz aussen) +- (OLD, UNUSED) Taster Eingang Innen -> Board21 GPIO2 (schwarz) +- (OLD, UNUSED) Taster Glocke außen -> Board21 GPIO3 (braun, needs 47kΩ pull-up) Insgesamt: 9 (-1) diff --git a/src/buttons.rs b/src/buttons.rs index 73b14c3..d8ccb93 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -118,6 +118,7 @@ pub const BUTTON_LIGHT: u8 = 0x01; pub const BUTTON_BELL: u8 = 0x01 << 1; pub const TASTER_AUSSEN: u8 = BUTTON_LIGHT; +// don't exist anymore, are now in haustuer.rs pub const TASTER_INNEN: u8 = 0x01 << 2; pub const TASTER_GLOCKE: u8 = 0x01 << 3; // = GPIO3 with external pull-up @@ -588,7 +589,7 @@ impl Buttons { .send(NextcloudEvent::Chat( NextcloudChat::Licht, gettext!( - "💡 Pressed switch outside or light button. {}.", + "💡 Pressed light button. {}.", self.switch_lights(false, true), ), )) diff --git a/src/haustuer.rs b/src/haustuer.rs index a878a91..1123b01 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -16,14 +16,18 @@ const MOD_IO_I2C_ADDR: u16 = 0x58; const READ_COMMAND_FOR_IO_OPTO_PINS: u8 = 0x20; +const IN1: u8 = 0x1; +const IN3: u8 = 0x4; +const IN4: u8 = 0x8; + #[derive(PartialEq, Debug)] pub enum HaustuerChange { None, - LightOutdoor, // IN1 - LightFarOutdoor, // IN2 - BellFarOutdoor, // IN3 - LightIndoor, // IN4 + LightFarOutdoor, // IN1 + // IN2 unused + BellFarOutdoor, // IN3 + LightIndoor, // IN4 Err(String), } @@ -31,7 +35,6 @@ pub enum HaustuerChange { pub struct Haustuer { board: LinuxI2CDevice, - light_outdoor: bool, light_far_outdoor: bool, bell_far_outdoor: bool, light_indoor: bool, @@ -42,7 +45,6 @@ impl Haustuer { Self { board: LinuxI2CDevice::new("/dev/i2c-2", MOD_IO_I2C_ADDR).unwrap(), - light_outdoor: false, light_far_outdoor: false, bell_far_outdoor: false, light_indoor: false, @@ -65,25 +67,7 @@ impl Haustuer { let pins = epins.unwrap(); // self.set_relay(pins).unwrap(); - if pins & 1 == 1 { - if !self.light_outdoor { - self.light_outdoor = true; - return HaustuerChange::LightOutdoor; - } - } else { - self.light_outdoor = false; - } - - if pins & 1 == 1 { - if !self.light_outdoor { - self.light_outdoor = true; - return HaustuerChange::LightOutdoor; - } - } else { - self.light_outdoor = false; - } - - if pins & 2 == 2 { + if pins & IN1 == IN1 { if !self.light_far_outdoor { self.light_far_outdoor = true; return HaustuerChange::LightFarOutdoor; @@ -92,7 +76,9 @@ impl Haustuer { self.light_far_outdoor = false; } - if pins & 4 == 4 { + // IN2 unused + + if pins & IN3 == IN3 { if !self.bell_far_outdoor { self.bell_far_outdoor = true; return HaustuerChange::BellFarOutdoor; @@ -101,7 +87,7 @@ impl Haustuer { self.bell_far_outdoor = false; } - if pins & 8 == 8 { + if pins & IN4 == IN4 { if !self.light_indoor { self.light_indoor = true; return HaustuerChange::LightIndoor; @@ -115,30 +101,53 @@ impl Haustuer { pub async fn get_background_task( mut haustuer: Haustuer, - _command_sender: Sender, + command_sender: Sender, nextcloud_sender: Sender, ) -> Result { let mut interval = interval(Duration::from_millis(1000)); loop { match haustuer.handle() { HaustuerChange::None => (), - HaustuerChange::LightOutdoor => { - println!("LightOutdoor Pressed"); + HaustuerChange::LightFarOutdoor => { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Default, - String::from("🔒 LightOutdoor pressed."), + String::from("💡 LightFarOutdoor pressed."), + )) + .await?; + command_sender + .send(CommandToButtons::SwitchLights( + true, + false, + "💡 Pressed at entrance top switch. Switch lights".to_string(), )) .await?; - } - HaustuerChange::LightFarOutdoor => { - println!("LightFarOutdoor Pressed"); } HaustuerChange::BellFarOutdoor => { - println!("BellFarOutdoor Pressed"); + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Default, + String::from("🔒 BellFarOutdoor pressed."), + )) + .await?; + command_sender + .send(CommandToButtons::RingBell(20, 0)) + .await?; } HaustuerChange::LightIndoor => { - println!("LightIndoor Pressed"); + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Default, + String::from("🔒 LightIndoor pressed."), + )) + .await?; + command_sender + .send(CommandToButtons::SwitchLights( + true, + true, + "💡 Pressed in entrance. Switch all lights".to_string(), + )) + .await?; } HaustuerChange::Err(err) => { println!("Error {}", err); diff --git a/src/main.rs b/src/main.rs index 8700ee8..2ea5b11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,11 +86,9 @@ async fn main() -> Result<(), ModuleError> { } if haustuer_enabled { - /* TODO, allow for now if !buttons_enabled { panic!("Haustuer depends on buttons!"); } - */ tasks.push(spawn(Haustuer::get_background_task( Haustuer::new(&mut config), command_sender.clone(), From ac18db1437f54192ca05f08328d3b95385397fc8 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 08:16:17 +0100 Subject: [PATCH 09/59] small modifications in texts --- src/buttons.rs | 6 +++--- src/nextcloud.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/buttons.rs b/src/buttons.rs index d8ccb93..045b495 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -75,7 +75,7 @@ pub enum CommandToButtons { OpenDoor, RingBell(u32, u32), // maybe implement it with interval RingBellAlarm(u32), - SwitchLights(bool, bool, String), // This also need to implement the sending of a Message to nextcloud, which is now in Garage + SwitchLights(bool, bool, String), } const BELL_MINIMUM_PERIOD: u32 = 20; // = 200ms shortest period time for bell @@ -533,11 +533,11 @@ impl Buttons { CommandToButtons::RingBell(period, counter) => { self.ring_bell(period, counter); } - CommandToButtons::SwitchLights(inside, outside, _text) => { + CommandToButtons::SwitchLights(inside, outside, text) => { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Licht, - gettext!("{}", self.switch_lights(inside, outside)), + gettext!("{} {}", self.switch_lights(inside, outside), text), )) .await?; } diff --git a/src/nextcloud.rs b/src/nextcloud.rs index fcb2a01..d07eb7c 100644 --- a/src/nextcloud.rs +++ b/src/nextcloud.rs @@ -99,7 +99,7 @@ impl Nextcloud { match result { Ok(..) => (), Err(error) => { - eprintln!("Couldn't post to licht {} because {}", message, error); + eprintln!("Couldn't post to light {} because {}", message, error); } }; } @@ -325,7 +325,7 @@ impl Nextcloud { .send(CommandToButtons::SwitchLights( inner_light, outer_light, - String::from("Switch lights {} {}"), + String::from("Switch light"), )) .await?; } From c8243feb69344bd01a1dc95964435cfb40c96975 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 08:42:47 +0100 Subject: [PATCH 10/59] do_reset now in PWR module --- src/buttons.rs | 42 +++++++----------------------------------- src/main.rs | 4 +++- src/pwr.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/buttons.rs b/src/buttons.rs index 045b495..22226fa 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -14,17 +14,14 @@ use systemstat::{Platform, System}; use tokio::sync::mpsc::{Receiver, Sender}; use tokio::time::interval; -use tokio::time::sleep; use crate::audio::AudioEvent; use crate::config::Config; use crate::nextcloud::NextcloudChat; use crate::nextcloud::NextcloudEvent; -use crate::pwr::Pwr; use crate::types::ModuleError; use crate::validator::{Validation, Validator}; -use crate::watchdog; pub struct Buttons { pub sequence: Vec, @@ -306,9 +303,7 @@ impl Buttons { let epins1 = self.board20.smbus_read_byte_data(GET_PORTS); if let Err(error) = epins1 { if self.failed_counter > 3 { - self.pins1 = PINS1_INIT; - self.pins2 = PINS2_INIT; - self.init(); + self.do_reset(); return Err(format!("Board 20 with error {}", error)); } self.failed_counter += 1; @@ -318,9 +313,7 @@ impl Buttons { let epins2 = self.board21.smbus_read_byte_data(GET_PORTS); if let Err(error) = epins2 { if self.failed_counter > 3 { - self.pins1 = PINS1_INIT; - self.pins2 = PINS2_INIT; - self.init(); + self.do_reset(); return Err(format!("Board 21 with error {}", error)); } self.failed_counter += 1; @@ -485,36 +478,16 @@ impl Buttons { ret } - async fn do_reset( - nextcloud_sender: Sender, - pwr: &mut Pwr, - ) -> Result<(), ModuleError> { - if pwr.enabled() { - pwr.switch(false); - nextcloud_sender - .send(NextcloudEvent::Chat( - NextcloudChat::Ping, - gettext("👋 Turned PWR_SWITCH off"), - )) - .await?; - sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; - - pwr.switch(true); - nextcloud_sender - .send(NextcloudEvent::Chat( - NextcloudChat::Ping, - gettext("👋 Turned PWR_SWITCH on"), - )) - .await?; - sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; - } - Ok(()) + fn do_reset(&mut self) { + self.pins1 = PINS1_INIT; + self.pins2 = PINS2_INIT; + self.init(); + // communication hopefully works again } pub async fn get_background_task( mut self, mut validator: Validator, - mut pwr: Pwr, time_format: String, mut command_receiver: Receiver, nextcloud_sender: Sender, @@ -637,7 +610,6 @@ impl Buttons { nextcloud_sender .send(NextcloudEvent::Chat(NextcloudChat::Ping, gettext!("⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: {}, Swap: {}, CPU temp: {}", board, loadavg.one, loadavg.five, loadavg.fifteen, sys.memory().unwrap().total, sys.swap().unwrap().total, sys.cpu_temp().unwrap()))) .await?; - Buttons::do_reset(nextcloud_sender.clone(), &mut pwr).await?; } } // Validation start diff --git a/src/main.rs b/src/main.rs index 2ea5b11..84537c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,9 @@ async fn main() -> Result<(), ModuleError> { startup_time.to_string(), ))); + let mut pwr = Pwr::new(&mut config); + let _ = pwr.do_reset(nextcloud_sender.clone()).await; + if garage_enabled { if !buttons_enabled { panic!("Garage depends on buttons!"); @@ -103,7 +106,6 @@ async fn main() -> Result<(), ModuleError> { tasks.push(spawn(Buttons::get_background_task( Buttons::new(&mut config), Validator::new(&mut config), - Pwr::new(&mut config), time_format.to_string(), command_receiver, nextcloud_sender.clone(), diff --git a/src/pwr.rs b/src/pwr.rs index e1e8ea7..2f42d01 100644 --- a/src/pwr.rs +++ b/src/pwr.rs @@ -1,6 +1,16 @@ use gpio_cdev::{Chip, LineHandle, LineRequestFlags}; +use systemstat::Duration; +use tokio::sync::mpsc::Sender; +use tokio::time::sleep; + +use crate::nextcloud::NextcloudChat; +use crate::nextcloud::NextcloudEvent; +use gettextrs::gettext; + use crate::config::Config; +use crate::types::ModuleError; +use crate::watchdog; const GPIO_PWR_LINE: u32 = 202; @@ -50,4 +60,30 @@ impl Pwr { } self.state = state; } + + pub async fn do_reset( + &mut self, + nextcloud_sender: Sender, + ) -> Result<(), ModuleError> { + if self.enabled() { + self.switch(false); + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Ping, + gettext("👋 Turned PWR_SWITCH off"), + )) + .await?; + sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; + + self.switch(true); + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Ping, + gettext("👋 Turned PWR_SWITCH on"), + )) + .await?; + sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; + } + Ok(()) + } } From 22daf94115e09e5d108396670dc7d3c794d8b839 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 09:10:58 +0100 Subject: [PATCH 11/59] various docu updates --- README.md | 6 +++--- doc/Audio.md | 3 ++- doc/Benchmark.md | 8 -------- doc/DevelopmentSetup.md | 1 + doc/Environment.md | 3 ++- doc/I2C.md | 1 + doc/Install.md | 4 +++- doc/ModIR.md | 3 ++- doc/Modules_Overview.md | 3 ++- doc/Nextcloud.md | 3 ++- doc/Opensensemap.md | 3 ++- doc/Ping.md | 3 ++- doc/SUMMARY.md | 22 +++++++++++++--------- doc/Signals.md | 3 ++- doc/Testreport_Async_Refactor.md | 3 ++- doc/Translations.md | 3 ++- doc/Types.md | 3 ++- doc/libmodbus-troubles.md | 3 ++- 18 files changed, 45 insertions(+), 33 deletions(-) delete mode 100644 doc/Benchmark.md diff --git a/README.md b/README.md index 5bd1a8b..86b7a45 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,12 @@ For what is missing, see [TODO.md](TODO.md). ## Disclaimer -Currently there is no full beginner-friendly documentation on how to setup the system. +Currently there is no complete beginner-friendly documentation on how to setup the system. If you are interested, please open an issue. [Installation](/doc/Install.md) is not difficult, though. As hardware hacking is involved I cannot guarantee that anything will work for you. -It works for me, though. +It works for me and worked for someone else, too. ## Quality Goals @@ -46,7 +46,7 @@ On each Olimex, the same software runs but differently configured using Elektra. E.g. to set a new PIN 1234 for "us": -kdb set user:/sw/libelektra/opensesame/#0/current/validator/us "[14, 15, 13, 15, 11, 15, 7, 15]" +`kdb set user:/sw/libelektra/opensesame/#0/current/validator/us "[14, 15, 13, 15, 11, 15, 7, 15]"` Deployment is done via Ansible, see [an example](/ansible/playbook.yaml). diff --git a/doc/Audio.md b/doc/Audio.md index 6bc8fa2..9b04333 100644 --- a/doc/Audio.md +++ b/doc/Audio.md @@ -1,3 +1,4 @@ # Audio Module + This module handles audio output for playing fire alarms and bell sounds. -This module can receive commands from the Module Buttons (Bell), Environment (FireAlarm), Nextcloud (FireAlarm, Bell), and Signals (FireAlarm, Bell). \ No newline at end of file +This module can receive commands from the Module Buttons (Bell), Environment (FireAlarm), Nextcloud (FireAlarm, Bell), and Signals (FireAlarm, Bell). diff --git a/doc/Benchmark.md b/doc/Benchmark.md deleted file mode 100644 index 7cbb481..0000000 --- a/doc/Benchmark.md +++ /dev/null @@ -1,8 +0,0 @@ -# Benchmark - -## with opensesame v0.6.2 - -sensors: ~100ms per iteration (854ms first iteration) -haustuer: ~46ms per iteration (695ms first iteration) -garage: ~46ms per iteration (710ms first iteration, 2620ms while compiling) - diff --git a/doc/DevelopmentSetup.md b/doc/DevelopmentSetup.md index a048e5b..293260a 100644 --- a/doc/DevelopmentSetup.md +++ b/doc/DevelopmentSetup.md @@ -1,4 +1,5 @@ # Development Setup + For the development setup you have to do some steps manually, so this page should help you to get your development environment ready to use. ## 1. Clone the project on you local development environment diff --git a/doc/Environment.md b/doc/Environment.md index 0948889..1fffbc6 100644 --- a/doc/Environment.md +++ b/doc/Environment.md @@ -1,4 +1,5 @@ # Environment sensors + ## MOD-BME280 ### Setup and Wiring @@ -18,4 +19,4 @@ These pins are the same as those used for UEXT1 on the [LIME2-SHIELD](https://ww The following command reads the status register as a test: ```bash /sbin/i2cget 2 0x77 0xF3 -``` \ No newline at end of file +``` diff --git a/doc/I2C.md b/doc/I2C.md index 9f8e2f7..552afab 100644 --- a/doc/I2C.md +++ b/doc/I2C.md @@ -2,6 +2,7 @@ - larger AC loads (>>10W) might need snubber circuits - larger DC loads might need a diode +- inputs that are somehow near AC/DC loads must be via opto-coppling (Mod_IO) - avoid switching relays faster than every ~200ms - avoid snubber parallel to switch on small loads - avoid multiple appliances that might create interferences on the same board (i.e. connect larger loads to different mod-io2) diff --git a/doc/Install.md b/doc/Install.md index 5db765a..d698905 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -1,6 +1,8 @@ # boot with A20-Debian-Server-SD + # latest A20-Debian-Server-SD images at: -# http://images.olimex.com/release/a20/ + +http://images.olimex.com/release/a20/ ``` bash $ wget https://images.olimex.com/release/a20/A20-OLinuXino-bullseye-minimal-20230515-130040.img.7z diff --git a/doc/ModIR.md b/doc/ModIR.md index bd7051f..02eac8e 100644 --- a/doc/ModIR.md +++ b/doc/ModIR.md @@ -1,4 +1,5 @@ # [MOD-IR-TEMP](https://www.olimex.com/Products/Modules/Sensors/MOD-IR-TEMP/open-source-hardware) Module Description + ## Setup and Wiring The setup and wiring instructions are the same as those provided in the [Environment-documentation](./Environment.md) @@ -11,4 +12,4 @@ You can configure the sensor by running the following commands: kdb set user:/sw/libelektra/opensesame/#0/current/ir/enable 1 kdb set user:/sw/libelektra/opensesame/#0/current/ir/device "/dev/ic2-2" kdb set user:/sw/libelektra/opensesame/#0/current/ir/data/interval 60 -``` \ No newline at end of file +``` diff --git a/doc/Modules_Overview.md b/doc/Modules_Overview.md index 0d491c8..98c4528 100644 --- a/doc/Modules_Overview.md +++ b/doc/Modules_Overview.md @@ -1,2 +1,3 @@ # Modules Overview -![information_flow](images/information_flow_v0.8.0.png) \ No newline at end of file + +![information_flow](images/information_flow_v0.8.0.png) diff --git a/doc/Nextcloud.md b/doc/Nextcloud.md index 812b0a4..88896a1 100644 --- a/doc/Nextcloud.md +++ b/doc/Nextcloud.md @@ -1,3 +1,4 @@ # Nextcloud Module + Implements two loops: one for sending (`message_sender_loop`) messages and status to Nextcloud, and the other for receiving (`command_loop`) messages/commands from Nextcloud. -Commands can be sent via Nextcloud chat by typing "\opensesame" to open the door, or other commands like "\ring_bell", "\fire_alarm", "\status", and "\switchlights true true". \ No newline at end of file +Commands can be sent via Nextcloud chat by typing "\opensesame" to open the door, or other commands like "\ring_bell", "\fire_alarm", "\status", and "\switchlights true true". diff --git a/doc/Opensensemap.md b/doc/Opensensemap.md index 10dda4b..b800630 100644 --- a/doc/Opensensemap.md +++ b/doc/Opensensemap.md @@ -1,4 +1,5 @@ # Opensensemap + After you've setup your account and logged in on [opensensemap.org](https://www.opensensemap.org/), you need to do following steps: ## 1. Adding a senseBox @@ -71,4 +72,4 @@ sensors."#0".loc = "Weatherstation" Set an environment name using the command: ```bash kdb set user:/sw/libelektra/opensesame/#0/current/environment/name "" -``` \ No newline at end of file +``` diff --git a/doc/Ping.md b/doc/Ping.md index a545f06..d66deb5 100644 --- a/doc/Ping.md +++ b/doc/Ping.md @@ -1,4 +1,5 @@ # Ping Module + This module sends a ping message to Nextcloud if it receives the `SendPing` event. Other functions update `Env`, `EnvStatus`, `EnvError`, and `BatCapacity`, but these commands aren't used yet. -They need to be triggered at the right spot in Environment and Battery to keep the ping up to date. \ No newline at end of file +They need to be triggered at the right spot in Environment and Battery to keep the ping up to date. diff --git a/doc/SUMMARY.md b/doc/SUMMARY.md index fd62bff..8a40bba 100644 --- a/doc/SUMMARY.md +++ b/doc/SUMMARY.md @@ -10,7 +10,6 @@ - [Translations](Translations.md) - [Benchmark](Benchmark.md) - [Debugging](Debugging.md) -- [Troubles libmodbus](libmodbus-troubles.md) - [Troubleshooting](Troubleshooting.md) # Using @@ -18,25 +17,30 @@ - [Ansible](Ansible.md) - [Installation](Install.md) -# Modules -- [Modules Overview](Modules_Overview.md) -- [GPIO](GPIO.md) +# HW-Hacking + - [I2C](I2C.md) +- [Troubles libmodbus](libmodbus-troubles.md) - [MQ135](MQ135.md) +- [GPIO](GPIO.md) +- [Energy](Energy.md) + +# Modules + +- [Modules Overview](Modules_Overview.md) +- [Nextcloud](Nextcloud.md) +- [Ping](Ping.md) +- [Signals](Signals.md) +- [Error-Types](Types.md) - [Garage](Garage.md) - [Environment](Environment.md) - [Front door](Haustüre.md) - [Weather station](thiesclima-weatherstation.md) - [Opensensemap](Opensensemap.md) - [Inverter](goodwe-inverter.md) -- [Energy](Energy.md) - [Audio](Audio.md) - [Battery](Battery.md) - [IR-Temp](ModIR.md) -- [Nextcloud](Nextcloud.md) -- [Ping](Ping.md) -- [Signals](Signals.md) -- [Error-Types](Types.md) - [Watchdog](Watchdog.md) diff --git a/doc/Signals.md b/doc/Signals.md index 358bdf9..26dd412 100644 --- a/doc/Signals.md +++ b/doc/Signals.md @@ -1,2 +1,3 @@ # Signal Module -This module listens to system signals and executes the same events as in the old version. \ No newline at end of file + +This module listens to system signals and executes the same events as in the old version. diff --git a/doc/Testreport_Async_Refactor.md b/doc/Testreport_Async_Refactor.md index ac1d6c5..0d76d10 100644 --- a/doc/Testreport_Async_Refactor.md +++ b/doc/Testreport_Async_Refactor.md @@ -1,4 +1,5 @@ # Testing Async + This is the testreport of the async refactor of opensesame. (`-`) means that the test failed, (`~`) something went wrong but it works and (`+`) means that everything went as expected. Here is a list of the modules which need to be tested. 1. **Signals** @@ -476,4 +477,4 @@ done | ---------------- | ---------- | | Reboot | `+` | - \ No newline at end of file + diff --git a/doc/Translations.md b/doc/Translations.md index 112f25f..a592ce3 100644 --- a/doc/Translations.md +++ b/doc/Translations.md @@ -1,4 +1,5 @@ # Get Translation Strings + ```bash cargo install xtr ~/.cargo/bin/xtr src/lib.rs -o lang/opensesame.pot @@ -15,4 +16,4 @@ msgmerge -U lang/de_AT.po lang/opensesame.pot ```bash msgfmt lang/de_AT.po mv messages.mo files/opensesame.mo -``` \ No newline at end of file +``` diff --git a/doc/Types.md b/doc/Types.md index 3a619ef..84cd8f7 100644 --- a/doc/Types.md +++ b/doc/Types.md @@ -1,2 +1,3 @@ # Types Module -This module contains the error types defined so far. \ No newline at end of file + +This module contains the error types defined so far. diff --git a/doc/libmodbus-troubles.md b/doc/libmodbus-troubles.md index 58b5efb..956dc79 100644 --- a/doc/libmodbus-troubles.md +++ b/doc/libmodbus-troubles.md @@ -1,4 +1,5 @@ # libmodbus Trouble Protocol + The documentation of the libmodbus library can be found on [this website](https://libmodbus.org/reference/). This brief troubleshooting protocol contains essential information required for communicating with a modbus device. It also includes details about the challenges we encountered during our programming journey. @@ -40,4 +41,4 @@ To solve this issue we had to use the right address, which is configured on the ### Solve To solve this issue we had to use the right function (`0x01`, `0x02`, ...) for the chosen register. -The function for any register is in the documentation of the [weatherstation](https://www.vetterag.ch/images/pdf/thies/BA/4.920x.x0.xxx_ClimaSensor_US_d.pdf) or [inverter](https://loxwiki.atlassian.net/wiki/spaces/LOX/pages/1605274474/Goodwe+GW10+ET+MODBUS+TCP+IP?preview=/1605274474/1605274552/Goodwe_Modbus_Protocol_Hybrid_ET_EH_BH_BT__ARM205%20HV__V1.7%20_%20Read%20Only_20200226%20(1).pdf). \ No newline at end of file +The function for any register is in the documentation of the [weatherstation](https://www.vetterag.ch/images/pdf/thies/BA/4.920x.x0.xxx_ClimaSensor_US_d.pdf) or [inverter](https://loxwiki.atlassian.net/wiki/spaces/LOX/pages/1605274474/Goodwe+GW10+ET+MODBUS+TCP+IP?preview=/1605274474/1605274552/Goodwe_Modbus_Protocol_Hybrid_ET_EH_BH_BT__ARM205%20HV__V1.7%20_%20Read%20Only_20200226%20(1).pdf). From 0b65b5f0913d4cc02ca8ba0a4d88571febe6dbf5 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 09:25:02 +0100 Subject: [PATCH 12/59] small translation fixes+updates --- files/opensesame.mo | Bin 5801 -> 5914 bytes lang/de_AT.po | 61 ++++++++++++++++++++++++-------------------- lang/opensesame.pot | 50 ++++++++++++++++++------------------ src/haustuer.rs | 2 +- src/pwr.rs | 4 +-- 5 files changed, 61 insertions(+), 56 deletions(-) diff --git a/files/opensesame.mo b/files/opensesame.mo index aed1082389ab23a247bf293c4b501bc2a49cd000..09ad8a89f16753c756b70a998f0a3f10d788568f 100644 GIT binary patch delta 1220 zcmZA0Ur19?9KiA4+B7Y*IV;Poj+JFJr(#N^Vt*COOw9f%LCf9rR?fO^W?Aed2(rky z&_fhKFH-bi?75c+D#C{dB6_H(poqX;q6mV%zqus3?Cx`aXXl)Ie&=^~r|f!Yv@Q`B zkrAIr5Iq?p3o(R6*n}k*!J~LF9e>Aq;>DRFoACf@d;{C@HP&L;Opyk(u?FwpI(&!Q zaekI0q>zV0S(0)X7ZG2>avaABe1}UhFI!|8R$wuv}umg2L$1sF9uo9nPKK@3XI4?(J4X#9* zq!oueBAux7zL+DzM+y_UBD6^<4r4Wz;e9N?x2T!@KwVg1F4ef$S3;O*c&3F*C zeGCuamvp=}Ph=zU1>As7a6KlxEVrG9I@A|kLEY-RX`f;h@n_TlMWne3_n^VExE61s z?$lFUfuC?W&YmZ-8bhc%u@|*;hmrmXIiGI0jas8esF}XOUASt#NEioE2fjir#V@SD zJc26RjMX@Z2Jaysncz!H@ey?axooQkr!GCFTpZ|B)}^TR$x+{PPkp0fS!e8MkLj@bPFPMj7I!Q&e9k-^-x4&ZZR>c%*aOCn znn*a>V>zaDpB;^8hraTGHOa2bNl%FxIAzDWd(E!KM)`K@>WJxxJ5eiQ+V-_i|J3UC zXZ5@O>;m^?mPxM8e(!TfeYMG^+;5((P1X^|wwx33=&_iI_od%%;?bDp40QK8b}VK^ zgJzpUgRX@B;okpOQt8i`vG(ulHtpGMdMw6?QU9!FTXU;%j|9$Tw%Fahu`<`6 PU+jJe6elb5hrE9PdziH= delta 1108 zcmYk*Ur19?9KiA4byw%i{I|+KrQKOplFpVbBD12RKUNgZ(m<+_(~R13bD>0xUV;>* zxK9a^2|fft535Imo`MKOsKV&dNgT%pG;>8NFo5f@4ePKEui#iV{)w%`HF+7kv7LAVTkt#X!+N*KPVC1WIE8Ka z&Mhga;>OAs#}=$4K8sCw9k<~WuE+Uoyo5gDT2E&DA=G)!qmCQKjragp;0x4wUuXS{ zWyHTdDUr3@lop5_$3{GY!+029Vm0P7%NpE-x}a9{V-y28iC&yTo%j>h;}7H`R-wp{ z!S15YJF`-Rk9S_*fO$W1K3M!bXN_zX3}H>eBzf^lpr7CC^^cmfx)@%9pt zbHqv1=X1Cp%SuIdV+eO)YMdLb*(=l^sABn=aWHELn~4WdUzkA)KVSp?!L8Up`ubiM zZonH@ixapRXHj=z0kw2X$oQ0aS7p8kpw=jan&CA(h0igJxvMkd`cO-87qt{q*o^ZS z)NwqtumyEoHy15M0(AkCXke!4F{N=(rG~zR9-wnRgdKBAqgiRK^dF&_y67Bysj>%L z<@#$gJG~HJ>z0&rXUZd6y znqBD;^R1D7l=s!ByAbL;)^YHt73=Ml#fSGtt&U_o8tJi4ceXD-irP=}V|J^j!VY?h z3u4K^M1N1jipA|}PeuBS=c8$ln0wRlqD3S9q$Dq={@;t?WTG#UxO6#ububdm%>LiB hk^ZRtzU-EL+v_Xr2qy+3aVyrt#lGnErKi0^uD_eIjV%BG diff --git a/lang/de_AT.po b/lang/de_AT.po index d83c7d6..e9d9410 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-05 08:57+0000\n" +"POT-Creation-Date: 2023-12-14 08:22+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -47,47 +47,39 @@ msgstr "🔋 An {}%" msgid "🔋 Battery Capacity is back to {}%" msgstr "🔋 Batterieladung ist zurück bei {}%" -#: src/buttons.rs:496 -msgid "👋 Turned PWR_SWITCH off" -msgstr "👋 PWR_SWITCH ausgeschalten" - -#: src/buttons.rs:505 -msgid "👋 Turned PWR_SWITCH on" -msgstr "👋 PWR_SWITCH eingeschalten" - -#: src/buttons.rs:539 -msgid "{}" -msgstr "{}" +#: src/buttons.rs:513 +msgid "{} {}" +msgstr "" -#: src/buttons.rs:559 +#: src/buttons.rs:533 msgid "🔔 Pressed button bell." msgstr "🔔 Knopf für Glocke gedrückt." -#: src/buttons.rs:568 +#: src/buttons.rs:542 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Knopf gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:580 +#: src/buttons.rs:554 msgid "💡 Pressed switch inside. {}." msgstr "💡 Taster innen gedrückt. {}." -#: src/buttons.rs:591 -msgid "💡 Pressed switch outside or light button. {}." -msgstr "💡 Taster oder Knopf außen gedrückt. {}." +#: src/buttons.rs:565 +msgid "💡 Pressed light button. {}." +msgstr "💡 Licht-Knopf außen gedrückt. {}." -#: src/buttons.rs:604 +#: src/buttons.rs:578 msgid "🔔 Pressed switch bell." msgstr "🔔 Taster Glocke gedrückt." -#: src/buttons.rs:613 +#: src/buttons.rs:587 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Taster außen gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:627 +#: src/buttons.rs:601 msgid "🕶️ Light was turned off." msgstr "🕶️ Licht wurde abgeschalten." -#: src/buttons.rs:637 +#: src/buttons.rs:611 msgid "" "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: " "{}, Swap: {}, CPU temp: {}" @@ -95,25 +87,25 @@ msgstr "" "⚠️ Fehler beim Lesen der Knöpfe am Board {}. Load average: {} {} {}, Memory " "usage: {}, Swap: {}, CPU temp: {}" -#: src/buttons.rs:650 +#: src/buttons.rs:623 msgid "🤗 Opened for {}" msgstr "🤗 Für {} geöffnet" -#: src/buttons.rs:666 +#: src/buttons.rs:639 msgid "💡 Switch lights in and out. {}" msgstr "💡 Schalte Licht innen und außen ein. {}" -#: src/buttons.rs:676 +#: src/buttons.rs:649 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" "🕶️ Schalte Lichter nicht ein, da es Tag ist. Jetzt: {} Sonnenaufgang: {} " "Sonnenuntergang: {}" -#: src/buttons.rs:692 +#: src/buttons.rs:665 msgid "⌛ Timeout with sequence {}" msgstr "⌛ Timeout mit Sequenz {}" -#: src/buttons.rs:703 +#: src/buttons.rs:676 msgid "⌛ Sequence {} too long" msgstr "⌛ Zu lange Sequenz {}" @@ -126,7 +118,6 @@ msgid "🌡️ Heat Alert {} °C, turn on PV cooling (Wind {} m/s)" msgstr "🌡️ Hitzewarnung {} °C, PV Kühlung einschalten (Wind {} m/s)" #: src/clima_sensor_us.rs:317 -#, fuzzy msgid "🌡 Freezing Temperature {} °C, yield is in danger (Wind {} m/s)" msgstr "🌡 Gefrierpunkt um {} °C unterschritten, Ernte in Gefahr (Wind {} m/s)" @@ -202,6 +193,14 @@ msgstr "" "{} Ping! Version {}, {}, Status {}, Error {}, Load {} {} {}, " "Speicherauslastung {}, Swap {}, CPU temp {}, Startup {} Bat {}" +#: src/pwr.rs:73 +msgid "👋 Turned PWR switch OFF" +msgstr "👋 PWR switch AUS geschalten" + +#: src/pwr.rs:82 +msgid "👋 Turned PWR switch ON" +msgstr "👋 PWR switch EIN geschalten" + #: src/sensors.rs:273 msgid "Fire Alarm {}" msgstr "Feueralarm {}" @@ -230,5 +229,11 @@ msgstr "🚨 Befehl für Alarm empfangen" msgid "🔔 Received bell" msgstr "🔔 Befehl für Glocke empfangen" +#~ msgid "👋 Turned PWR_SWITCH off" +#~ msgstr "👋 PWR_SWITCH ausgeschalten" + +#~ msgid "{}" +#~ msgstr "{}" + #~ msgid "{}. {}" #~ msgstr "{}. {}" diff --git a/lang/opensesame.pot b/lang/opensesame.pot index 5314b7d..258a4e6 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-05 08:57+0000\n" +"POT-Creation-Date: 2023-12-14 08:22+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -45,67 +45,59 @@ msgstr "" msgid "🔋 Battery Capacity is back to {}%" msgstr "" -#: src/buttons.rs:496 -msgid "👋 Turned PWR_SWITCH off" +#: src/buttons.rs:513 +msgid "{} {}" msgstr "" -#: src/buttons.rs:505 -msgid "👋 Turned PWR_SWITCH on" -msgstr "" - -#: src/buttons.rs:539 -msgid "{}" -msgstr "" - -#: src/buttons.rs:559 +#: src/buttons.rs:533 msgid "🔔 Pressed button bell." msgstr "" -#: src/buttons.rs:568 +#: src/buttons.rs:542 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:580 +#: src/buttons.rs:554 msgid "💡 Pressed switch inside. {}." msgstr "" -#: src/buttons.rs:591 -msgid "💡 Pressed switch outside or light button. {}." +#: src/buttons.rs:565 +msgid "💡 Pressed light button. {}." msgstr "" -#: src/buttons.rs:604 +#: src/buttons.rs:578 msgid "🔔 Pressed switch bell." msgstr "" -#: src/buttons.rs:613 +#: src/buttons.rs:587 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:627 +#: src/buttons.rs:601 msgid "🕶️ Light was turned off." msgstr "" -#: src/buttons.rs:637 +#: src/buttons.rs:611 msgid "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: {}, Swap: {}, CPU temp: {}" msgstr "" -#: src/buttons.rs:650 +#: src/buttons.rs:623 msgid "🤗 Opened for {}" msgstr "" -#: src/buttons.rs:666 +#: src/buttons.rs:639 msgid "💡 Switch lights in and out. {}" msgstr "" -#: src/buttons.rs:676 +#: src/buttons.rs:649 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" -#: src/buttons.rs:692 +#: src/buttons.rs:665 msgid "⌛ Timeout with sequence {}" msgstr "" -#: src/buttons.rs:703 +#: src/buttons.rs:676 msgid "⌛ Sequence {} too long" msgstr "" @@ -185,6 +177,14 @@ msgstr "" msgid "{} Ping! Version {}, {}, Status {}, Error {}, Load {} {} {}, Memory usage {}, Swap {}, CPU temp {}, Startup {} Bat {}" msgstr "" +#: src/pwr.rs:73 +msgid "👋 Turned PWR switch OFF" +msgstr "" + +#: src/pwr.rs:82 +msgid "👋 Turned PWR switch ON" +msgstr "" + #: src/sensors.rs:273 msgid "Fire Alarm {}" msgstr "" diff --git a/src/haustuer.rs b/src/haustuer.rs index 1123b01..b4d29ef 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -150,7 +150,7 @@ impl Haustuer { .await?; } HaustuerChange::Err(err) => { - println!("Error {}", err); + println!("Error on {}", err); } } interval.tick().await; diff --git a/src/pwr.rs b/src/pwr.rs index 2f42d01..948e170 100644 --- a/src/pwr.rs +++ b/src/pwr.rs @@ -70,7 +70,7 @@ impl Pwr { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Ping, - gettext("👋 Turned PWR_SWITCH off"), + gettext("👋 Turned PWR switch OFF"), )) .await?; sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; @@ -79,7 +79,7 @@ impl Pwr { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Ping, - gettext("👋 Turned PWR_SWITCH on"), + gettext("👋 Turned PWR switch ON"), )) .await?; sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; From d0ac4c6379e66a36440fb8399769c61eca08c75d Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 09:44:36 +0100 Subject: [PATCH 13/59] =?UTF-8?q?add=20haust=C3=BCr+pwr=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 84537c6..69cb397 100644 --- a/src/main.rs +++ b/src/main.rs @@ -241,9 +241,11 @@ async fn main() -> Result<(), ModuleError> { nextcloud_sender.send( NextcloudEvent::Chat(NextcloudChat::Ping, - gettext!("Enabled Modules: \nButtons: {},\n Garage: {},\n Sensors: {},\n ModIR: {},\n Environment: {},\n Weatherstation: {},\n Battery: {},\n Watchdog: {},\n Ping: {}\n", + gettext!("Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", buttons_enabled, garage_enabled, + haustuer_enabled, + pwr.enabled(), sensors_enabled, modir_enabled, env_enabled, From b895bce6e11f5b73ff6aae30adf11146576f93ad Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 10:13:10 +0100 Subject: [PATCH 14/59] change start/end msg at startup --- src/main.rs | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 69cb397..ad45e01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,26 @@ async fn main() -> Result<(), ModuleError> { let watchdog_enabled = config.get_bool("watchdog/enable"); let ping_enabled = config.get_bool("ping/enable"); + let mut pwr = Pwr::new(&mut config); + + nextcloud_sender.send( + NextcloudEvent::Chat(NextcloudChat::Ping, + gettext!("Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", + buttons_enabled, + garage_enabled, + haustuer_enabled, + pwr.enabled(), + sensors_enabled, + modir_enabled, + env_enabled, + weatherstation_enabled, + bat_enabled, + watchdog_enabled, + ping_enabled, +))).await?; + + let _ = pwr.do_reset(nextcloud_sender.clone()).await; + let mut tasks = vec![]; tasks.push(spawn(Nextcloud::get_background_task( @@ -74,9 +94,6 @@ async fn main() -> Result<(), ModuleError> { startup_time.to_string(), ))); - let mut pwr = Pwr::new(&mut config); - let _ = pwr.do_reset(nextcloud_sender.clone()).await; - if garage_enabled { if !buttons_enabled { panic!("Garage depends on buttons!"); @@ -239,21 +256,12 @@ async fn main() -> Result<(), ModuleError> { tasks.push(spawn(signals.get_background_task())); - nextcloud_sender.send( - NextcloudEvent::Chat(NextcloudChat::Ping, - gettext!("Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", - buttons_enabled, - garage_enabled, - haustuer_enabled, - pwr.enabled(), - sensors_enabled, - modir_enabled, - env_enabled, - weatherstation_enabled, - bat_enabled, - watchdog_enabled, - ping_enabled, -))).await?; + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Ping, + gettext!("⚠️ Startup Complete"), + )) + .await?; join_all(tasks).await; Ok(()) From 08499d814a1f0241c2f04219db1590d20452ecda Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 11:24:12 +0100 Subject: [PATCH 15/59] fix clippy error --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ad45e01..737cd1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,7 +259,7 @@ async fn main() -> Result<(), ModuleError> { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Ping, - gettext!("⚠️ Startup Complete"), + gettext("⚠️ Startup Complete"), )) .await?; From b8eb71145c366a0378d6436cd5448f2030d16304 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 11:24:40 +0100 Subject: [PATCH 16/59] fix to production time --- src/haustuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index b4d29ef..d7f7224 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -104,7 +104,7 @@ impl Haustuer { command_sender: Sender, nextcloud_sender: Sender, ) -> Result { - let mut interval = interval(Duration::from_millis(1000)); + let mut interval = interval(Duration::from_millis(10)); loop { match haustuer.handle() { HaustuerChange::None => (), From 1339bd46d989db577fdec741438d6dfc5f53a213 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 11:35:17 +0100 Subject: [PATCH 17/59] add set_hook to readd later --- src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.rs b/src/main.rs index 737cd1f..6069e35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,34 @@ async fn main() -> Result<(), ModuleError> { ping_enabled, ))).await?; + // use std::ops::Deref; + // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log + // // Alternative: https://github.com/sfackler/rust-log-panics + // panic::set_hook(Box::new(|panic_info| { + // let (filename, line) = panic_info + // .location() + // .map(|loc| (loc.file(), loc.line())) + // .unwrap_or(("", 0)); + // let cause = panic_info + // .payload() + // .downcast_ref::() + // .map(String::deref); + // let cause = cause.unwrap_or_else(|| { + // panic_info + // .payload() + // .downcast_ref::<&str>() + // .map(|s| *s) + // .unwrap_or("") + // }); + // let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); + // nextcloud_sender // <--- Doesn't live long enough + // .send(NextcloudEvent::Chat( + // NextcloudChat::Ping, + // text.clone(), + // )); + // eprintln!("{}", text); + // })); + let _ = pwr.do_reset(nextcloud_sender.clone()).await; let mut tasks = vec![]; From 2190e2c20b3e8cf7f0c6d3425098bb83ea89aa37 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 13:28:56 +0100 Subject: [PATCH 18/59] small changes in msg --- src/main.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6069e35..44db265 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,7 @@ async fn main() -> Result<(), ModuleError> { nextcloud_sender.send( NextcloudEvent::Chat(NextcloudChat::Ping, - gettext!("Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", + gettext!("👋 Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", buttons_enabled, garage_enabled, haustuer_enabled, @@ -83,7 +83,6 @@ async fn main() -> Result<(), ModuleError> { // use std::ops::Deref; // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log - // // Alternative: https://github.com/sfackler/rust-log-panics // panic::set_hook(Box::new(|panic_info| { // let (filename, line) = panic_info // .location() @@ -124,7 +123,7 @@ async fn main() -> Result<(), ModuleError> { if garage_enabled { if !buttons_enabled { - panic!("Garage depends on buttons!"); + panic!("⚠️ Garage depends on buttons!"); } tasks.push(spawn(Garage::get_background_task( Garage::new(&mut config), @@ -135,7 +134,7 @@ async fn main() -> Result<(), ModuleError> { if haustuer_enabled { if !buttons_enabled { - panic!("Haustuer depends on buttons!"); + panic!("⚠️ Haustuer depends on buttons!"); } tasks.push(spawn(Haustuer::get_background_task( Haustuer::new(&mut config), @@ -287,7 +286,7 @@ async fn main() -> Result<(), ModuleError> { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Ping, - gettext("⚠️ Startup Complete"), + gettext("👋Startup Complete"), )) .await?; From 5008d84da3eb3f197fb524a14a8c568e2201d9ed Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 15:22:41 +0100 Subject: [PATCH 19/59] reduce interval --- src/haustuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index d7f7224..f2fe99a 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -104,7 +104,7 @@ impl Haustuer { command_sender: Sender, nextcloud_sender: Sender, ) -> Result { - let mut interval = interval(Duration::from_millis(10)); + let mut interval = interval(Duration::from_millis(30)); loop { match haustuer.handle() { HaustuerChange::None => (), From 8a2cc3bde2b540a3a8e5ad77e083857df03656ca Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 15:28:58 +0100 Subject: [PATCH 20/59] check if sleep helps from recovering from error --- src/haustuer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index f2fe99a..691a9b6 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -3,7 +3,7 @@ use i2cdev::core::*; use i2cdev::linux::LinuxI2CDevice; use i2cdev::linux::LinuxI2CError; use systemstat::Duration; -use tokio::{sync::mpsc::Sender, time::interval}; +use tokio::{sync::mpsc::Sender, time::interval, time::sleep}; use crate::{ buttons::CommandToButtons, @@ -151,6 +151,7 @@ impl Haustuer { } HaustuerChange::Err(err) => { println!("Error on {}", err); + sleep(Duration::from_millis(1000)).await; } } interval.tick().await; From 7b3fd8f142fdd4c962624d22ee7a46f1ee01b0f5 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 15:42:44 +0100 Subject: [PATCH 21/59] switch lights (should be out instead of in) --- src/haustuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 691a9b6..cc909fd 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -117,8 +117,8 @@ impl Haustuer { .await?; command_sender .send(CommandToButtons::SwitchLights( - true, false, + true, "💡 Pressed at entrance top switch. Switch lights".to_string(), )) .await?; From e7df939d37b2c461a523d0ba953bc4d6677b8619 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 15:46:20 +0100 Subject: [PATCH 22/59] different ringing --- src/haustuer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index cc909fd..ddb8ae4 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -131,7 +131,7 @@ impl Haustuer { )) .await?; command_sender - .send(CommandToButtons::RingBell(20, 0)) + .send(CommandToButtons::RingBell(5, 5)) .await?; } HaustuerChange::LightIndoor => { From 18719c70862e002f522fa2e3ada31b4a384fbad0 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Thu, 14 Dec 2023 17:42:03 +0100 Subject: [PATCH 23/59] TEST: don't do anything when press indoor --- src/haustuer.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/haustuer.rs b/src/haustuer.rs index ddb8ae4..cd98f39 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -141,6 +141,7 @@ impl Haustuer { String::from("🔒 LightIndoor pressed."), )) .await?; + /* command_sender .send(CommandToButtons::SwitchLights( true, @@ -148,6 +149,7 @@ impl Haustuer { "💡 Pressed in entrance. Switch all lights".to_string(), )) .await?; + */ } HaustuerChange::Err(err) => { println!("Error on {}", err); From 644f88062e6e4342636c70bcb84ecc9a7b10c17e Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 08:12:07 +0100 Subject: [PATCH 24/59] NC msg on error --- src/haustuer.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index cd98f39..f37c564 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -1,4 +1,5 @@ use futures::never::Never; +use gettextrs::*; use i2cdev::core::*; use i2cdev::linux::LinuxI2CDevice; use i2cdev::linux::LinuxI2CError; @@ -152,8 +153,13 @@ impl Haustuer { */ } HaustuerChange::Err(err) => { - println!("Error on {}", err); - sleep(Duration::from_millis(1000)).await; + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Default, + gettext!("⚠️ Error on {}", err), + )) + .await?; + sleep(Duration::from_millis(3000)).await; } } interval.tick().await; From 543bb7d2d41d80d6eee6b22042ce3ac1d3979724 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 08:19:40 +0100 Subject: [PATCH 25/59] continue/start translation --- files/opensesame.mo | Bin 5914 -> 6456 bytes lang/de_AT.po | 26 +++++++++++++++++++++++++- lang/opensesame.pot | 26 +++++++++++++++++++++++++- src/haustuer.rs | 14 +++++++------- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/files/opensesame.mo b/files/opensesame.mo index 09ad8a89f16753c756b70a998f0a3f10d788568f..543f3dc9cbff0c0f9c5ec7835a68d82edcac9a09 100644 GIT binary patch delta 1626 zcmZ|Pdx%U?9Ki82v%6Sp?J^AOdAwh1JeNftZL-#G(OTjUam}9H89VOPox71oBY)rz zMIMQg_{*QGQ3yp_!XFe;O8$`lM2bj=@9*643a9RT&N=tI?(dv4rxRCZ=AQR2KA}i+ zd4};kjwscDhl=8$gYgE+cu#N~zQg`l)kCQ* zSdG-@)JZZ6skni4__o((BW7`xfZ8k zGfu~Sh4*c;aJL#u?#<<^e>?x?Z*~e zg!1L6`#Ze-oY985o0)seUO0{;v`&!45fDB z4z_VW$~fQphU3R8!mZnY452zOw~NdUGE?zA4#Lru;g`EaYxdo-eK^%>@ za6G<5IU8jI!*V@p$}Ud9!zdBGhGXz4O8>7o0d<`COURZJC+X0FvgdnII-W0-Z=&q! z3zUd_!Iij_a5;D!rQZkSl^VK425p;BnM=52f9!92wcWD5J|lsxcz+NJLnu z4Lz5_o_4U;i`!(AOd?6H7}5QiWHCRI9A=3syQ??~HgcSGd!}-QYi?IV-5*IJz^zh~ zdE}%^VvB8(a7sit3ibn}at4o_qnT15abxXynu}Zx`@aD;^l}sCaAxh@ls^gy58G)I z$H0auigHpVgt9%dcM>K3dpKF1Se=L1g6tDA55XfS;rUSjqq%y`X_F?(q$g!%5vbfXP#^QB4 z8)&laCZN4>^Xn@j#km$I8_>Kdo#Z3Zu4`P~Zd(2B>&cGb=f}u9XRBW8`R$HR*PTx1 z-_06bZ(Ez*Y|{U4s8=UbP9`vg=}g*SY*6ihHmS=?(6!Dm+UaVCi`tYd1t`Y F=y&OI`se@v delta 1132 zcmYk*%}Z2K7{~GFdM8aMb!Kd)d?_to(i*R0rf4rH7D*))Qh`SFLYrz6K@u3vrU)u( z5w!^0L@*RBio59#2ux&FK|~945f~A)ie4b-`#avE2hM!Xxn9pb=XuU~x%okmpHIc^ z8PQE^pgs1?c4F4&hv<))_2B?k;(1(wSMVa<#4LKt%vNK7nr8%C@id;r8`1b1?qFPB zYBp?^w{bdpFpXpQ9=BmZy%jM(N+*#p+k?kYe<2L%mq!N2U0PT0j+f_3;1T zK)YSHqizxB%}AVkUyGz_?q+DCx>QudotswF`Ew~zU!h$qx|T3*mr*7cCH#^}w?HlG zZz%POjWiwHMhys^5oMEP{tFW0Hm0m9hA5?#(>Sayg#jv6Wi%b4ER7rKf~>g%rqt<< pE5e!BaW5Pw&HHzoD;C3!_**~BRNwZ(V&bPCj;1TU@LDD;`2&K0VKx8& diff --git a/lang/de_AT.po b/lang/de_AT.po index e9d9410..942b7d9 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-14 08:22+0000\n" +"POT-Creation-Date: 2023-12-15 07:19+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -161,6 +161,30 @@ msgstr "🚨 Mögicher Feuer-Alarm! Läute Glocke 1x! ⏰. {}" msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "🚨 Möglicher Feueralarm! (läute noch nicht). {}" +#: src/haustuer.rs:65 +msgid "Board 58 with error {}" +msgstr "Brett 58 mit Fehler {}" + +#: src/haustuer.rs:116 +msgid "💡 Light far outdoor pressed." +msgstr "💡 Licht am Vorgartenzaun gedrückt." + +#: src/haustuer.rs:123 +msgid "💡 Pressed at entrance switch. Switch lights." +msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." + +#: src/haustuer.rs:131 +msgid "🔔 Bell far outdoor pressed." +msgstr "🔔 Taste für Glocke Vorgarten gedrückt." + +#: src/haustuer.rs:142 +msgid "💡 Indoor light pressed." +msgstr "💡 Taster Licht innen gedrückt." + +#: src/haustuer.rs:159 +msgid "⚠️ Error on {}" +msgstr "⚠️ Ein Fehler auf {} ist aufgetreten" + #: src/mod_ir_temp.rs:199 msgid "🌡️🌡️ ModIR both sensors too hot! Ambient: {} °C, Object: {} °C" msgstr "🌡️🌡️ Beide ModIR Sensoren sind zu heiß! Ambient: {} °C, Objekt: {} °C" diff --git a/lang/opensesame.pot b/lang/opensesame.pot index 258a4e6..e2d49a3 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-14 08:22+0000\n" +"POT-Creation-Date: 2023-12-15 07:19+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -149,6 +149,30 @@ msgstr "" msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "" +#: src/haustuer.rs:65 +msgid "Board 58 with error {}" +msgstr "" + +#: src/haustuer.rs:116 +msgid "💡 Light far outdoor pressed." +msgstr "" + +#: src/haustuer.rs:123 +msgid "💡 Pressed at entrance switch. Switch lights." +msgstr "" + +#: src/haustuer.rs:131 +msgid "🔔 Bell far outdoor pressed." +msgstr "" + +#: src/haustuer.rs:142 +msgid "💡 Indoor light pressed." +msgstr "" + +#: src/haustuer.rs:159 +msgid "⚠️ Error on {}" +msgstr "" + #: src/mod_ir_temp.rs:199 msgid "🌡️🌡️ ModIR both sensors too hot! Ambient: {} °C, Object: {} °C" msgstr "" diff --git a/src/haustuer.rs b/src/haustuer.rs index f37c564..7f2b6ec 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -62,7 +62,7 @@ impl Haustuer { .board .smbus_read_byte_data(READ_COMMAND_FOR_IO_OPTO_PINS); if let Err(error) = epins { - return HaustuerChange::Err(format!("Board 58 with error {}", error)); + return HaustuerChange::Err(gettext!("Board 58 with error {}", error)); } let pins = epins.unwrap(); @@ -113,14 +113,14 @@ impl Haustuer { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Default, - String::from("💡 LightFarOutdoor pressed."), + gettext("💡 Light far outdoor pressed."), )) .await?; command_sender .send(CommandToButtons::SwitchLights( false, true, - "💡 Pressed at entrance top switch. Switch lights".to_string(), + gettext("💡 Pressed at entrance switch. Switch lights."), )) .await?; } @@ -128,7 +128,7 @@ impl Haustuer { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Default, - String::from("🔒 BellFarOutdoor pressed."), + gettext("🔔 Bell far outdoor pressed."), )) .await?; command_sender @@ -139,15 +139,15 @@ impl Haustuer { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Default, - String::from("🔒 LightIndoor pressed."), + gettext("💡 Indoor light pressed."), )) .await?; - /* + /* TODO, reinclude command_sender .send(CommandToButtons::SwitchLights( true, true, - "💡 Pressed in entrance. Switch all lights".to_string(), + gettext("💡 Pressed in entrance. Switch all lights"), )) .await?; */ From 2741ea6e403bbcfaddc653dcdf6de524176f0475 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 09:13:04 +0100 Subject: [PATCH 26/59] reinclude --- src/haustuer.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 7f2b6ec..4e27f57 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -142,7 +142,6 @@ impl Haustuer { gettext("💡 Indoor light pressed."), )) .await?; - /* TODO, reinclude command_sender .send(CommandToButtons::SwitchLights( true, @@ -150,7 +149,6 @@ impl Haustuer { gettext("💡 Pressed in entrance. Switch all lights"), )) .await?; - */ } HaustuerChange::Err(err) => { nextcloud_sender From e4ceceeb6fcc1ac64e661ee3553b5bd91829a4b9 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 09:57:24 +0100 Subject: [PATCH 27/59] implement Rst Logic --- src/haustuer.rs | 12 ++++++++++-- src/lib.rs | 1 + src/rst.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/rst.rs diff --git a/src/haustuer.rs b/src/haustuer.rs index 4e27f57..27b83fa 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -4,9 +4,10 @@ use i2cdev::core::*; use i2cdev::linux::LinuxI2CDevice; use i2cdev::linux::LinuxI2CError; use systemstat::Duration; -use tokio::{sync::mpsc::Sender, time::interval, time::sleep}; +use tokio::{sync::mpsc::Sender, time::interval}; use crate::{ + rst::Rst, buttons::CommandToButtons, config::Config, nextcloud::{NextcloudChat, NextcloudEvent}, @@ -106,6 +107,7 @@ impl Haustuer { nextcloud_sender: Sender, ) -> Result { let mut interval = interval(Duration::from_millis(30)); + let mut rst = Rst::new(); loop { match haustuer.handle() { HaustuerChange::None => (), @@ -157,7 +159,13 @@ impl Haustuer { gettext!("⚠️ Error on {}", err), )) .await?; - sleep(Duration::from_millis(3000)).await; + rst.do_reset().await?; + nextcloud_sender + .send(NextcloudEvent::Chat( + NextcloudChat::Ping, + gettext("👋 RST MOD-IO done"), + )) + .await?; } } interval.tick().await; diff --git a/src/lib.rs b/src/lib.rs index a0d5792..f27f599 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub mod mod_ir_temp; pub mod nextcloud; pub mod ping; pub mod pwr; +pub mod rst; pub mod sensors; pub mod signals; pub mod ssh; diff --git a/src/rst.rs b/src/rst.rs new file mode 100644 index 0000000..ed37213 --- /dev/null +++ b/src/rst.rs @@ -0,0 +1,48 @@ +use gpio_cdev::{Chip, LineHandle, LineRequestFlags}; + +use systemstat::Duration; +use tokio::time::sleep; + +use crate::types::ModuleError; + +const GPIO_RST_LINE: u32 = 203; + +pub struct Rst { + state: bool, + rst_line: LineHandle, +} + +impl Rst { + pub fn new() -> Self { + let mut chip = Chip::new("/dev/gpiochip0").unwrap(); + let line = chip + .get_line(GPIO_RST_LINE) + .unwrap() + .request(LineRequestFlags::OUTPUT, 0, "gpio_rst_line") + .unwrap(); + Self { + state: line.get_value().unwrap() != 0, + rst_line: line, + } + } + + pub fn switch(&mut self, state: bool) { + if state && !self.state { + self.rst_line.set_value(1).unwrap(); + } else if self.state { + self.rst_line.set_value(0).unwrap(); + } + self.state = state; + } + + pub async fn do_reset( + &mut self + ) -> Result<(), ModuleError> { + self.switch(false); + sleep(Duration::from_millis(10)).await; + + self.switch(true); + sleep(Duration::from_millis(10)).await; + Ok(()) + } +} From 7cb5d9c8ec7b8dbad4040523067b9c2c45168440 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 10:19:41 +0100 Subject: [PATCH 28/59] reformat --- "doc/Haust\303\274re.md" | 22 ++++++++++++++++++++++ src/haustuer.rs | 2 +- src/rst.rs | 4 +--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git "a/doc/Haust\303\274re.md" "b/doc/Haust\303\274re.md" index 393a6fa..f8e1021 100644 --- "a/doc/Haust\303\274re.md" +++ "b/doc/Haust\303\274re.md" @@ -97,3 +97,25 @@ Sensor Mod-ENV 24V 0.5A for relais 6V~ 0.3A for bell 5V 2.0A for A20 + +## Kabeln + +von links nach rechts: + +1. nicht verwendet: blau, Nullleiter Vorraum, 1-polig +2. nicht verwendet: grau, 14 polig, no shield, vermutlich von Haustüre kommend (geht quer über alle Sicherung) +3. Taster Eingang Innen: schwarz, 2 polig, no shield, Board21 GPIO2 (Schlauch 1) +4. Türöffner: weiss, 2 polig, no shield, 12 V (geht quer über alle Sicherung) +5. Medi-Sensor: weiss, 4? polig, paar-weise geshielded, Verwendung: i2C Environment (Schlauch nach oben, mit Stromdrähten) +6. Hauptkabel zu Türöffner, geshielded (geht quer über alle Sicherung) +7. Taster bei Glocke, orange/weiss, Board 21 GPIO 0 (Schlauch mit fetten anderen Kabel, evtl wärmepumpe) +8. Netzwerkkabel 1 +9. Netzwerkkabel 2 +10. Glocke Taster aussen, weiss klein dünn, Board 21 GPIO 3 (Schlauch 1) +11. Anschlusskabel grüne Relais (HIMA), 4 polig, with shield; + grün: linke Relay 4 + gelb: rechts Relay 4, + weiß: rechts Relay 2 (GND) + braun: linken Relay 2 (GND) + shield: GND +12. Glocke: 2 polig, no shield 16V (eigener Schlauch) diff --git a/src/haustuer.rs b/src/haustuer.rs index 27b83fa..2f338cc 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -7,10 +7,10 @@ use systemstat::Duration; use tokio::{sync::mpsc::Sender, time::interval}; use crate::{ - rst::Rst, buttons::CommandToButtons, config::Config, nextcloud::{NextcloudChat, NextcloudEvent}, + rst::Rst, types::ModuleError, }; diff --git a/src/rst.rs b/src/rst.rs index ed37213..e5ceec0 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -35,9 +35,7 @@ impl Rst { self.state = state; } - pub async fn do_reset( - &mut self - ) -> Result<(), ModuleError> { + pub async fn do_reset(&mut self) -> Result<(), ModuleError> { self.switch(false); sleep(Duration::from_millis(10)).await; From c1ca877e73342be819c4c3c06279b50a666579af Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 10:20:49 +0100 Subject: [PATCH 29/59] fix some clippy warnings --- src/bat.rs | 6 ++++++ src/rst.rs | 6 ++++++ src/weather_station/write_to_reg.rs | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/bat.rs b/src/bat.rs index a5a565d..10ac9e0 100644 --- a/src/bat.rs +++ b/src/bat.rs @@ -23,6 +23,12 @@ pub struct Bat { capacity_threshold: u8, } +impl Default for Bat { + fn default() -> Self { + Self::new() + } +} + impl Bat { pub fn new() -> Self { Self { diff --git a/src/rst.rs b/src/rst.rs index e5ceec0..7fc9fbf 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -12,6 +12,12 @@ pub struct Rst { rst_line: LineHandle, } +impl Default for Rst { + fn default() -> Self { + Self::new() + } +} + impl Rst { pub fn new() -> Self { let mut chip = Chip::new("/dev/gpiochip0").unwrap(); diff --git a/src/weather_station/write_to_reg.rs b/src/weather_station/write_to_reg.rs index 298b954..6385f34 100644 --- a/src/weather_station/write_to_reg.rs +++ b/src/weather_station/write_to_reg.rs @@ -5,7 +5,7 @@ use libmodbus::*; use std::env; ///Constants -const DEVICE: &'static str = "/dev/ttyS5"; +const DEVICE: &str = "/dev/ttyS5"; const BAUDRATE: i32 = 9600; const PARITY: char = 'N'; const DATA_BITS: i32 = 8; @@ -31,11 +31,11 @@ fn main() { // open Modbus connection ctx.connect().expect("Verbindung mit ctx Fehlerhaft!"); - ctx.write_registers(KY_REG, 2, &vec![0, 0x1267]) + ctx.write_registers(KY_REG, 2, &[0, 0x1267]) .expect("Error while writing register KY_REG"); ctx.write_registers(reg, 2, &value) .expect("Error while writing register as given by command-line argument"); - ctx.write_registers(KY_REG, 2, &vec![0, 0]) + ctx.write_registers(KY_REG, 2, &[0, 0]) .expect("Error while writing register KY_REG"); // close Modbus connection From d9eb3c90e2c52500315be3e37bd05f2a766d4039 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 10:43:53 +0100 Subject: [PATCH 30/59] fix fmt of code changed by clippy --- src/bat.rs | 6 +++--- src/rst.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bat.rs b/src/bat.rs index 10ac9e0..f6cfaaf 100644 --- a/src/bat.rs +++ b/src/bat.rs @@ -24,9 +24,9 @@ pub struct Bat { } impl Default for Bat { - fn default() -> Self { - Self::new() - } + fn default() -> Self { + Self::new() + } } impl Bat { diff --git a/src/rst.rs b/src/rst.rs index 7fc9fbf..1d6b95b 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -13,9 +13,9 @@ pub struct Rst { } impl Default for Rst { - fn default() -> Self { - Self::new() - } + fn default() -> Self { + Self::new() + } } impl Rst { From 267a0a7e292606bbe230591ab101f7f23f52bfc2 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 10:58:57 +0100 Subject: [PATCH 31/59] add a few comments --- src/pwr.rs | 4 +++- src/rst.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pwr.rs b/src/pwr.rs index 948e170..25fd382 100644 --- a/src/pwr.rs +++ b/src/pwr.rs @@ -1,3 +1,5 @@ +// needs UEXT PIN 3 connected with PWR-SWITCH https://www.olimex.com/Products/Duino/Shields/PWR-SWITCH/ + use gpio_cdev::{Chip, LineHandle, LineRequestFlags}; use systemstat::Duration; @@ -12,7 +14,7 @@ use crate::config::Config; use crate::types::ModuleError; use crate::watchdog; -const GPIO_PWR_LINE: u32 = 202; +const GPIO_PWR_LINE: u32 = 202; // UEXT1 (e.g. LIME-2 Shield) UART4-TX GPIO202 PG10 pub struct Pwr { state: bool, diff --git a/src/rst.rs b/src/rst.rs index 1d6b95b..7b92edf 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -1,3 +1,5 @@ +// Needs UEXT1 PIN 4 connected with RST of MOD-IO's JTAG PIN 6 (RST) + use gpio_cdev::{Chip, LineHandle, LineRequestFlags}; use systemstat::Duration; @@ -5,7 +7,7 @@ use tokio::time::sleep; use crate::types::ModuleError; -const GPIO_RST_LINE: u32 = 203; +const GPIO_RST_LINE: u32 = 203; // UEXT1 (e.g. LIME-2 Shield) UART4-RX GPIO203 PG11 pub struct Rst { state: bool, From ca5bbd370527fd0ebfd380dec22231de7d7e9b0c Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 14:47:47 +0100 Subject: [PATCH 32/59] use correct chats --- src/haustuer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 2f338cc..e142700 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -114,7 +114,7 @@ impl Haustuer { HaustuerChange::LightFarOutdoor => { nextcloud_sender .send(NextcloudEvent::Chat( - NextcloudChat::Default, + NextcloudChat::Licht, gettext("💡 Light far outdoor pressed."), )) .await?; @@ -140,7 +140,7 @@ impl Haustuer { HaustuerChange::LightIndoor => { nextcloud_sender .send(NextcloudEvent::Chat( - NextcloudChat::Default, + NextcloudChat::Licht, gettext("💡 Indoor light pressed."), )) .await?; @@ -148,22 +148,22 @@ impl Haustuer { .send(CommandToButtons::SwitchLights( true, true, - gettext("💡 Pressed in entrance. Switch all lights"), + gettext("💡 Pressed in entrance. Switch all lights."), )) .await?; } HaustuerChange::Err(err) => { nextcloud_sender .send(NextcloudEvent::Chat( - NextcloudChat::Default, - gettext!("⚠️ Error on {}", err), + NextcloudChat::Ping, + gettext!("⚠️ Error on {}, will do reset.", err), )) .await?; rst.do_reset().await?; nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Ping, - gettext("👋 RST MOD-IO done"), + gettext("👋 RST of MOD-IO done."), )) .await?; } From e53ac5f84d70424f590482846bcf4c70e089ee35 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 15 Dec 2023 14:50:15 +0100 Subject: [PATCH 33/59] update translations --- files/opensesame.mo | Bin 6456 -> 6693 bytes lang/de_AT.po | 34 +++++++++++++++++++++------------- lang/opensesame.pot | 34 +++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/files/opensesame.mo b/files/opensesame.mo index 543f3dc9cbff0c0f9c5ec7835a68d82edcac9a09..09b5306dfee1870fedbccdf18190f5b3ffa06ac9 100644 GIT binary patch delta 1386 zcmX}sNla5g7{Kwb&=#n&NLvsAeWD0jD2rv&xZxI1(pZSbc&bn=rna#bG11syqQ-;q zKsb0b!9){Gj6Gls7ncYT6R)1|03o6Wy%^rk{U>(llM*M|3Ux8hu8a-Hrr|=>s z((Ot4LSY{bwj7a8Jd9eug8_Vpd$BZEsP&szh7Yj; zQ`m?L=I==nmqTO=4GpLr{HSk|#LYOF`F#$zQvZ%RVg9=G18Pvmcj9(Dk9_1VUpjsa zwf~EZAF-JF5|;CPS)p(O-R$Ra4B|0-ik0{i^#}^scU^fkdhs+i;cax{6zartxD)4* zsU^2Sg5$A6^0%g>L|kT+G4S7<36iW;G4A|8zPhrCAb t$WWp`Yy=~bl-prqbU4n$ZdaQnRphR<{s(zIk6i!& delta 1226 zcmY+^Uuex?9LMqR`Ll6$%%7b(_Q&R!4P%_0Is2>4lAO&Htr2R4ODl@hVmWIH7m6}1 z7jBetIsFvUiW`l@g{9mm;)R1B;LmsoW^2Yz$I8*V0IQOumP`Q8BU?bdxv#6izQfIXm$b{ zkn?$);GmNeQ@9i7gScyvSwHazZpSyc1LKSRiS%KXcntU8L#)7X%(n{5iQ6!Z{n&_O z!F3PU@P2z8-0&T%xuLp97nl^T#X;0SdDIJT1=k;7E%6M-@i*%E0s`G%8`y>V@U@G( z9ma#GcoMsD7CSJ@?A!2Eg8cV$aE}v8?K~=l$x`2D+(tZrdf*Dy;4@s0pHXWgzS56# zm?A!joADYdqfc-hzDGU(7dK!kN&c0x9`d9I22eF0MLl>Yh@YZr`U#bhKe!Kfk*;Gn zj(YAFa>>fr0*#nPeZWy{#&JyHOVoW|dpJ<-!i=toG+;>5l@TWDQqQJvs~z0-VmG;_ zm#Ed<_!voOF}bGYt2|OqqxddYtZui8f_?2?&#C{KKACM~o9J5FYSh#<H znW1apG$}AUV(d}3f?AR7;QlGVC0lF1g`TGCpF#Pcey&k>mzOYVX)0%`hl-`NM7=N3 e3nA}J;au3e7>k9x$3;J4-mB6~$ZJo2i~IvARc!VE diff --git a/lang/de_AT.po b/lang/de_AT.po index 942b7d9..bf0b543 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-15 07:19+0000\n" +"POT-Creation-Date: 2023-12-15 13:48+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -31,19 +31,19 @@ msgstr "🚨 Audio Feueralarm!" msgid "Couldn't send SIGUSR2 to other opensesame instance: {}" msgstr "SIGUSR2 konnte nicht zu anderen Opensesame-Instanz gesendet werden: {}" -#: src/bat.rs:60 +#: src/bat.rs:66 msgid "🪫 ON {}%" msgstr "🪫 An {}%" -#: src/bat.rs:67 +#: src/bat.rs:73 msgid "🪫 Battery Capacity is below {}% at {}%" msgstr "🪫 Batterieladung ist unter {}% auf {}%" -#: src/bat.rs:83 +#: src/bat.rs:89 msgid "🔋 ON {}%" msgstr "🔋 An {}%" -#: src/bat.rs:89 +#: src/bat.rs:95 msgid "🔋 Battery Capacity is back to {}%" msgstr "🔋 Batterieladung ist zurück bei {}%" @@ -161,30 +161,38 @@ msgstr "🚨 Mögicher Feuer-Alarm! Läute Glocke 1x! ⏰. {}" msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "🚨 Möglicher Feueralarm! (läute noch nicht). {}" -#: src/haustuer.rs:65 +#: src/haustuer.rs:66 msgid "Board 58 with error {}" msgstr "Brett 58 mit Fehler {}" -#: src/haustuer.rs:116 +#: src/haustuer.rs:118 msgid "💡 Light far outdoor pressed." msgstr "💡 Licht am Vorgartenzaun gedrückt." -#: src/haustuer.rs:123 +#: src/haustuer.rs:125 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." -#: src/haustuer.rs:131 +#: src/haustuer.rs:133 msgid "🔔 Bell far outdoor pressed." msgstr "🔔 Taste für Glocke Vorgarten gedrückt." -#: src/haustuer.rs:142 +#: src/haustuer.rs:144 msgid "💡 Indoor light pressed." msgstr "💡 Taster Licht innen gedrückt." +#: src/haustuer.rs:151 +msgid "💡 Pressed in entrance. Switch all lights." +msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." + #: src/haustuer.rs:159 -msgid "⚠️ Error on {}" +msgid "⚠️ Error on {}, will do reset." msgstr "⚠️ Ein Fehler auf {} ist aufgetreten" +#: src/haustuer.rs:166 +msgid "👋 RST of MOD-IO done." +msgstr "👋 RST von MOD-IO durchgeführt." + #: src/mod_ir_temp.rs:199 msgid "🌡️🌡️ ModIR both sensors too hot! Ambient: {} °C, Object: {} °C" msgstr "🌡️🌡️ Beide ModIR Sensoren sind zu heiß! Ambient: {} °C, Objekt: {} °C" @@ -217,11 +225,11 @@ msgstr "" "{} Ping! Version {}, {}, Status {}, Error {}, Load {} {} {}, " "Speicherauslastung {}, Swap {}, CPU temp {}, Startup {} Bat {}" -#: src/pwr.rs:73 +#: src/pwr.rs:75 msgid "👋 Turned PWR switch OFF" msgstr "👋 PWR switch AUS geschalten" -#: src/pwr.rs:82 +#: src/pwr.rs:84 msgid "👋 Turned PWR switch ON" msgstr "👋 PWR switch EIN geschalten" diff --git a/lang/opensesame.pot b/lang/opensesame.pot index e2d49a3..138e209 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-15 07:19+0000\n" +"POT-Creation-Date: 2023-12-15 13:48+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -29,19 +29,19 @@ msgstr "" msgid "Couldn't send SIGUSR2 to other opensesame instance: {}" msgstr "" -#: src/bat.rs:60 +#: src/bat.rs:66 msgid "🪫 ON {}%" msgstr "" -#: src/bat.rs:67 +#: src/bat.rs:73 msgid "🪫 Battery Capacity is below {}% at {}%" msgstr "" -#: src/bat.rs:83 +#: src/bat.rs:89 msgid "🔋 ON {}%" msgstr "" -#: src/bat.rs:89 +#: src/bat.rs:95 msgid "🔋 Battery Capacity is back to {}%" msgstr "" @@ -149,28 +149,36 @@ msgstr "" msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "" -#: src/haustuer.rs:65 +#: src/haustuer.rs:66 msgid "Board 58 with error {}" msgstr "" -#: src/haustuer.rs:116 +#: src/haustuer.rs:118 msgid "💡 Light far outdoor pressed." msgstr "" -#: src/haustuer.rs:123 +#: src/haustuer.rs:125 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "" -#: src/haustuer.rs:131 +#: src/haustuer.rs:133 msgid "🔔 Bell far outdoor pressed." msgstr "" -#: src/haustuer.rs:142 +#: src/haustuer.rs:144 msgid "💡 Indoor light pressed." msgstr "" +#: src/haustuer.rs:151 +msgid "💡 Pressed in entrance. Switch all lights." +msgstr "" + #: src/haustuer.rs:159 -msgid "⚠️ Error on {}" +msgid "⚠️ Error on {}, will do reset." +msgstr "" + +#: src/haustuer.rs:166 +msgid "👋 RST of MOD-IO done." msgstr "" #: src/mod_ir_temp.rs:199 @@ -201,11 +209,11 @@ msgstr "" msgid "{} Ping! Version {}, {}, Status {}, Error {}, Load {} {} {}, Memory usage {}, Swap {}, CPU temp {}, Startup {} Bat {}" msgstr "" -#: src/pwr.rs:73 +#: src/pwr.rs:75 msgid "👋 Turned PWR switch OFF" msgstr "" -#: src/pwr.rs:82 +#: src/pwr.rs:84 msgid "👋 Turned PWR switch ON" msgstr "" From 1eadc28b9785a1e924b3a86c628e95d4b874889b Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 05:48:55 +0100 Subject: [PATCH 34/59] try longer rst time --- src/rst.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rst.rs b/src/rst.rs index 7b92edf..a81fa75 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -45,10 +45,10 @@ impl Rst { pub async fn do_reset(&mut self) -> Result<(), ModuleError> { self.switch(false); - sleep(Duration::from_millis(10)).await; + sleep(Duration::from_millis(100)).await; self.switch(true); - sleep(Duration::from_millis(10)).await; + sleep(Duration::from_millis(100)).await; Ok(()) } } From 8e0d90879a2b564d809c78d33936a14217159e84 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 13:22:43 +0100 Subject: [PATCH 35/59] unhandled panic+working threads --- .cargo/config.toml | 4 +++ Cargo.lock | 87 +++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 3 +- src/buttons.rs | 1 + src/environment.rs | 8 ++++- src/main.rs | 33 ++++++++++++------ 6 files changed, 105 insertions(+), 31 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index cbb49d3..290cf13 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,3 +4,7 @@ linker = "arm-linux-gnueabihf-gcc" [env] GETTEXT_SYSTEM = "1" + +[build] +rustflags = ["--cfg", "tokio_unstable"] + diff --git a/Cargo.lock b/Cargo.lock index 68f0fd8..3d7be97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -110,6 +119,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base-x" version = "0.2.11" @@ -834,6 +858,12 @@ dependencies = [ "polyval", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "glob" version = "0.3.0" @@ -962,7 +992,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -1078,9 +1108,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" @@ -1232,12 +1262,11 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] @@ -1402,6 +1431,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.13.0" @@ -1574,9 +1612,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project-lite" -version = "0.2.8" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1925,6 +1963,12 @@ dependencies = [ "yasna", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2217,6 +2261,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "spidev" version = "0.5.1" @@ -2496,33 +2550,32 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.19.2" +version = "1.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" +checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" dependencies = [ + "backtrace", "bytes", "libc", - "memchr", "mio", "num_cpus", - "once_cell", "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", - "winapi", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "1.8.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.85", + "syn 2.0.29", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 203045d..b52bfff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ assets = [ ["doc/*", "usr/share/doc/opensesame/", "644"], ] - [dependencies] gpio-cdev = { version = "0.5.1", features = ["async-tokio"]} @@ -59,7 +58,7 @@ chrono = "0.4.19" signal-hook = "0.3.14" signal-hook-tokio = "0.3.1" -tokio = { version = "1.15.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["full"] } tokio-util = "0.6.9" async-ssh2-tokio = "0.7.1" futures = "0.3.19" diff --git a/src/buttons.rs b/src/buttons.rs index 22226fa..da8ec2b 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -166,6 +166,7 @@ impl Buttons { self.board20 .smbus_write_byte_data(SET_TRIS, ALL_BUTTONS) .expect("I2C Communication to Buttons does not work"); + // Info: typical point to trigger shutdown via panic self.board21 .smbus_write_byte_data(SET_TRIS, ALL_BUTTONS) .unwrap(); diff --git a/src/environment.rs b/src/environment.rs index 08a503a..bfd64e2 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -316,7 +316,13 @@ impl<'a> Environment<'a> { Some(board5a) => { // check if we get new data if !self.first_time { - let measurement = self.bme280.as_mut().unwrap().measure().unwrap(); + let measurement = self + .bme280 + .as_mut() + .unwrap() + .measure() + .expect("Communication to Mod-ENV/BME280 does not work"); + // Info: typical point to trigger shutdown via panic set_env_data_ccs811(board5a, measurement.temperature, measurement.humidity); self.temperature = measurement.temperature; self.humidity = measurement.humidity; diff --git a/src/main.rs b/src/main.rs index 44db265..9e3db3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,10 @@ use mlx9061x::Error as MlxError; use std::panic; use std::sync::Arc; use systemstat::Duration; +use tokio::runtime::UnhandledPanic; use tokio::spawn; use tokio::sync::{mpsc, Mutex}; -use tokio::time::interval; +use tokio::time::interval; // https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.unhandled_panic use opensesame::audio::{Audio, AudioEvent}; use opensesame::bat::Bat; @@ -30,10 +31,20 @@ use opensesame::watchdog::Watchdog; const CONFIG_PARENT: &str = "/sw/libelektra/opensesame/#0/current"; const STATE_PARENT: &str = "/state/libelektra/opensesame/#0/current"; -#[tokio::main] -async fn main() -> Result<(), ModuleError> { +fn main() { TextDomain::new("opensesame").init().unwrap(); + tokio::runtime::Builder::new_multi_thread() + .unhandled_panic(UnhandledPanic::ShutdownRuntime) + .worker_threads(2) + .enable_all() + .build() + .unwrap() + .block_on(async { + let _ = start().await; + }) +} +async fn start() -> Result<(), ModuleError> { let mut config = Config::new(CONFIG_PARENT); let config_mutex = Arc::new(Mutex::new(Config::new(CONFIG_PARENT))); let state_mutex = Arc::new(Mutex::new(Config::new(STATE_PARENT))); @@ -108,10 +119,16 @@ async fn main() -> Result<(), ModuleError> { // eprintln!("{}", text); // })); - let _ = pwr.do_reset(nextcloud_sender.clone()).await; - let mut tasks = vec![]; + if watchdog_enabled { + let interval = interval(Duration::from_secs(config.get::("watchdog/interval"))); + let path = config.get::("watchdog/path"); + tasks.push(spawn(Watchdog::get_background_task(path, interval))); + } + + let _ = pwr.do_reset(nextcloud_sender.clone()).await; + tasks.push(spawn(Nextcloud::get_background_task( Nextcloud::new(&mut config), nextcloud_receiver, @@ -253,12 +270,6 @@ async fn main() -> Result<(), ModuleError> { ))); } - if watchdog_enabled { - let interval = interval(Duration::from_secs(config.get::("watchdog/interval"))); - let path = config.get::("watchdog/path"); - tasks.push(spawn(Watchdog::get_background_task(path, interval))); - } - if ping_enabled { tasks.push(spawn(Ping::get_background_task( Ping::new(startup_time.to_string()), From 2c1b8ba496f727333d8da16a31379ad4b6228ff9 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 14:41:11 +0100 Subject: [PATCH 36/59] use lower value, see https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/8/html/optimizing_rhel_8_for_real_time_for_low_latency_operation/assembly_viewing-scheduling-priorities-of-running-threads_optimizing-rhel8-for-real-time-for-low-latency-operation --- debian/service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/service b/debian/service index c00ae0d..c3066c9 100644 --- a/debian/service +++ b/debian/service @@ -12,7 +12,7 @@ NoNewPrivileges=true ProtectSystem=full Nice=-20 -CPUSchedulingPriority=80 +CPUSchedulingPriority=49 IOSchedulingClass=realtime IOSchedulingPriority=0 From 341c428d62c75f50626e68f79ca55523a45f3c68 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 16:52:00 +0100 Subject: [PATCH 37/59] add 15 init value --- src/buttons.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buttons.rs b/src/buttons.rs index da8ec2b..8e405a4 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -105,7 +105,7 @@ const RELAY_LICHT_AUSSEN: u8 = 0x01 << 1; const ALL_RELAYS: u8 = RELAY_DOOR | RELAY_LICHT_AUSSEN; -const PINS1_INIT: u8 = 0b01100000; +const PINS1_INIT: u8 = 0b01100000 + 15; // add 15 to avoid "⌛ Timeout mit Sequenz [15]" error // board 21 From 019085749a91a72de659af6b129eea1ae87440b6 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 16:54:33 +0100 Subject: [PATCH 38/59] also add policy --- debian/service | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/service b/debian/service index c3066c9..59cb485 100644 --- a/debian/service +++ b/debian/service @@ -13,6 +13,7 @@ ProtectSystem=full Nice=-20 CPUSchedulingPriority=49 +CPUSchedulingPolicy=rr IOSchedulingClass=realtime IOSchedulingPriority=0 From 87b80784bfefb846dc322fd66421d93c488c8c65 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 16 Dec 2023 17:13:50 +0100 Subject: [PATCH 39/59] try Priority 20 --- debian/service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/service b/debian/service index 59cb485..b9e018e 100644 --- a/debian/service +++ b/debian/service @@ -12,8 +12,8 @@ NoNewPrivileges=true ProtectSystem=full Nice=-20 -CPUSchedulingPriority=49 -CPUSchedulingPolicy=rr +CPUSchedulingPriority=20 +CPUSchedulingPolicy=fifo IOSchedulingClass=realtime IOSchedulingPriority=0 From e7ddbc77eb4c2f7ff0a8d470144753a701aeaac0 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 17 Dec 2023 06:49:53 +0100 Subject: [PATCH 40/59] start buttons earlier --- src/main.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9e3db3d..10bbf24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,6 +138,22 @@ async fn start() -> Result<(), ModuleError> { startup_time.to_string(), ))); + if buttons_enabled { + let time_format = config.get::("nextcloud/format/time"); + let location_latitude = config.get::("location/latitude"); + let location_longitude = config.get::("location/longitude"); + tasks.push(spawn(Buttons::get_background_task( + Buttons::new(&mut config), + Validator::new(&mut config), + time_format.to_string(), + command_receiver, + nextcloud_sender.clone(), + audio_sender.clone(), + location_latitude, + location_longitude, + ))); + } + if garage_enabled { if !buttons_enabled { panic!("⚠️ Garage depends on buttons!"); @@ -160,22 +176,6 @@ async fn start() -> Result<(), ModuleError> { ))); } - if buttons_enabled { - let time_format = config.get::("nextcloud/format/time"); - let location_latitude = config.get::("location/latitude"); - let location_longitude = config.get::("location/longitude"); - tasks.push(spawn(Buttons::get_background_task( - Buttons::new(&mut config), - Validator::new(&mut config), - time_format.to_string(), - command_receiver, - nextcloud_sender.clone(), - audio_sender.clone(), - location_latitude, - location_longitude, - ))); - } - if sensors_enabled { let device_path = config.get::("sensors/device"); tasks.push(spawn(Sensors::get_background_task( @@ -232,7 +232,6 @@ async fn start() -> Result<(), ModuleError> { ))); } - // if env_enabled || buttons_enabled { let audio_bell = config.get::("audio/bell"); let audio_alarm = config.get::("audio/alarm"); tasks.push(spawn(Audio::get_background_task( @@ -240,7 +239,6 @@ async fn start() -> Result<(), ModuleError> { audio_receiver, nextcloud_sender.clone(), ))); - // } if weatherstation_enabled { let clima_sensor_result = ClimaSensorUS::new(&mut config); From 63bdd67f96fe5753a9d1a7fac6e82bf9712325c6 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 17 Dec 2023 06:53:40 +0100 Subject: [PATCH 41/59] reorder steps --- src/main.rs | 56 ++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 10bbf24..0baa216 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,24 +74,6 @@ async fn start() -> Result<(), ModuleError> { let watchdog_enabled = config.get_bool("watchdog/enable"); let ping_enabled = config.get_bool("ping/enable"); - let mut pwr = Pwr::new(&mut config); - - nextcloud_sender.send( - NextcloudEvent::Chat(NextcloudChat::Ping, - gettext!("👋 Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", - buttons_enabled, - garage_enabled, - haustuer_enabled, - pwr.enabled(), - sensors_enabled, - modir_enabled, - env_enabled, - weatherstation_enabled, - bat_enabled, - watchdog_enabled, - ping_enabled, -))).await?; - // use std::ops::Deref; // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log // panic::set_hook(Box::new(|panic_info| { @@ -121,14 +103,7 @@ async fn start() -> Result<(), ModuleError> { let mut tasks = vec![]; - if watchdog_enabled { - let interval = interval(Duration::from_secs(config.get::("watchdog/interval"))); - let path = config.get::("watchdog/path"); - tasks.push(spawn(Watchdog::get_background_task(path, interval))); - } - - let _ = pwr.do_reset(nextcloud_sender.clone()).await; - + // Step 1: NC tasks.push(spawn(Nextcloud::get_background_task( Nextcloud::new(&mut config), nextcloud_receiver, @@ -138,6 +113,34 @@ async fn start() -> Result<(), ModuleError> { startup_time.to_string(), ))); + nextcloud_sender.send( + NextcloudEvent::Chat(NextcloudChat::Ping, + gettext!("👋 Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", + buttons_enabled, + garage_enabled, + haustuer_enabled, + pwr.enabled(), + sensors_enabled, + modir_enabled, + env_enabled, + weatherstation_enabled, + bat_enabled, + watchdog_enabled, + ping_enabled, + ))).await?; + + // Step 2: Watchdog + if watchdog_enabled { + let interval = interval(Duration::from_secs(config.get::("watchdog/interval"))); + let path = config.get::("watchdog/path"); + tasks.push(spawn(Watchdog::get_background_task(path, interval))); + } + + // Step 3: PWR Reset + let mut pwr = Pwr::new(&mut config); + let _ = pwr.do_reset(nextcloud_sender.clone()).await; + + // Step 4: Button module (as others require it) if buttons_enabled { let time_format = config.get::("nextcloud/format/time"); let location_latitude = config.get::("location/latitude"); @@ -154,6 +157,7 @@ async fn start() -> Result<(), ModuleError> { ))); } + // Step 5: now other modules, that might communicate with Buttons if garage_enabled { if !buttons_enabled { panic!("⚠️ Garage depends on buttons!"); From 2b797e77b191d48290bb8788058b57cc80f188ef Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 17 Dec 2023 06:58:41 +0100 Subject: [PATCH 42/59] reallow debug/backtrace --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0baa216..790cc2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use chrono::Local; use futures::future::join_all; use gettextrs::*; use mlx9061x::Error as MlxError; +use std::env; use std::panic; use std::sync::Arc; use systemstat::Duration; @@ -46,6 +47,8 @@ fn main() { async fn start() -> Result<(), ModuleError> { let mut config = Config::new(CONFIG_PARENT); + env::set_var("RUST_BACKTRACE", config.get::("debug/backtrace")); + let config_mutex = Arc::new(Mutex::new(Config::new(CONFIG_PARENT))); let state_mutex = Arc::new(Mutex::new(Config::new(STATE_PARENT))); @@ -113,6 +116,7 @@ async fn start() -> Result<(), ModuleError> { startup_time.to_string(), ))); + let mut pwr = Pwr::new(&mut config); nextcloud_sender.send( NextcloudEvent::Chat(NextcloudChat::Ping, gettext!("👋 Enabled Modules:\n\tButtons: {},\n\tGarage: {},\n\tHaustür: {},\n\tPWR: {},\n\tSensors: {},\n\tModIR: {},\n\tEnvironment: {},\n\tWeatherstation: {},\n\tBattery: {},\n\tWatchdog: {},\n\tPing: {}\n", @@ -137,7 +141,6 @@ async fn start() -> Result<(), ModuleError> { } // Step 3: PWR Reset - let mut pwr = Pwr::new(&mut config); let _ = pwr.do_reset(nextcloud_sender.clone()).await; // Step 4: Button module (as others require it) From bf48b5f5c4ebd929d3980493eed80691658edc87 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 17 Dec 2023 08:38:39 +0100 Subject: [PATCH 43/59] increase to a second --- src/rst.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rst.rs b/src/rst.rs index a81fa75..7ad6d47 100644 --- a/src/rst.rs +++ b/src/rst.rs @@ -45,10 +45,10 @@ impl Rst { pub async fn do_reset(&mut self) -> Result<(), ModuleError> { self.switch(false); - sleep(Duration::from_millis(100)).await; + sleep(Duration::from_millis(1000)).await; self.switch(true); - sleep(Duration::from_millis(100)).await; + sleep(Duration::from_millis(1000)).await; Ok(()) } } From 9a519f84566611ab5c222c0f02d1ab996d07556a Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 17 Dec 2023 08:41:11 +0100 Subject: [PATCH 44/59] unhandled_panic later --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 790cc2c..36dfb22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,9 +35,9 @@ const STATE_PARENT: &str = "/state/libelektra/opensesame/#0/current"; fn main() { TextDomain::new("opensesame").init().unwrap(); tokio::runtime::Builder::new_multi_thread() - .unhandled_panic(UnhandledPanic::ShutdownRuntime) - .worker_threads(2) .enable_all() + .worker_threads(2) + .unhandled_panic(UnhandledPanic::ShutdownRuntime) .build() .unwrap() .block_on(async { From b3f67d4c5d0a8e7119f15a73a5724fd6a4934363 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 22 Dec 2023 12:55:34 +0100 Subject: [PATCH 45/59] avoid massive spam in NC --- src/haustuer.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/haustuer.rs b/src/haustuer.rs index e142700..63ee418 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -40,6 +40,8 @@ pub struct Haustuer { light_far_outdoor: bool, bell_far_outdoor: bool, light_indoor: bool, + + how_many_err: u8, } impl Haustuer { @@ -50,6 +52,8 @@ impl Haustuer { light_far_outdoor: false, bell_far_outdoor: false, light_indoor: false, + + how_many_err: 0, } } @@ -63,8 +67,13 @@ impl Haustuer { .board .smbus_read_byte_data(READ_COMMAND_FOR_IO_OPTO_PINS); if let Err(error) = epins { + self.how_many_err += 1; + if self.how_many_err >= 58 { + panic!("58 errors reached, giving up, last error {}", error) + } return HaustuerChange::Err(gettext!("Board 58 with error {}", error)); } + self.how_many_err = 0; let pins = epins.unwrap(); // self.set_relay(pins).unwrap(); From eb54fa6848e854bac6c2174e8842142629ede002 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 22 Dec 2023 13:22:53 +0100 Subject: [PATCH 46/59] hook to exit process on panics --- src/main.rs | 54 ++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 36dfb22..52a29a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ use futures::future::join_all; use gettextrs::*; use mlx9061x::Error as MlxError; use std::env; +use std::ops::Deref; use std::panic; +use std::process; use std::sync::Arc; use systemstat::Duration; use tokio::runtime::UnhandledPanic; @@ -77,32 +79,34 @@ async fn start() -> Result<(), ModuleError> { let watchdog_enabled = config.get_bool("watchdog/enable"); let ping_enabled = config.get_bool("ping/enable"); - // use std::ops::Deref; // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log - // panic::set_hook(Box::new(|panic_info| { - // let (filename, line) = panic_info - // .location() - // .map(|loc| (loc.file(), loc.line())) - // .unwrap_or(("", 0)); - // let cause = panic_info - // .payload() - // .downcast_ref::() - // .map(String::deref); - // let cause = cause.unwrap_or_else(|| { - // panic_info - // .payload() - // .downcast_ref::<&str>() - // .map(|s| *s) - // .unwrap_or("") - // }); - // let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); - // nextcloud_sender // <--- Doesn't live long enough - // .send(NextcloudEvent::Chat( - // NextcloudChat::Ping, - // text.clone(), - // )); - // eprintln!("{}", text); - // })); + panic::set_hook(Box::new(|panic_info| { + let (filename, line) = panic_info + .location() + .map(|loc| (loc.file(), loc.line())) + .unwrap_or(("", 0)); + let cause = panic_info + .payload() + .downcast_ref::() + .map(String::deref); + let cause = cause.unwrap_or_else(|| { + panic_info + .payload() + .downcast_ref::<&str>() + .map(|s| *s) + .unwrap_or("") + }); + let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); + /* + nextcloud_sender // <--- Doesn't live long enough + .send(NextcloudEvent::Chat( + NextcloudChat::Ping, + text.clone(), + )); + */ + eprintln!("{}", text); + process::exit(0x0100); + })); let mut tasks = vec![]; From 9b7697aa49f20970fe96721e09076814d35ac132 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Fri, 22 Dec 2023 15:36:41 +0100 Subject: [PATCH 47/59] try to send ping msg on panics --- src/main.rs | 21 +++++++++++++-------- src/nextcloud.rs | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 52a29a5..78c237a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,14 @@ async fn start() -> Result<(), ModuleError> { // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log panic::set_hook(Box::new(|panic_info| { + struct Exit; + impl Drop for Exit { + fn drop(&mut self) { + process::exit(0x0100); + } + } + let _exit = Exit; + let (filename, line) = panic_info .location() .map(|loc| (loc.file(), loc.line())) @@ -97,15 +105,12 @@ async fn start() -> Result<(), ModuleError> { .unwrap_or("") }); let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); - /* - nextcloud_sender // <--- Doesn't live long enough - .send(NextcloudEvent::Chat( - NextcloudChat::Ping, - text.clone(), - )); - */ eprintln!("{}", text); - process::exit(0x0100); + let mut config = Config::new(CONFIG_PARENT); + let nextcloud = Nextcloud::new(&mut config); + futures::executor::block_on(async { + nextcloud.ping(text.clone()).await; + }); })); let mut tasks = vec![]; diff --git a/src/nextcloud.rs b/src/nextcloud.rs index d07eb7c..fa8f000 100644 --- a/src/nextcloud.rs +++ b/src/nextcloud.rs @@ -104,7 +104,7 @@ impl Nextcloud { }; } - async fn ping(&self, message: String) { + pub async fn ping(&self, message: String) { let result = self.send_message_once(&message, &self.chat_ping).await; match result { From cb9ba376ccb38f131c92c7131e0fbf46f97b0019 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 06:59:47 +0100 Subject: [PATCH 48/59] debugging panic hook --- src/main.rs | 2 ++ src/signals.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main.rs b/src/main.rs index 78c237a..fcfc591 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,9 +81,11 @@ async fn start() -> Result<(), ModuleError> { // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log panic::set_hook(Box::new(|panic_info| { + eprintln!("Enter Panic Hook"); struct Exit; impl Drop for Exit { fn drop(&mut self) { + eprintln!("Exit Panic Hook"); process::exit(0x0100); } } diff --git a/src/signals.rs b/src/signals.rs index 225d749..f92f572 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -204,6 +204,7 @@ impl<'a> Signals<'a> { if self.environment_enabled { self.sigterm().await?; } + panic!("Sigterm received"); } } } From 0b24670f83487f3bf9e35f66d181983115e440cd Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 07:03:05 +0100 Subject: [PATCH 49/59] minor fix in translation + update line numbers --- files/opensesame.mo | Bin 6693 -> 6687 bytes lang/de_AT.po | 60 ++++++++++++++++++++++---------------------- lang/opensesame.pot | 58 +++++++++++++++++++++--------------------- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/files/opensesame.mo b/files/opensesame.mo index 09b5306dfee1870fedbccdf18190f5b3ffa06ac9..5311d6aa63aeded02b1ee92b81417acda863a29c 100644 GIT binary patch delta 241 zcmXZWzY76z7{~D^1_Kk_IfFVsB3+@JLH>Z-m>6sZ>4r<)U~q%k><>^%veEqmR;x`h zu_%9ljrTXE*Ynip^Ym=&mA$`4=1mcKYa%7A>LMog(84KZag7B$Vjdq@##mY;jx|*I zHs)}Qs<-&>TgrFG`CuJ&S`BniJsO~i2UNK;R`7}HkyN;g Y4w4DiGy4;N=6c@9UtY9g*wSCoFDgnRP5=M^ delta 228 zcmXZWu?j(97{>7@CzCAd9Oo2uP$UbT?^sMG6LuyS;0}~rfx!is6oXP{a0iT5gUv+B zYV`kN`n_*G&)d5;8*{j&<{e2NSE{1%q!7p0z!?^CixoU!8J}3gY+lM>j5goJ5>CtFzlq IBJbsV0gqoD7ytkO diff --git a/lang/de_AT.po b/lang/de_AT.po index bf0b543..979ad03 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-15 13:48+0000\n" +"POT-Creation-Date: 2023-12-23 06:02+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -47,39 +47,39 @@ msgstr "🔋 An {}%" msgid "🔋 Battery Capacity is back to {}%" msgstr "🔋 Batterieladung ist zurück bei {}%" -#: src/buttons.rs:513 +#: src/buttons.rs:514 msgid "{} {}" msgstr "" -#: src/buttons.rs:533 +#: src/buttons.rs:534 msgid "🔔 Pressed button bell." msgstr "🔔 Knopf für Glocke gedrückt." -#: src/buttons.rs:542 +#: src/buttons.rs:543 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Knopf gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:554 +#: src/buttons.rs:555 msgid "💡 Pressed switch inside. {}." msgstr "💡 Taster innen gedrückt. {}." -#: src/buttons.rs:565 +#: src/buttons.rs:566 msgid "💡 Pressed light button. {}." msgstr "💡 Licht-Knopf außen gedrückt. {}." -#: src/buttons.rs:578 +#: src/buttons.rs:579 msgid "🔔 Pressed switch bell." msgstr "🔔 Taster Glocke gedrückt." -#: src/buttons.rs:587 +#: src/buttons.rs:588 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Taster außen gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:601 +#: src/buttons.rs:602 msgid "🕶️ Light was turned off." msgstr "🕶️ Licht wurde abgeschalten." -#: src/buttons.rs:611 +#: src/buttons.rs:612 msgid "" "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: " "{}, Swap: {}, CPU temp: {}" @@ -87,25 +87,25 @@ msgstr "" "⚠️ Fehler beim Lesen der Knöpfe am Board {}. Load average: {} {} {}, Memory " "usage: {}, Swap: {}, CPU temp: {}" -#: src/buttons.rs:623 +#: src/buttons.rs:624 msgid "🤗 Opened for {}" msgstr "🤗 Für {} geöffnet" -#: src/buttons.rs:639 +#: src/buttons.rs:640 msgid "💡 Switch lights in and out. {}" msgstr "💡 Schalte Licht innen und außen ein. {}" -#: src/buttons.rs:649 +#: src/buttons.rs:650 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" "🕶️ Schalte Lichter nicht ein, da es Tag ist. Jetzt: {} Sonnenaufgang: {} " "Sonnenuntergang: {}" -#: src/buttons.rs:665 +#: src/buttons.rs:666 msgid "⌛ Timeout with sequence {}" msgstr "⌛ Timeout mit Sequenz {}" -#: src/buttons.rs:676 +#: src/buttons.rs:677 msgid "⌛ Sequence {} too long" msgstr "⌛ Zu lange Sequenz {}" @@ -136,60 +136,60 @@ msgstr "" msgid "⚠️ Error from weather station: {}" msgstr "⚠️ Ein Fehler ist beim ausführen der Wetterstation aufgetreten: {}" -#: src/environment.rs:394 +#: src/environment.rs:400 msgid "⚠️ Error {:#02b} reading environment! Status: {:#02b}. {}" msgstr "" "⚠️ Fehler {:#02b} beim Lesen vom Environment-Sensor! Status: {:#02b}. {}" -#: src/environment.rs:408 +#: src/environment.rs:414 msgid "💨 Airquality is ok. {}" msgstr "💨 Luftqualität ist ok. {}" -#: src/environment.rs:416 +#: src/environment.rs:422 msgid "💩 Airquality is moderate. {}" msgstr "💩 Luftqualität ist moderat. {}" -#: src/environment.rs:424 +#: src/environment.rs:430 msgid "💩 Airquality is bad! {}" msgstr "💩 Luftqualität ist schlecht! {}" -#: src/environment.rs:437 +#: src/environment.rs:443 msgid "🚨 Possible fire alarm! Ring bell once! ⏰. {}" msgstr "🚨 Mögicher Feuer-Alarm! Läute Glocke 1x! ⏰. {}" -#: src/environment.rs:452 +#: src/environment.rs:458 msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "🚨 Möglicher Feueralarm! (läute noch nicht). {}" -#: src/haustuer.rs:66 +#: src/haustuer.rs:74 msgid "Board 58 with error {}" msgstr "Brett 58 mit Fehler {}" -#: src/haustuer.rs:118 +#: src/haustuer.rs:127 msgid "💡 Light far outdoor pressed." msgstr "💡 Licht am Vorgartenzaun gedrückt." -#: src/haustuer.rs:125 +#: src/haustuer.rs:134 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." -#: src/haustuer.rs:133 +#: src/haustuer.rs:142 msgid "🔔 Bell far outdoor pressed." msgstr "🔔 Taste für Glocke Vorgarten gedrückt." -#: src/haustuer.rs:144 +#: src/haustuer.rs:153 msgid "💡 Indoor light pressed." msgstr "💡 Taster Licht innen gedrückt." -#: src/haustuer.rs:151 +#: src/haustuer.rs:160 msgid "💡 Pressed in entrance. Switch all lights." -msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." +msgstr "💡 Knopf im Vorzimmer gedrückt. Schalte Licht ein." -#: src/haustuer.rs:159 +#: src/haustuer.rs:168 msgid "⚠️ Error on {}, will do reset." msgstr "⚠️ Ein Fehler auf {} ist aufgetreten" -#: src/haustuer.rs:166 +#: src/haustuer.rs:175 msgid "👋 RST of MOD-IO done." msgstr "👋 RST von MOD-IO durchgeführt." diff --git a/lang/opensesame.pot b/lang/opensesame.pot index 138e209..a1e1092 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-15 13:48+0000\n" +"POT-Creation-Date: 2023-12-23 06:02+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -45,59 +45,59 @@ msgstr "" msgid "🔋 Battery Capacity is back to {}%" msgstr "" -#: src/buttons.rs:513 +#: src/buttons.rs:514 msgid "{} {}" msgstr "" -#: src/buttons.rs:533 +#: src/buttons.rs:534 msgid "🔔 Pressed button bell." msgstr "" -#: src/buttons.rs:542 +#: src/buttons.rs:543 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:554 +#: src/buttons.rs:555 msgid "💡 Pressed switch inside. {}." msgstr "" -#: src/buttons.rs:565 +#: src/buttons.rs:566 msgid "💡 Pressed light button. {}." msgstr "" -#: src/buttons.rs:578 +#: src/buttons.rs:579 msgid "🔔 Pressed switch bell." msgstr "" -#: src/buttons.rs:587 +#: src/buttons.rs:588 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:601 +#: src/buttons.rs:602 msgid "🕶️ Light was turned off." msgstr "" -#: src/buttons.rs:611 +#: src/buttons.rs:612 msgid "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: {}, Swap: {}, CPU temp: {}" msgstr "" -#: src/buttons.rs:623 +#: src/buttons.rs:624 msgid "🤗 Opened for {}" msgstr "" -#: src/buttons.rs:639 +#: src/buttons.rs:640 msgid "💡 Switch lights in and out. {}" msgstr "" -#: src/buttons.rs:649 +#: src/buttons.rs:650 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" -#: src/buttons.rs:665 +#: src/buttons.rs:666 msgid "⌛ Timeout with sequence {}" msgstr "" -#: src/buttons.rs:676 +#: src/buttons.rs:677 msgid "⌛ Sequence {} too long" msgstr "" @@ -125,59 +125,59 @@ msgstr "" msgid "⚠️ Error from weather station: {}" msgstr "" -#: src/environment.rs:394 +#: src/environment.rs:400 msgid "⚠️ Error {:#02b} reading environment! Status: {:#02b}. {}" msgstr "" -#: src/environment.rs:408 +#: src/environment.rs:414 msgid "💨 Airquality is ok. {}" msgstr "" -#: src/environment.rs:416 +#: src/environment.rs:422 msgid "💩 Airquality is moderate. {}" msgstr "" -#: src/environment.rs:424 +#: src/environment.rs:430 msgid "💩 Airquality is bad! {}" msgstr "" -#: src/environment.rs:437 +#: src/environment.rs:443 msgid "🚨 Possible fire alarm! Ring bell once! ⏰. {}" msgstr "" -#: src/environment.rs:452 +#: src/environment.rs:458 msgid "🚨 Possible fire alarm! (don't ring yet). {}" msgstr "" -#: src/haustuer.rs:66 +#: src/haustuer.rs:74 msgid "Board 58 with error {}" msgstr "" -#: src/haustuer.rs:118 +#: src/haustuer.rs:127 msgid "💡 Light far outdoor pressed." msgstr "" -#: src/haustuer.rs:125 +#: src/haustuer.rs:134 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "" -#: src/haustuer.rs:133 +#: src/haustuer.rs:142 msgid "🔔 Bell far outdoor pressed." msgstr "" -#: src/haustuer.rs:144 +#: src/haustuer.rs:153 msgid "💡 Indoor light pressed." msgstr "" -#: src/haustuer.rs:151 +#: src/haustuer.rs:160 msgid "💡 Pressed in entrance. Switch all lights." msgstr "" -#: src/haustuer.rs:159 +#: src/haustuer.rs:168 msgid "⚠️ Error on {}, will do reset." msgstr "" -#: src/haustuer.rs:166 +#: src/haustuer.rs:175 msgid "👋 RST of MOD-IO done." msgstr "" From fccc2d0df7a82630e75dd8ac765ecec5e255b349 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 07:09:40 +0100 Subject: [PATCH 50/59] try to exit within block_on --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fcfc591..4dcf873 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,7 +86,7 @@ async fn start() -> Result<(), ModuleError> { impl Drop for Exit { fn drop(&mut self) { eprintln!("Exit Panic Hook"); - process::exit(0x0100); + process::exit(1); } } let _exit = Exit; @@ -112,6 +112,7 @@ async fn start() -> Result<(), ModuleError> { let nextcloud = Nextcloud::new(&mut config); futures::executor::block_on(async { nextcloud.ping(text.clone()).await; + process::exit(2); }); })); From 3b46f55e5c2185d19c646bfd4a2f5ae305a65302 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 07:11:02 +0100 Subject: [PATCH 51/59] add even more debug --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4dcf873..9071ab7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,9 @@ async fn start() -> Result<(), ModuleError> { let mut config = Config::new(CONFIG_PARENT); let nextcloud = Nextcloud::new(&mut config); futures::executor::block_on(async { + eprintln!("Before Ping"); nextcloud.ping(text.clone()).await; + eprintln!("After Ping"); process::exit(2); }); })); From 3d42edd1ebb8c0516b3f3aae73da492565674593 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 08:22:22 +0100 Subject: [PATCH 52/59] do proper sync implementation of try_ping --- Cargo.toml | 2 +- src/main.rs | 17 ++++++++--------- src/nextcloud.rs | 32 +++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b52bfff..988ee1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ i2cdev = "0.5.1" elektra = { version = "0.11.0", features = ["pkg-config"] } -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.11", features = ["json", "blocking"] } bme280 = "0.3.0" mlx9061x = "0.2.1" diff --git a/src/main.rs b/src/main.rs index 9071ab7..9c5cf19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ use opensesame::environment::{EnvEvent, Environment}; use opensesame::garage::Garage; use opensesame::haustuer::Haustuer; use opensesame::mod_ir_temp::ModIR; -use opensesame::nextcloud::{Nextcloud, NextcloudChat, NextcloudEvent}; +use opensesame::nextcloud::{try_ping, Nextcloud, NextcloudChat, NextcloudEvent}; use opensesame::ping::{Ping, PingEvent}; use opensesame::pwr::Pwr; use opensesame::sensors::Sensors; @@ -107,15 +107,14 @@ async fn start() -> Result<(), ModuleError> { .unwrap_or("") }); let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); - eprintln!("{}", text); + // eprintln!("{}", text); let mut config = Config::new(CONFIG_PARENT); - let nextcloud = Nextcloud::new(&mut config); - futures::executor::block_on(async { - eprintln!("Before Ping"); - nextcloud.ping(text.clone()).await; - eprintln!("After Ping"); - process::exit(2); - }); + match try_ping(&mut config, text.clone()) { + Ok(_response) => (), + Err(error) => { + eprintln!("Couldn't set status message {} because {}", text, error); + } + } })); let mut tasks = vec![]; diff --git a/src/nextcloud.rs b/src/nextcloud.rs index fa8f000..71be8df 100644 --- a/src/nextcloud.rs +++ b/src/nextcloud.rs @@ -46,6 +46,36 @@ pub struct Nextcloud { startup_time: String, } +fn get_headers() -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + headers.insert(ACCEPT, "application/json".parse().unwrap()); + headers.insert("OCS-APIRequest", "true".parse().unwrap()); + return headers; +} + +pub fn try_ping( + config: &mut Config, + message: String, +) -> Result { + let mut payload = HashMap::new(); + payload.insert("token", config.get::("nextcloud/chat/ping")); + payload.insert("message", message); + reqwest::blocking::Client::new() + .post(format!( + "{}/ocs/v2.php/apps/spreed/api/v1/chat/{}", + config.get::("nextcloud/url"), + config.get::("nextcloud/chat/ping") + )) + .basic_auth( + config.get::("nextcloud/user"), + Some(config.get::("nextcloud/pass")), + ) + .headers(get_headers()) + .json(&payload) + .send() +} + impl Nextcloud { pub fn new(config: &mut Config) -> Self { let mut headers = HeaderMap::new(); @@ -65,7 +95,7 @@ impl Nextcloud { info_environment: String::new(), info_online: String::new(), client, - headers, + headers: get_headers(), startup_time: String::new(), } } From 6eee7ff85e50560e52725a4fdaf3c20dd1d3d356 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sat, 23 Dec 2023 08:54:55 +0100 Subject: [PATCH 53/59] remove debug --- lang/opensesame.pot | 4 ++-- src/main.rs | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lang/opensesame.pot b/lang/opensesame.pot index a1e1092..d71ff6d 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-23 06:02+0000\n" +"POT-Creation-Date: 2023-12-23 07:54+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -201,7 +201,7 @@ msgstr "" msgid "⚠️ Error while handling ModIR: {}" msgstr "" -#: src/nextcloud.rs:243 +#: src/nextcloud.rs:273 msgid "👋 Opensesame {} init {}" msgstr "" diff --git a/src/main.rs b/src/main.rs index 9c5cf19..3069894 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,11 +81,9 @@ async fn start() -> Result<(), ModuleError> { // // https://stackoverflow.com/questions/42456497/stdresultresult-panic-to-log panic::set_hook(Box::new(|panic_info| { - eprintln!("Enter Panic Hook"); struct Exit; impl Drop for Exit { fn drop(&mut self) { - eprintln!("Exit Panic Hook"); process::exit(1); } } @@ -107,7 +105,6 @@ async fn start() -> Result<(), ModuleError> { .unwrap_or("") }); let text = gettext!("A panic occurred at {}:{}: {}", filename, line, cause); - // eprintln!("{}", text); let mut config = Config::new(CONFIG_PARENT); match try_ping(&mut config, text.clone()) { Ok(_response) => (), From 45a1a7ad9edb29fb61b9b7c945934a94bf5b905c Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 24 Dec 2023 07:01:55 +0100 Subject: [PATCH 54/59] implement multi-press for indoor schalter --- files/opensesame.mo | Bin 6687 -> 6841 bytes lang/de_AT.po | 26 +++++++++++++++----------- lang/opensesame.pot | 22 +++++++++++++--------- src/buttons.rs | 2 +- src/haustuer.rs | 29 ++++++++++++++++++++++------- 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/files/opensesame.mo b/files/opensesame.mo index 5311d6aa63aeded02b1ee92b81417acda863a29c..80ba8531c8a21a3d25484ae7a75955b9ce02c860 100644 GIT binary patch delta 1294 zcmX}sTS(JU9Ki9PxlP-wEp4;3bWTgNbegkF6Eh<5Qkq>z31Zoxf4L2|q)=>75kwKe zpP~y9Aq71Ife;i0K^RH&5ENw(K@Wisg+bAUUi$ua>EPMt{LcUU|L5+_z{AGG$9&5r zAvKeik-ub#^y1@een`J9A|CvM>(FHtS%4jwhr4kE58xVnk4w;MOMR~dR}ivljHKfWxRm%V z`tcdo;rHb8gh+*5q?C#_)Cc=f8(vKN6ibM|p|*26M9R>Q`r#d@9Unn`eg-S>4)P~2 z`O){^p|<~-*2VJW)4x7UB=ondU7@4X_fch@%+8 zE2vxOp!Xi!j-7ZNwf-{>U=^d(_+)`3WD|ucD)a!_7K=1tJNDx!YKO1ThqI_l>2Rm4 z#s=a})c3|w+daUQID@^Y)73N7m-amB^A{f0-%DYRiq+_1n!3~*u^b0cKX?Kw@fPY* zPNTMei+UEaIC1)3IcnUFy4ORfTRDz8kSPqJn}^!&*e(k6EmyG)@1xG>6E>oo>3gvo zwcRl4o}NM-$UV%$d1Ou6rrdmzT^Q7j)6Jnr(Ywsr|4%w4J)!}!Ud~KvqF_r0dLo<2 zezJ~?`=7jb%s4rM2D8yp+PQ%!ld37`m@-K(1D7oMZ$ayH#dXni;+dq2$|gyzdBaj% zww_Xb<`L=&c*!|rZlA23oUx2q9ot5Rj~X?7u~0m2p0n4Q`|Mk6M&w{L8k?N3S2)~8 z*t;hh8#Th=P|O<+9g2m6!*SE;DKgJ`@^a(xP{bQDBIYA^)M`W`p~z&F=U4VW9xsJf delta 1214 zcmX}rPe{{Y9LMpmZF4$vmD4S=a?Z?Z=CpKbQi)}v36lLIIw?fZQ7VE#qv#JFI{nz8 zQxrl32GtG`bchPHtV{Ro;E=>imm&{h@6YyI4|{&E=Xv%#&+q$t{=DgY)RA7O@@9S;)zI*g*eB#k?9#{GXD8>p|KCakO|yr3C1z8`nt1oE@{JT%@x^?&91 z1*@npVIA+cRSGAuhV>l8aXf*~a0mWEZ9$NASL99Dis!H$?_vmFqb8omy|{o(ZDm2T z8*FPeYMuw13iD56nm)Edfp^#{rm%Fg*?zo@5qyDK$~jbki?|2lTg)c$3~K9UaRdWI zF@)z)?T_&S=G^)bqV1!8D`aUqMBzOR-MEHhn5-_ma0+A8r%_8e>$-#osrzaQ<9bm2 zCUG}rP-o^XcH&>Ry_L_8Qa_7vydGx#wZuxa5ka+BgxOgbvXR8Bz)rKD@WkF29oOxhhb!y29E-nxb)B`rfSbx_b%@{_q`)}CGV brhHB&Fyh<^)MnQL!3yVMcq02D{KxYTCU|o6 diff --git a/lang/de_AT.po b/lang/de_AT.po index 979ad03..d3e5870 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-23 06:02+0000\n" +"POT-Creation-Date: 2023-12-24 06:00+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -165,31 +165,35 @@ msgstr "🚨 Möglicher Feueralarm! (läute noch nicht). {}" msgid "Board 58 with error {}" msgstr "Brett 58 mit Fehler {}" -#: src/haustuer.rs:127 +#: src/haustuer.rs:129 msgid "💡 Light far outdoor pressed." msgstr "💡 Licht am Vorgartenzaun gedrückt." -#: src/haustuer.rs:134 +#: src/haustuer.rs:136 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." -#: src/haustuer.rs:142 +#: src/haustuer.rs:144 msgid "🔔 Bell far outdoor pressed." msgstr "🔔 Taste für Glocke Vorgarten gedrückt." -#: src/haustuer.rs:153 +#: src/haustuer.rs:155 msgid "💡 Indoor light pressed." msgstr "💡 Taster Licht innen gedrückt." -#: src/haustuer.rs:160 -msgid "💡 Pressed in entrance. Switch all lights." -msgstr "💡 Knopf im Vorzimmer gedrückt. Schalte Licht ein." +#: src/haustuer.rs:164 +msgid "💡 Multi-Press in entrance. Switch all lights." +msgstr "💡 Knopf im Vorzimmer mehrmals gedrückt. Schalte Licht innen und aussen ein." -#: src/haustuer.rs:168 +#: src/haustuer.rs:173 +msgid "💡 Pressed in entrance. Switch indoor lights." +msgstr "💡 Knopf im Vorzimmer gedrückt. Schalte Licht innen ein." + +#: src/haustuer.rs:183 msgid "⚠️ Error on {}, will do reset." msgstr "⚠️ Ein Fehler auf {} ist aufgetreten" -#: src/haustuer.rs:175 +#: src/haustuer.rs:190 msgid "👋 RST of MOD-IO done." msgstr "👋 RST von MOD-IO durchgeführt." @@ -213,7 +217,7 @@ msgstr "🌡 ModIR warnung wurde entfernt! Ambient: {} °C, Objekt: {} °C" msgid "⚠️ Error while handling ModIR: {}" msgstr "⚠️ Ein Fehler ist bei der Behandlung von ModIR aufgetreten: {}" -#: src/nextcloud.rs:243 +#: src/nextcloud.rs:273 msgid "👋 Opensesame {} init {}" msgstr "👋 Opensesame {} init {}" diff --git a/lang/opensesame.pot b/lang/opensesame.pot index d71ff6d..1898ec8 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-23 07:54+0000\n" +"POT-Creation-Date: 2023-12-24 06:00+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -153,31 +153,35 @@ msgstr "" msgid "Board 58 with error {}" msgstr "" -#: src/haustuer.rs:127 +#: src/haustuer.rs:129 msgid "💡 Light far outdoor pressed." msgstr "" -#: src/haustuer.rs:134 +#: src/haustuer.rs:136 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "" -#: src/haustuer.rs:142 +#: src/haustuer.rs:144 msgid "🔔 Bell far outdoor pressed." msgstr "" -#: src/haustuer.rs:153 +#: src/haustuer.rs:155 msgid "💡 Indoor light pressed." msgstr "" -#: src/haustuer.rs:160 -msgid "💡 Pressed in entrance. Switch all lights." +#: src/haustuer.rs:164 +msgid "💡 Multi-Press in entrance. Switch all lights." msgstr "" -#: src/haustuer.rs:168 +#: src/haustuer.rs:173 +msgid "💡 Pressed in entrance. Switch indoor lights." +msgstr "" + +#: src/haustuer.rs:183 msgid "⚠️ Error on {}, will do reset." msgstr "" -#: src/haustuer.rs:175 +#: src/haustuer.rs:190 msgid "👋 RST of MOD-IO done." msgstr "" diff --git a/src/buttons.rs b/src/buttons.rs index 8e405a4..3ab438c 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -72,7 +72,7 @@ pub enum CommandToButtons { OpenDoor, RingBell(u32, u32), // maybe implement it with interval RingBellAlarm(u32), - SwitchLights(bool, bool, String), + SwitchLights(bool, bool, String), // inside, outside, message } const BELL_MINIMUM_PERIOD: u32 = 20; // = 200ms shortest period time for bell diff --git a/src/haustuer.rs b/src/haustuer.rs index 63ee418..11ba3c3 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -117,7 +117,9 @@ impl Haustuer { ) -> Result { let mut interval = interval(Duration::from_millis(30)); let mut rst = Rst::new(); + let mut indoor_counter = 0; loop { + indoor_counter += 1; match haustuer.handle() { HaustuerChange::None => (), HaustuerChange::LightFarOutdoor => { @@ -153,13 +155,26 @@ impl Haustuer { gettext("💡 Indoor light pressed."), )) .await?; - command_sender - .send(CommandToButtons::SwitchLights( - true, - true, - gettext("💡 Pressed in entrance. Switch all lights."), - )) - .await?; + if indoor_counter < 50 { + // multi-click detected (within 1.5 sec) + command_sender + .send(CommandToButtons::SwitchLights( + true, + true, + gettext("💡 Multi-Press in entrance. Switch all lights."), + )) + .await?; + } else { + // normal click or first click + command_sender + .send(CommandToButtons::SwitchLights( + true, + false, + gettext("💡 Pressed in entrance. Switch indoor lights."), + )) + .await?; + } + indoor_counter = 0; // reset } HaustuerChange::Err(err) => { nextcloud_sender From 25992c0459a7104ff611d6bc300fa3103d497cde Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 24 Dec 2023 07:35:26 +0100 Subject: [PATCH 55/59] improve permanent logic let caller decide if permanent should be possible --- lang/opensesame.pot | 44 ++++++++++++++++++++++---------------------- src/buttons.rs | 22 +++++++++++++--------- src/garage.rs | 2 ++ src/haustuer.rs | 3 +++ src/nextcloud.rs | 1 + 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/lang/opensesame.pot b/lang/opensesame.pot index 1898ec8..c38ceee 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-24 06:00+0000\n" +"POT-Creation-Date: 2023-12-24 06:35+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -45,59 +45,59 @@ msgstr "" msgid "🔋 Battery Capacity is back to {}%" msgstr "" -#: src/buttons.rs:514 +#: src/buttons.rs:515 msgid "{} {}" msgstr "" -#: src/buttons.rs:534 +#: src/buttons.rs:538 msgid "🔔 Pressed button bell." msgstr "" -#: src/buttons.rs:543 +#: src/buttons.rs:547 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:555 +#: src/buttons.rs:559 msgid "💡 Pressed switch inside. {}." msgstr "" -#: src/buttons.rs:566 +#: src/buttons.rs:570 msgid "💡 Pressed light button. {}." msgstr "" -#: src/buttons.rs:579 +#: src/buttons.rs:583 msgid "🔔 Pressed switch bell." msgstr "" -#: src/buttons.rs:588 +#: src/buttons.rs:592 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:602 +#: src/buttons.rs:606 msgid "🕶️ Light was turned off." msgstr "" -#: src/buttons.rs:612 +#: src/buttons.rs:616 msgid "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: {}, Swap: {}, CPU temp: {}" msgstr "" -#: src/buttons.rs:624 +#: src/buttons.rs:628 msgid "🤗 Opened for {}" msgstr "" -#: src/buttons.rs:640 +#: src/buttons.rs:644 msgid "💡 Switch lights in and out. {}" msgstr "" -#: src/buttons.rs:650 +#: src/buttons.rs:654 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" -#: src/buttons.rs:666 +#: src/buttons.rs:670 msgid "⌛ Timeout with sequence {}" msgstr "" -#: src/buttons.rs:677 +#: src/buttons.rs:681 msgid "⌛ Sequence {} too long" msgstr "" @@ -157,31 +157,31 @@ msgstr "" msgid "💡 Light far outdoor pressed." msgstr "" -#: src/haustuer.rs:136 +#: src/haustuer.rs:137 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "" -#: src/haustuer.rs:144 +#: src/haustuer.rs:145 msgid "🔔 Bell far outdoor pressed." msgstr "" -#: src/haustuer.rs:155 +#: src/haustuer.rs:156 msgid "💡 Indoor light pressed." msgstr "" -#: src/haustuer.rs:164 +#: src/haustuer.rs:166 msgid "💡 Multi-Press in entrance. Switch all lights." msgstr "" -#: src/haustuer.rs:173 +#: src/haustuer.rs:176 msgid "💡 Pressed in entrance. Switch indoor lights." msgstr "" -#: src/haustuer.rs:183 +#: src/haustuer.rs:186 msgid "⚠️ Error on {}, will do reset." msgstr "" -#: src/haustuer.rs:190 +#: src/haustuer.rs:193 msgid "👋 RST of MOD-IO done." msgstr "" diff --git a/src/buttons.rs b/src/buttons.rs index 3ab438c..a0e32e3 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -72,7 +72,7 @@ pub enum CommandToButtons { OpenDoor, RingBell(u32, u32), // maybe implement it with interval RingBellAlarm(u32), - SwitchLights(bool, bool, String), // inside, outside, message + SwitchLights(bool, bool, bool, String), // inside, outside, permanent, message } const BELL_MINIMUM_PERIOD: u32 = 20; // = 200ms shortest period time for bell @@ -432,8 +432,8 @@ impl Buttons { /// returns what was done /// usually extends light time - /// on double press event (on true) -> make light permanent on (until next press event) - pub fn switch_lights(&mut self, inside: bool, outside: bool) -> String { + /// if permanent==true: on double press event (on true) -> make light permanent on (until next press event) + pub fn switch_lights(&mut self, inside: bool, outside: bool, permanent: bool) -> String { assert!( inside || outside, "logic error, at least one must be switched on!" @@ -458,7 +458,7 @@ impl Buttons { self.light_permanent = false; self.light_timeout = 30; // turn off soon return format!("Light {} not permanent anymore", which); - } else if inside && self.light_timeout > init_light_timeout - 200 { + } else if permanent && self.light_timeout > init_light_timeout - 200 { self.light_permanent = true; ret = "Light now permanently on".to_string(); } else if self.light_timeout > 1 { @@ -507,11 +507,15 @@ impl Buttons { CommandToButtons::RingBell(period, counter) => { self.ring_bell(period, counter); } - CommandToButtons::SwitchLights(inside, outside, text) => { + CommandToButtons::SwitchLights(inside, outside, permanent, text) => { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Licht, - gettext!("{} {}", self.switch_lights(inside, outside), text), + gettext!( + "{} {}", + self.switch_lights(inside, outside, permanent), + text + ), )) .await?; } @@ -553,7 +557,7 @@ impl Buttons { NextcloudChat::Licht, gettext!( "💡 Pressed switch inside. {}.", - self.switch_lights(true, true) + self.switch_lights(true, true, true) ), )) .await?; @@ -564,7 +568,7 @@ impl Buttons { NextcloudChat::Licht, gettext!( "💡 Pressed light button. {}.", - self.switch_lights(false, true), + self.switch_lights(false, true, false), ), )) .await?; @@ -638,7 +642,7 @@ impl Buttons { NextcloudChat::Licht, gettext!( "💡 Switch lights in and out. {}", - self.switch_lights(true, true) + self.switch_lights(true, true, false) ), )) .await?; diff --git a/src/garage.rs b/src/garage.rs index 8b055f6..04d41f3 100644 --- a/src/garage.rs +++ b/src/garage.rs @@ -165,6 +165,7 @@ impl Garage { .send(CommandToButtons::SwitchLights( true, false, + true, "💡 Pressed at entrance top switch. Switch lights in garage" .to_string(), )) @@ -173,6 +174,7 @@ impl Garage { GarageChange::PressedTasterTorOben => { command_sender .send(CommandToButtons::SwitchLights( + true, true, true, "💡 Pressed top switch at garage door. Switch lights in and out garage" diff --git a/src/haustuer.rs b/src/haustuer.rs index 11ba3c3..f678427 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -133,6 +133,7 @@ impl Haustuer { .send(CommandToButtons::SwitchLights( false, true, + false, gettext("💡 Pressed at entrance switch. Switch lights."), )) .await?; @@ -161,6 +162,7 @@ impl Haustuer { .send(CommandToButtons::SwitchLights( true, true, + false, gettext("💡 Multi-Press in entrance. Switch all lights."), )) .await?; @@ -170,6 +172,7 @@ impl Haustuer { .send(CommandToButtons::SwitchLights( true, false, + false, gettext("💡 Pressed in entrance. Switch indoor lights."), )) .await?; diff --git a/src/nextcloud.rs b/src/nextcloud.rs index 71be8df..8732370 100644 --- a/src/nextcloud.rs +++ b/src/nextcloud.rs @@ -355,6 +355,7 @@ impl Nextcloud { .send(CommandToButtons::SwitchLights( inner_light, outer_light, + false, // TODO: should be also an argument of switchlights String::from("Switch light"), )) .await?; From 66ba3ba2d3107b5e4b335f33a3aba62c00a50351 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 24 Dec 2023 07:55:27 +0100 Subject: [PATCH 56/59] fix that outside lights actually work --- lang/de_AT.po | 48 ++++++++++++++++++++++----------------------- lang/opensesame.pot | 32 +++++++++++++++--------------- src/buttons.rs | 4 ++++ src/haustuer.rs | 4 ++-- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/lang/de_AT.po b/lang/de_AT.po index d3e5870..7085a7e 100644 --- a/lang/de_AT.po +++ b/lang/de_AT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: opensesame 0.7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-24 06:00+0000\n" +"POT-Creation-Date: 2023-12-24 06:54+0000\n" "PO-Revision-Date: 2022-10-02 13:40+0200\n" "Last-Translator: Markus Raab \n" "Language-Team: German \n" @@ -47,39 +47,39 @@ msgstr "🔋 An {}%" msgid "🔋 Battery Capacity is back to {}%" msgstr "🔋 Batterieladung ist zurück bei {}%" -#: src/buttons.rs:514 +#: src/buttons.rs:519 msgid "{} {}" msgstr "" -#: src/buttons.rs:534 +#: src/buttons.rs:542 msgid "🔔 Pressed button bell." msgstr "🔔 Knopf für Glocke gedrückt." -#: src/buttons.rs:543 +#: src/buttons.rs:551 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Knopf gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:555 +#: src/buttons.rs:563 msgid "💡 Pressed switch inside. {}." msgstr "💡 Taster innen gedrückt. {}." -#: src/buttons.rs:566 +#: src/buttons.rs:574 msgid "💡 Pressed light button. {}." msgstr "💡 Licht-Knopf außen gedrückt. {}." -#: src/buttons.rs:579 +#: src/buttons.rs:587 msgid "🔔 Pressed switch bell." msgstr "🔔 Taster Glocke gedrückt." -#: src/buttons.rs:588 +#: src/buttons.rs:596 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "🔕 Läute Glocke nicht (Taster außen gedrückt) weil Uhrzeit 🌜 ist {}, {}" -#: src/buttons.rs:602 +#: src/buttons.rs:610 msgid "🕶️ Light was turned off." msgstr "🕶️ Licht wurde abgeschalten." -#: src/buttons.rs:612 +#: src/buttons.rs:620 msgid "" "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: " "{}, Swap: {}, CPU temp: {}" @@ -87,25 +87,25 @@ msgstr "" "⚠️ Fehler beim Lesen der Knöpfe am Board {}. Load average: {} {} {}, Memory " "usage: {}, Swap: {}, CPU temp: {}" -#: src/buttons.rs:624 +#: src/buttons.rs:632 msgid "🤗 Opened for {}" msgstr "🤗 Für {} geöffnet" -#: src/buttons.rs:640 +#: src/buttons.rs:648 msgid "💡 Switch lights in and out. {}" msgstr "💡 Schalte Licht innen und außen ein. {}" -#: src/buttons.rs:650 +#: src/buttons.rs:658 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" "🕶️ Schalte Lichter nicht ein, da es Tag ist. Jetzt: {} Sonnenaufgang: {} " "Sonnenuntergang: {}" -#: src/buttons.rs:666 +#: src/buttons.rs:674 msgid "⌛ Timeout with sequence {}" msgstr "⌛ Timeout mit Sequenz {}" -#: src/buttons.rs:677 +#: src/buttons.rs:685 msgid "⌛ Sequence {} too long" msgstr "⌛ Zu lange Sequenz {}" @@ -169,31 +169,31 @@ msgstr "Brett 58 mit Fehler {}" msgid "💡 Light far outdoor pressed." msgstr "💡 Licht am Vorgartenzaun gedrückt." -#: src/haustuer.rs:136 +#: src/haustuer.rs:137 msgid "💡 Pressed at entrance switch. Switch lights." msgstr "💡 Knopf beim Vorgartenzaun gedrückt. Schalte Licht ein." -#: src/haustuer.rs:144 +#: src/haustuer.rs:145 msgid "🔔 Bell far outdoor pressed." msgstr "🔔 Taste für Glocke Vorgarten gedrückt." -#: src/haustuer.rs:155 +#: src/haustuer.rs:156 msgid "💡 Indoor light pressed." msgstr "💡 Taster Licht innen gedrückt." -#: src/haustuer.rs:164 -msgid "💡 Multi-Press in entrance. Switch all lights." -msgstr "💡 Knopf im Vorzimmer mehrmals gedrückt. Schalte Licht innen und aussen ein." +#: src/haustuer.rs:166 +msgid "💡 Multi-Press in entrance. Switch outdoor lights." +msgstr "💡 Knopf im Vorzimmer mehrmals gedrückt. Schalte Licht aussen ein." -#: src/haustuer.rs:173 +#: src/haustuer.rs:176 msgid "💡 Pressed in entrance. Switch indoor lights." msgstr "💡 Knopf im Vorzimmer gedrückt. Schalte Licht innen ein." -#: src/haustuer.rs:183 +#: src/haustuer.rs:186 msgid "⚠️ Error on {}, will do reset." msgstr "⚠️ Ein Fehler auf {} ist aufgetreten" -#: src/haustuer.rs:190 +#: src/haustuer.rs:193 msgid "👋 RST of MOD-IO done." msgstr "👋 RST von MOD-IO durchgeführt." diff --git a/lang/opensesame.pot b/lang/opensesame.pot index c38ceee..58ff265 100644 --- a/lang/opensesame.pot +++ b/lang/opensesame.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-24 06:35+0000\n" +"POT-Creation-Date: 2023-12-24 06:54+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -45,59 +45,59 @@ msgstr "" msgid "🔋 Battery Capacity is back to {}%" msgstr "" -#: src/buttons.rs:515 +#: src/buttons.rs:519 msgid "{} {}" msgstr "" -#: src/buttons.rs:538 +#: src/buttons.rs:542 msgid "🔔 Pressed button bell." msgstr "" -#: src/buttons.rs:547 +#: src/buttons.rs:551 msgid "🔕 Did not ring bell (button was pressed) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:559 +#: src/buttons.rs:563 msgid "💡 Pressed switch inside. {}." msgstr "" -#: src/buttons.rs:570 +#: src/buttons.rs:574 msgid "💡 Pressed light button. {}." msgstr "" -#: src/buttons.rs:583 +#: src/buttons.rs:587 msgid "🔔 Pressed switch bell." msgstr "" -#: src/buttons.rs:592 +#: src/buttons.rs:596 msgid "🔕 Did not ring bell (taster outside) because the time 🌜 is {}, {}" msgstr "" -#: src/buttons.rs:606 +#: src/buttons.rs:610 msgid "🕶️ Light was turned off." msgstr "" -#: src/buttons.rs:616 +#: src/buttons.rs:620 msgid "⚠️ Error reading buttons of board {}. Load average: {} {} {}, Memory usage: {}, Swap: {}, CPU temp: {}" msgstr "" -#: src/buttons.rs:628 +#: src/buttons.rs:632 msgid "🤗 Opened for {}" msgstr "" -#: src/buttons.rs:644 +#: src/buttons.rs:648 msgid "💡 Switch lights in and out. {}" msgstr "" -#: src/buttons.rs:654 +#: src/buttons.rs:658 msgid "🕶️ Don't switch lights as its day. Now: {} Sunrise: {} Sunset: {}" msgstr "" -#: src/buttons.rs:670 +#: src/buttons.rs:674 msgid "⌛ Timeout with sequence {}" msgstr "" -#: src/buttons.rs:681 +#: src/buttons.rs:685 msgid "⌛ Sequence {} too long" msgstr "" @@ -170,7 +170,7 @@ msgid "💡 Indoor light pressed." msgstr "" #: src/haustuer.rs:166 -msgid "💡 Multi-Press in entrance. Switch all lights." +msgid "💡 Multi-Press in entrance. Switch outdoor lights." msgstr "" #: src/haustuer.rs:176 diff --git a/src/buttons.rs b/src/buttons.rs index a0e32e3..43de29b 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -475,6 +475,10 @@ impl Buttons { self.board21 .smbus_write_byte_data(SET_RELAYS_ON, RELAY_LICHT_INNEN) .unwrap(); + } else if outside { + self.board21 + .smbus_write_byte_data(SET_RELAYS_ON, RELAY_LICHT_AUSSEN) + .unwrap(); } ret } diff --git a/src/haustuer.rs b/src/haustuer.rs index f678427..1e7e547 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -160,10 +160,10 @@ impl Haustuer { // multi-click detected (within 1.5 sec) command_sender .send(CommandToButtons::SwitchLights( - true, + false, true, false, - gettext("💡 Multi-Press in entrance. Switch all lights."), + gettext("💡 Multi-Press in entrance. Switch outdoor lights."), )) .await?; } else { From 7563f70b02a8d7e01ee4bdd309d62222e88c853e Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Sun, 24 Dec 2023 08:57:52 +0100 Subject: [PATCH 57/59] longer time for double presses --- src/haustuer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/haustuer.rs b/src/haustuer.rs index 1e7e547..d8b5bf1 100644 --- a/src/haustuer.rs +++ b/src/haustuer.rs @@ -117,7 +117,7 @@ impl Haustuer { ) -> Result { let mut interval = interval(Duration::from_millis(30)); let mut rst = Rst::new(); - let mut indoor_counter = 0; + let mut indoor_counter = 100; loop { indoor_counter += 1; match haustuer.handle() { @@ -153,11 +153,11 @@ impl Haustuer { nextcloud_sender .send(NextcloudEvent::Chat( NextcloudChat::Licht, - gettext("💡 Indoor light pressed."), + gettext!("💡 Indoor light pressed {}.", indoor_counter), )) .await?; - if indoor_counter < 50 { - // multi-click detected (within 1.5 sec) + if indoor_counter < 100 { + // multi-click detected (within 3 sec) command_sender .send(CommandToButtons::SwitchLights( false, From 913d7ebe39212197b5f3657786bc2feacc4e44c8 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 26 Mar 2024 09:39:57 +0100 Subject: [PATCH 58/59] wait longer for MOD-IO to settle --- src/pwr.rs | 5 ++--- src/watchdog.rs | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pwr.rs b/src/pwr.rs index 25fd382..d9cee23 100644 --- a/src/pwr.rs +++ b/src/pwr.rs @@ -12,7 +12,6 @@ use gettextrs::gettext; use crate::config::Config; use crate::types::ModuleError; -use crate::watchdog; const GPIO_PWR_LINE: u32 = 202; // UEXT1 (e.g. LIME-2 Shield) UART4-TX GPIO202 PG10 @@ -75,7 +74,7 @@ impl Pwr { gettext("👋 Turned PWR switch OFF"), )) .await?; - sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; + sleep(Duration::from_secs(30)).await; self.switch(true); nextcloud_sender @@ -84,7 +83,7 @@ impl Pwr { gettext("👋 Turned PWR switch ON"), )) .await?; - sleep(Duration::from_millis(watchdog::SAFE_TIMEOUT)).await; + sleep(Duration::from_secs(10)).await; } Ok(()) } diff --git a/src/watchdog.rs b/src/watchdog.rs index ae07a3b..6dce4ea 100644 --- a/src/watchdog.rs +++ b/src/watchdog.rs @@ -4,7 +4,8 @@ use tokio::{fs::File, io::AsyncWriteExt, time::Interval}; use crate::types::ModuleError; -pub const SAFE_TIMEOUT: u64 = 15 * 1000; // safe to wait if trigger was done just before +// irrelevant, as watchdog trigger happens async +// pub const SAFE_TIMEOUT: u64 = 15 * 1000; // safe to wait if trigger was done just before pub struct Watchdog {} From 86744e2b67ab78f9b348191525d575ace4f575a5 Mon Sep 17 00:00:00 2001 From: Markus Raab Date: Tue, 26 Mar 2024 09:51:36 +0100 Subject: [PATCH 59/59] RestartSec --- debian/service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/service b/debian/service index b9e018e..10849d1 100644 --- a/debian/service +++ b/debian/service @@ -2,6 +2,7 @@ Description=opensesame Wants=network-online.target nss-lookup.target After=network.target network-online.target nss-lookup.target +StartLimitIntervalSec=0 [Service] Type=simple @@ -18,6 +19,7 @@ IOSchedulingClass=realtime IOSchedulingPriority=0 Restart=always +RestartSec=1s ExecStart=/usr/bin/opensesame [Install]