Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Commit

Permalink
fix: updated button trigger handler
Browse files Browse the repository at this point in the history
Cloud publications triggered by button pushes are now
limited to 1 publication per 2 seconds. This is to avoid
spamming on the cloud socket where the socket returns
POLLERR(socket error) if publications are triggered
extremely frequently.

Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
  • Loading branch information
simensrostad committed Mar 25, 2020
1 parent f76de71 commit 393297d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/gps_controller/gps_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static void start(struct k_work *work)
return;
}

ui_led_set_pattern(UI_LED_GPS_SEARCHING);

err = gps_start(gps_dev, &gps_cfg);
if (err) {
LOG_ERR("Failed to enable GPS, error: %d", err);
Expand Down
17 changes: 14 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ static void gps_trigger_handler(struct device *dev, struct gps_event *evt)
switch (evt->type) {
case GPS_EVT_SEARCH_STARTED:
LOG_INF("GPS_EVT_SEARCH_STARTED");
ui_led_set_pattern(UI_LED_GPS_SEARCHING);
break;
case GPS_EVT_SEARCH_STOPPED:
LOG_INF("GPS_EVT_SEARCH_STOPPED");
Expand Down Expand Up @@ -787,8 +786,12 @@ static int modem_data_init(void)

static void button_handler(u32_t button_states, u32_t has_changed)
{
static int try_again_timeout;

if (has_changed & button_states & DK_BTN1_MSK) {
/* Publication of data due to button presses limited
* to 1 push every 2 seconds to avoid spamming the cloud socket. */
if ((has_changed & button_states & DK_BTN1_MSK) &&
k_uptime_get() - try_again_timeout > K_SECONDS(2)) {

int err = lte_connection_check();
if (err) {
Expand All @@ -797,15 +800,23 @@ static void button_handler(u32_t button_states, u32_t has_changed)
}

if (k_sem_count_get(&cloud_conn_sem) && cloud_connected) {

LOG_INF("Cloud publication by button 1 triggered, ");
LOG_INF("2 seconds to next allowed cloud publication ");
LOG_INF("triggered by button 1");

cloud_data.btn_number = 1;
cloud_data.btn_ts = k_uptime_get();
k_delayed_work_submit(&cloud_button_message_send_work,
K_NO_WAIT);
k_delayed_work_submit(&led_device_mode_set_work,
K_SECONDS(5));
K_SECONDS(3));
}

try_again_timeout = k_uptime_get();
}


#if defined(CONFIG_BOARD_NRF9160_PCA10090NS)
/* Fake motion. The nRF9160 DK does not have an accelerometer by
* default. Reset accelerometer data.
Expand Down

0 comments on commit 393297d

Please sign in to comment.