Skip to content

Commit

Permalink
Update sensors VOC
Browse files Browse the repository at this point in the history
  • Loading branch information
blavka committed Dec 21, 2020
1 parent ca19617 commit 79306eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
52 changes: 32 additions & 20 deletions app/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,18 +436,24 @@ static void _sensor_sgp30_event_handler(twr_sgp30_t *self, twr_sgp30_event_t eve

if ((event == TWR_SGP30_EVENT_UPDATE) && twr_sgp30_get_tvoc_ppb(self, &value))
{
int tvoc = value;
if (ctx->attr->channel == TWR_RADIO_PUB_CHANNEL_R1_I2C0_ADDRESS_DEFAULT)
if ((fabs(value - ctx->value) >= VOC_PUB_VALUE_CHANGE) || (ctx->next_pub < twr_tick_get()))
{
twr_radio_pub_int("voc-sensor/0:0/tvoc", &tvoc);
}
else
{
twr_radio_pub_int("voc-sensor/1:0/tvoc", &tvoc);
}
int tvoc = value;
if (ctx->attr->channel == TWR_RADIO_PUB_CHANNEL_R1_I2C0_ADDRESS_DEFAULT)
{
twr_radio_pub_int("voc-sensor/0:0/tvoc", &tvoc);
}
else
{
twr_radio_pub_int("voc-sensor/1:0/tvoc", &tvoc);
}

ctx->value = value;
ctx->next_pub = twr_tick_get() + VOC_PUB_NO_CHANGE_INTERVAL;

values.voc = value;
_sensor_event_pub(ctx);
values.voc = value;
_sensor_event_pub(ctx);
}
}
else if (event == TWR_SGP30_EVENT_ERROR)
{
Expand All @@ -464,18 +470,24 @@ static void _sensor_sgpc3_event_handler(twr_sgpc3_t *self, twr_sgpc3_event_t eve

if ((event == TWR_SGPC3_EVENT_UPDATE) && twr_sgpc3_get_tvoc_ppb(self, &value))
{
int tvoc = value;
if (ctx->attr->channel == TWR_RADIO_PUB_CHANNEL_R1_I2C0_ADDRESS_DEFAULT)
if ((fabs(value - ctx->value) >= VOC_PUB_VALUE_CHANGE) || (ctx->next_pub < twr_tick_get()))
{
twr_radio_pub_int("voc-lp-sensor/0:0/tvoc", &tvoc);
}
else
{
twr_radio_pub_int("voc-lp-sensor/1:0/tvoc", &tvoc);
}
int tvoc = value;
if (ctx->attr->channel == TWR_RADIO_PUB_CHANNEL_R1_I2C0_ADDRESS_DEFAULT)
{
twr_radio_pub_int("voc-lp-sensor/0:0/tvoc", &tvoc);
}
else
{
twr_radio_pub_int("voc-lp-sensor/1:0/tvoc", &tvoc);
}

ctx->value = value;
ctx->next_pub = twr_tick_get() + VOC_PUB_NO_CHANGE_INTERVAL;

values.voc = value;
_sensor_event_pub(ctx);
values.voc = value;
_sensor_event_pub(ctx);
}
}
else if (event == TWR_SGPC3_EVENT_ERROR)
{
Expand Down
2 changes: 2 additions & 0 deletions app/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define BAROMETER_PUB_VALUE_CHANGE 50.0f
#define BAROMETER_UPDATE_INTERVAL (1 * 60 * 1000)

#define VOC_PUB_NO_CHANGE_INTERVAL (15 * 60 * 1000)
#define VOC_PUB_VALUE_CHANGE 50.0f
#define VOC_UPDATE_INTERVAL (30 * 1000)


Expand Down

0 comments on commit 79306eb

Please sign in to comment.