Skip to content

Commit

Permalink
modules: trigger: Don't schedule triggers immediately in normal mode
Browse files Browse the repository at this point in the history
When entering normal mode, schedule triggers after the respective
timeouts, not immediately.

This fix prevents the trigger module from firing triggers every time
the GNSS is disabled in normal mode.
This issue occurs when a trigger is sent, and GNSS finishes sampling,
causing an endless loop of back-and-forth triggers instead of
returning to the expected interval.

Signed-off-by: Simen S. Røstad <[email protected]>
  • Loading branch information
simensrostad committed Aug 12, 2024
1 parent 68eab32 commit 00709f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions app/src/modules/trigger/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ static void normal_entry(void *o)
LOG_DBG("Sending FOTA poll triggers every %d seconds",
CONFIG_APP_TRIGGER_FOTA_POLL_INTERVAL_SEC);

k_work_reschedule(&trigger_work, K_NO_WAIT);
k_work_reschedule(&trigger_fota_poll_work, K_NO_WAIT);
k_work_reschedule(&trigger_work, K_SECONDS(user_object->update_interval_used_sec));
k_work_reschedule(&trigger_fota_poll_work,
K_SECONDS(CONFIG_APP_TRIGGER_FOTA_POLL_INTERVAL_SEC));
}

static void normal_run(void *o)
Expand Down
17 changes: 11 additions & 6 deletions tests/module/trigger/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ static void go_to_normal_state(void)
go_to_frequent_poll_state();
send_frequent_poll_duration_timer_expiry();
check_trigger_mode_event(TRIGGER_MODE_NORMAL);
check_trigger_event(TRIGGER_DATA_SAMPLE);
check_trigger_event(TRIGGER_POLL);
check_trigger_event(TRIGGER_FOTA_POLL);
}

void test_init_to_frequent_poll(void)
Expand Down Expand Up @@ -228,11 +225,14 @@ void test_frequent_poll_to_normal(void)

/* Then */
check_trigger_mode_event(TRIGGER_MODE_NORMAL);
/* Verify that one more trigger event was sent when entering normal mode. */
check_no_trigger_events(CONFIG_APP_TRIGGER_TIMEOUT_SECONDS - 10);

k_sleep(K_SECONDS(10));

check_trigger_event(TRIGGER_DATA_SAMPLE);
check_trigger_event(TRIGGER_POLL);
check_trigger_event(TRIGGER_FOTA_POLL);
check_no_trigger_events(FREQUENT_POLL_TRIGGER_INTERVAL_SEC * 10);

/* Cleanup */
send_cloud_disconnected();
}
Expand Down Expand Up @@ -334,10 +334,15 @@ void test_frequent_poll_to_blocked_to_normal(void)

/* Then */
check_trigger_mode_event(TRIGGER_MODE_NORMAL);
check_no_trigger_events(CONFIG_APP_TRIGGER_TIMEOUT_SECONDS - 10);

k_sleep(K_SECONDS(10));

check_trigger_event(TRIGGER_DATA_SAMPLE);
check_trigger_event(TRIGGER_POLL);
check_trigger_event(TRIGGER_FOTA_POLL);
check_no_trigger_events(FREQUENT_POLL_TRIGGER_INTERVAL_SEC * 10);

check_no_trigger_events(CONFIG_APP_TRIGGER_TIMEOUT_SECONDS - 10);

/* Cleanup */
send_cloud_disconnected();
Expand Down

0 comments on commit 00709f0

Please sign in to comment.