Skip to content

Commit

Permalink
samples: cellular: nrf_cloud_multi_service: Button press alert
Browse files Browse the repository at this point in the history
Extend the multi service sample by adding button handling.

When the button is pressed, send an alert to the cloud.

Signed-off-by: Pete Skeggs <[email protected]>
  • Loading branch information
plskeggs authored and rlubos committed Sep 26, 2024
1 parent b38111c commit c6b8384
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/cellular/nrf_cloud_multi_service/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CONFIG_EVENTS=y
CONFIG_PICOLIBC_IO_FLOAT=y
CONFIG_RESET_ON_FATAL_ERROR=y
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_DK_LIBRARY=y

# LED indication
# Uncomment these to minimize LED state indication when power savings are necessary
Expand Down
13 changes: 13 additions & 0 deletions samples/cellular/nrf_cloud_multi_service/src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <modem/location.h>
#include "location_tracking.h"
#endif
#include <dk_buttons_and_leds.h>
#include "application.h"
#include "temperature.h"
#include "cloud_connection.h"
Expand Down Expand Up @@ -322,6 +323,16 @@ static void test_counter_send(void)
}
}

static void button_handler(uint32_t button_state, uint32_t has_changed)
{
if (has_changed & DK_BTN1_MSK) {
if ((button_state & DK_BTN1_MSK) == DK_BTN1_MSK) {
LOG_INF("Button pressed");
(void)nrf_cloud_alert_send(ALERT_TYPE_MSG, 0, "Button pressed");
}
}
}

static void print_reset_reason(void)
{
uint32_t reset_reason;
Expand Down Expand Up @@ -352,6 +363,8 @@ void main_application_thread_fn(void)
register_general_dev_msg_handler(handle_at_cmd_requests);
}

dk_buttons_init(button_handler);

/* Wait for first connection before starting the application. */
(void)await_cloud_ready(K_FOREVER);

Expand Down

0 comments on commit c6b8384

Please sign in to comment.