-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b19d40
commit 4ffff67
Showing
8 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/fota.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Copyright (c) 20224 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menuconfig APP_FOTA | ||
bool "FOTA" | ||
select FOTA | ||
default y if !BOARD_NATIVE_POSIX | ||
|
||
if APP_FOTA | ||
|
||
module = APP_FOTA | ||
module-str = FOTA | ||
source "subsys/logging/Kconfig.template.log_config" | ||
|
||
endif # APP_FOTA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/logging/log_ctrl.h> | ||
#include <zephyr/zbus/zbus.h> | ||
#include <net/nrf_cloud_coap.h> | ||
#include <net/nrf_cloud_fota_poll.h> | ||
#include <zephyr/sys/reboot.h> | ||
|
||
#include "message_channel.h" | ||
|
||
/* Register log module */ | ||
LOG_MODULE_REGISTER(fota, CONFIG_APP_FOTA_LOG_LEVEL); | ||
|
||
/* FOTA support context */ | ||
static void fota_reboot(enum nrf_cloud_fota_reboot_status status); | ||
static struct nrf_cloud_fota_poll_ctx ctx = { | ||
.reboot_fn = fota_reboot | ||
}; | ||
|
||
void fota_reboot(enum nrf_cloud_fota_reboot_status status) | ||
{ | ||
LOG_INF("Rebooting with FOTA status %d", status); | ||
|
||
/* TODO: disconnect from network? */ | ||
|
||
/* Flush the logging buffers */ | ||
LOG_PANIC(); | ||
|
||
/* Reboot the device */ | ||
sys_reboot(SYS_REBOOT_COLD); | ||
} | ||
|
||
|
||
void fota_callback(const struct zbus_channel *chan) | ||
{ | ||
int err = 0; | ||
|
||
if (&CLOUD_CHAN == chan) | ||
{ | ||
enum cloud_status status = CLOUD_DISCONNECTED; | ||
int err = zbus_chan_read(chan, &status, K_NO_WAIT); | ||
|
||
if (!err && status == CLOUD_CONNECTED) | ||
{ | ||
err = nrf_cloud_fota_poll_init(&ctx); | ||
if (err) { | ||
LOG_ERR("nrf_cloud_fota_poll_init failed: %d", err); | ||
return; | ||
/* TODO: can we recover from this? */ | ||
} | ||
|
||
/* Process pending FOTA job, the FOTA type is returned */ | ||
err = nrf_cloud_fota_poll_process_pending(&ctx); | ||
if (err < 0) { | ||
LOG_ERR("nrf_cloud_fota_poll_process_pending failed: %d", err); | ||
} else if (err != NRF_CLOUD_FOTA_TYPE__INVALID) { | ||
LOG_INF("Processed pending FOTA job type: %d", err); | ||
} | ||
} | ||
} | ||
if (&TRIGGER_CHAN == chan) | ||
{ | ||
err = nrf_cloud_fota_poll_process(&ctx); | ||
if (err && err != -EAGAIN) { | ||
LOG_ERR("nrf_cloud_fota_poll_process failed: %d", err); | ||
} | ||
} | ||
} | ||
|
||
|
||
/* Register listener - led_callback will be called everytime a channel that the module listens on | ||
* receives a new message. | ||
*/ | ||
ZBUS_LISTENER_DEFINE(fota, fota_callback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters