mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-04 01:44:18 +00:00
added HOTSPOT_IDS as an env var to enable hotspot with
This commit is contained in:
parent
56981d5f23
commit
b6b66a7e5b
@ -14,3 +14,4 @@ Environment variables:
|
|||||||
- `PM3_BIN`: Path to the pm3 binary. Seach in path if not set. Can also be set to the `pm3_mock.sh` for testing.
|
- `PM3_BIN`: Path to the pm3 binary. Seach in path if not set. Can also be set to the `pm3_mock.sh` for testing.
|
||||||
- `LOG_LEVEL`: Can be set to either "debug","warn","error","trace" or "info". Defaults to "warn" in production.
|
- `LOG_LEVEL`: Can be set to either "debug","warn","error","trace" or "info". Defaults to "warn" in production.
|
||||||
- `HTTP_PORT`: What port to listen on. Defaults to 80.
|
- `HTTP_PORT`: What port to listen on. Defaults to 80.
|
||||||
|
- `HOTSPOT_IDS`: A semicolon seperated list of ids to activate the hotspot with e.g. `578B5DF2;c1532b57`.
|
||||||
|
30
src/main.rs
30
src/main.rs
@ -1,5 +1,5 @@
|
|||||||
use buzzer::GPIOBuzzer;
|
use buzzer::GPIOBuzzer;
|
||||||
use id_store::IDStore;
|
use id_store::{IDStore, TallyID};
|
||||||
use led::Led;
|
use led::Led;
|
||||||
use log::{LevelFilter, debug, error, info, warn};
|
use log::{LevelFilter, debug, error, info, warn};
|
||||||
use pm3::run_pm3;
|
use pm3::run_pm3;
|
||||||
@ -79,14 +79,30 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
Arc::new(Mutex::new(GPIOBuzzer::new(PWM_CHANNEL_BUZZER)?));
|
Arc::new(Mutex::new(GPIOBuzzer::new(PWM_CHANNEL_BUZZER)?));
|
||||||
let status_led: Arc<Mutex<Led>> = Arc::new(Mutex::new(Led::new()?));
|
let status_led: Arc<Mutex<Led>> = Arc::new(Mutex::new(Led::new()?));
|
||||||
|
|
||||||
|
let hotspot_ids: Vec<TallyID> = env::var("HOTSPOT_IDS")
|
||||||
|
.map(|ids| ids.split(";").map(|id| TallyID(id.to_owned())).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if hotspot_ids.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"HOTSPOT_IDS is not set or empty. You will not be able to activate the hotspot via a tally!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let channel_store = store.clone();
|
let channel_store = store.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(tally_id_string) = rx.recv().await {
|
while let Some(tally_id_string) = rx.recv().await {
|
||||||
if channel_store
|
let tally_id = id_store::TallyID(tally_id_string);
|
||||||
.lock()
|
|
||||||
.await
|
if hotspot_ids.contains(&tally_id) {
|
||||||
.add_id(id_store::TallyID(tally_id_string))
|
info!("Enableing hotspot");
|
||||||
{
|
hotspot::enable_hotspot().await.unwrap_or_else(|err| {
|
||||||
|
error!("Hotspot: {err}");
|
||||||
|
});
|
||||||
|
// TODO: Should the ID be added anyway or ignored ?
|
||||||
|
}
|
||||||
|
|
||||||
|
if channel_store.lock().await.add_id(tally_id) {
|
||||||
info!("Added new id to current day");
|
info!("Added new id to current day");
|
||||||
|
|
||||||
gpio_buzzer
|
gpio_buzzer
|
||||||
@ -105,8 +121,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
error!("Failed to blink LED {}", e);
|
error!("Failed to blink LED {}", e);
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO Hotspot command
|
|
||||||
|
|
||||||
if let Err(e) = channel_store.lock().await.export_json(STORE_PATH).await {
|
if let Err(e) = channel_store.lock().await.export_json(STORE_PATH).await {
|
||||||
error!("Failed to save id store to file: {}", e);
|
error!("Failed to save id store to file: {}", e);
|
||||||
// TODO: How to handle a failure to save ?
|
// TODO: How to handle a failure to save ?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user