Skip to content

Commit

Permalink
Add configurable thresholds for sensor data which will generate alert…
Browse files Browse the repository at this point in the history
… conditions.

Signed-off-by: Brian Bradley <brian.bradley.p@gmail.com>
  • Loading branch information
bpbradley committed Jan 26, 2022
1 parent d641f20 commit e113d88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(app LANGUAGES C VERSION 0.2.0)
project(app LANGUAGES C VERSION 0.2.1)

configure_file(app_version.h.in ${CMAKE_BINARY_DIR}/app/include/app_version.h)
target_include_directories(app PRIVATE ${CMAKE_BINARY_DIR}/app/include src)
Expand Down
22 changes: 22 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ config PYRRHA_FCB_MAGIC
Magic 32-bit word for to identify valid settings area
endmenu

menu "alerts"

config CO_ALERT_THRESHOLD_PPM
int "Threshold in ppm for co alerts"
range 1 1000
default 420
help
Threshold in PPM for CO level when an alert is generated.
420ppm is the AEGL2 10 minute limit.
config NO2_ALERT_THRESHOLD_PPM
int "Threshold in ppm for no2 alerts"
range 1 100
default 8
help
Threshold in PPM for NO2 level when an alert is generated.
20ppm is the AEGL2 10 minute limit.
config TEMPERATURE_ALERT_THRESHOLD_CELCIUS
int "Threshold in celcius for temperature alerts"
range 60 120
default 80
endmenu

config PYRRHA_SAMPLE_PERIOD
int "Period (in seconds) of sensor data collection"
range 1 300
Expand Down
16 changes: 16 additions & 0 deletions app/src/alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
#include <alerts.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(alerts, CONFIG_PYRRHA_LOG_LEVEL);
#define OVER_TEMPERATURE(temp) (temp > CONFIG_TEMPERATURE_ALERT_THRESHOLD_CELCIUS)
#define OVER_CO(co) (co > CONFIG_CO_ALERT_THRESHOLD_PPM)
#define OVER_NO2(no2) (no2 > CONFIG_NO2_ALERT_THRESHOLD_PPM)

/**
* @brief generate an alert from sensor data exceeding set thresholds
*/
static void threshold_alert(void){
return;
}
int generate_alerts(struct pyrrha_data * data){
if (OVER_TEMPERATURE(data->rht.temperature.val1) ||
OVER_CO(data->gas.co.val1) ||
OVER_NO2(data->gas.no2.val1))
{
threshold_alert();
}
return 0;
}

0 comments on commit e113d88

Please sign in to comment.