Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ target_sources(app PRIVATE
src/main.c
)

# Add modules subdirectories
# Include modules
add_subdirectory(src/modules/controller)
add_subdirectory(src/modules/sensor)
add_subdirectory(src/modules/network)
add_subdirectory(src/modules/cloud)

# Add include directories for modules
target_include_directories(app PRIVATE src)
3 changes: 3 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rsource "src/modules/controller/Kconfig.controller"
# Include network module configuration
rsource "src/modules/network/Kconfig.network"

# Include cloud module configuration
rsource "src/modules/cloud/Kconfig.cloud"

endmenu

module = APP
Expand Down
60 changes: 58 additions & 2 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#
# This file contains selected Kconfig options for the application.

# Enable logging with debug level
# CONFIG_NET_LOG=y
# CONFIG_NRF_CLOUD_LOG_LEVEL_DBG=y
# CONFIG_CLOUD_MODULE_LOG_LEVEL_DBG=y
# CONFIG_NRF_CLOUD_COAP_LOG_LEVEL_DBG=y
# CONFIG_MODEM_KEY_MGMT_LOG_LEVEL_DBG=y
# CONFIG_LOG_BUFFER_SIZE=10000

CONFIG_LOG=y
CONFIG_BLINK=y
CONFIG_HEAP_MEM_POOL_SIZE=10240
Expand Down Expand Up @@ -45,7 +53,6 @@ CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_LC_PSM_MODULE=y
CONFIG_LTE_LC_EDRX_MODULE=y
CONFIG_LTE_LC_CONN_EVAL_MODULE=y
CONFIG_MODEM_INFO=y

# Nordic Modem Library
CONFIG_NRF_MODEM_LIB=y
Expand All @@ -67,13 +74,60 @@ CONFIG_NET_IPV6_MLD=n
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=512

# Needed due to using connectivity manager
CONFIG_NET_IF_MAX_IPV6_COUNT=2
CONFIG_NET_IF_MAX_IPV4_COUNT=2

# Network statistics (useful for debugging)
CONFIG_NET_STATISTICS=y
CONFIG_NET_STATISTICS_USER_API=y
CONFIG_NET_CONTEXT_SYNC_RECV=y

# nRF Cloud
CONFIG_NRF_CLOUD=y
CONFIG_NRF_CLOUD_COAP=y
CONFIG_NRF_CLOUD_COAP_DISCONNECT_ON_FAILED_REQUEST=y
CONFIG_NRF_CLOUD_PRINT_DETAILS=y
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS=y
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK=y
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_SIM=y
CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA=y

# Modem
CONFIG_MODEM_JWT=y
CONFIG_MODEM_INFO=y
CONFIG_MODEM_INFO_ADD_DEVICE=y
CONFIG_MODEM_KEY_MGMT=y


# Credentials
CONFIG_NRF_CLOUD_CLIENT_ID_SRC_IMEI=y # Use IMEI for Client ID as INTERNAL_UUID requires nRF91x1
CONFIG_NRF_CLOUD_CHECK_CREDENTIALS=y
CONFIG_NRF_CLOUD_CREDENTIALS_MGMT_MODEM=y

# COAP client
CONFIG_COAP=y
CONFIG_COAP_CLIENT=y
CONFIG_COAP_MAX_RETRANSMIT=5
CONFIG_COAP_INIT_ACK_TIMEOUT_MS=5000
# Set CoAP therad to same priority as other modules
CONFIG_COAP_CLIENT_THREAD_PRIORITY=14
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
CONFIG_COAP_CLIENT_MESSAGE_SIZE=1024
CONFIG_COAP_CLIENT_STACK_SIZE=1280
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=192
CONFIG_NRF_CLOUD_COAP_DOWNLOADS=y

# Downloader support (required by NRF_CLOUD_COAP_DOWNLOADS)
CONFIG_DOWNLOADER=y

# needed for processing floats
CONFIG_PICOLIBC=y
CONFIG_FPU=y

# Date and time configuration
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_MODEM=y
CONFIG_DATE_TIME_AUTO_UPDATE=y

# AT Monitor configuration to prevent heap exhaustion
Expand All @@ -90,4 +144,6 @@ CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=2048
CONFIG_AT_SHELL=y

# Task Watchdog
CONFIG_TASK_WDT=y
CONFIG_TASK_WDT=y
CONFIG_TASK_WDT_CHANNELS=8
CONFIG_TASK_WDT_MIN_TIMEOUT=10000
91 changes: 91 additions & 0 deletions app/src/app_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef _APP_COMMON_H_
#define _APP_COMMON_H_

#include <zephyr/kernel.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/sys/util.h> /* For Zephyr's utility macros, including MAX */
#if defined(CONFIG_MEMFAULT)
#include <memfault/panics/assert.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

/** @brief Handle fatal error.
* @param is_watchdog_timeout Boolean indicating if the macro was called upon a watchdog timeout.
*/
#define FATAL_ERROR_HANDLE(is_watchdog_timeout) \
do { \
LOG_PANIC(); \
if (is_watchdog_timeout) { \
IF_ENABLED(CONFIG_MEMFAULT, (MEMFAULT_SOFTWARE_WATCHDOG())); \
} \
k_sleep(K_SECONDS(10)); \
__ASSERT(false, "SEND_FATAL_ERROR() macro called"); \
} while (0)

/** @brief Macro used to handle fatal errors. */
#define SEND_FATAL_ERROR() FATAL_ERROR_HANDLE(0)

/** @brief Macro used to handle watchdog timeouts. */
#define SEND_FATAL_ERROR_WATCHDOG_TIMEOUT() FATAL_ERROR_HANDLE(1)

/* Helper macros for computing MAX with different numbers of arguments */
#define MAX_1(a1) (a1)
#define MAX_2(a1, a2) MAX(a1, a2)
#define MAX_3(a1, a2, a3) MAX(MAX_2(a1, a2), a3)
#define MAX_4(a1, a2, a3, a4) MAX(MAX_3(a1, a2, a3), a4)
#define MAX_5(a1, a2, a3, a4, a5) MAX(MAX_4(a1, a2, a3, a4), a5)
#define MAX_6(a1, a2, a3, a4, a5, a6) MAX(MAX_5(a1, a2, a3, a4, a5), a6)
#define MAX_7(a1, a2, a3, a4, a5, a6, a7) MAX(MAX_6(a1, a2, a3, a4, a5, a6), a7)
#define MAX_8(a1, a2, a3, a4, a5, a6, a7, a8) MAX(MAX_7(a1, a2, a3, a4, a5, a6, a7), a8)
#define MAX_9(a1, a2, a3, a4, a5, a6, a7, a8, a9) MAX(MAX_8(a1, a2, a3, a4, a5, a6, a7, a8), a9)
#define MAX_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
MAX(MAX_9(a1, a2, a3, a4, a5, a6, a7, a8, a9), a10)

#define SELECT_MAX_N(N) CONCAT(MAX_, N)

/**
* @brief Macro to compute the maximum of a list of numbers.
*
* @param ... List of numbers to compute the maximum of.
*/
#define MAX_N(...) SELECT_MAX_N(NUM_VA_ARGS(__VA_ARGS__))(__VA_ARGS__)

/**
* @brief Helper macro for computing the size of a type.
* The intended use is with X macros to generate a list of sizes for each type in a list of types.
*
* @param _chan Channel to compute the size of the type for.
* @param _type Type to compute the size of.
*
* @return Size of the type.
*/
#define SIZE_OF_TYPE(_chan, _type) sizeof(_type),

/**
* @brief Macro to compute the maximum message size from a list of channel date types.
* The macro expands to a list of sizeof(type) for each channel's type, followed by a 0 to
* account for the trailing comma when expanding SIZE_OF_TYPE
* The MAX_N macro is used to find the maximum value in the list.
* Example: MAX_N(sizeof(struct cloud_msg), sizeof(enum fota_msg_type), 0)

* @param _CHAN_LIST List of channels to compute the maximum message size from.
* The list should be in the format: (CHANNEL_NAME, type)
*
* @return Maximum message size from the list of channels
*/
#define MAX_MSG_SIZE_FROM_LIST(_CHAN_LIST) MAX_N(_CHAN_LIST(SIZE_OF_TYPE) 0)

#ifdef __cplusplus
}
#endif

#endif /* _APP_COMMON_H_ */
45 changes: 0 additions & 45 deletions app/src/app_fatal_error.h

This file was deleted.

15 changes: 15 additions & 0 deletions app/src/modules/cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cloud_module.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cloud_shell.c)
target_include_directories(app PRIVATE .)

if (CONFIG_NRF_CLOUD_COAP_SEC_TAG GREATER_EQUAL 2147483648 AND CONFIG_NRF_CLOUD_COAP_SEC_TAG LESS_EQUAL 2147483667)
message(WARNING "CONFIG_NRF_CLOUD_COAP_SEC_TAG is set to a developer security tag. "
"TLS traffic can now be decrypted with Nordic tools. "
"This should only be used during development and testing.")
endif()
118 changes: 118 additions & 0 deletions app/src/modules/cloud/Kconfig.cloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Copyright (c) 2024 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig CLOUD_MODULE
bool "Cloud module"
default y if NRF_CLOUD_COAP

if CLOUD_MODULE

config CLOUD_MODULE_SHELL
bool "Enable cloud shell"
default y if SHELL
help
Enable cloud shell commands.

config CLOUD_MODULE_PAYLOAD_BUFFER_MAX_SIZE
int "Payload maximum buffer size"
default 128
help
Maximum size of the buffer sent over the payload channel when sending RAW JSON messages
to the cloud.

config CLOUD_MODULE_SHADOW_RESPONSE_BUFFER_MAX_SIZE
int "Payload maximum buffer size"
default 512
help
Maximum size of the buffer used to receive shadow responses from the cloud.

config CLOUD_MODULE_CONFIRMABLE_MESSAGES
bool "Use confirmable messages"
help
Use confirmable messages for CoAP communications with nRF Cloud.
Confirmable messages are retransmitted COAP_MAX_RETRANSMIT times
until an acknowledgment is received.

config CLOUD_MODULE_BACKOFF_INITIAL_SECONDS
int "Reconnection backoff time in seconds"
default 60
help
Time in between reconnection attempts to the nRF Cloud CoAP server.
The timer starts after the last failed attempt.

choice CLOUD_MODULE_BACKOFF_TYPE
prompt "Reconnection backoff type"
default CLOUD_MODULE_BACKOFF_TYPE_LINEAR

config CLOUD_MODULE_BACKOFF_TYPE_EXPONENTIAL
bool "Exponential backoff"
help
Exponential backoff doubles the reconnection timeout after each failed attempt.
The maximum reconnection timeout is defined by CLOUD_MODULE_BACKOFF_MAX_SECONDS.

config CLOUD_MODULE_BACKOFF_TYPE_LINEAR
bool "Linear backoff"
help
Linear backoff adds a fixed amount of time to the reconnection timeout after each failed attempt,
as defined by CLOUD_MODULE_BACKOFF_LINEAR_INCREMENT_SECONDS.

config CLOUD_MODULE_BACKOFF_TYPE_NONE
bool "No backoff"
help
No backoff means that the reconnection timeout is constant at the value defined by
CLOUD_MODULE_BACKOFF_INITIAL_SECONDS.

endchoice

config CLOUD_MODULE_BACKOFF_LINEAR_INCREMENT_SECONDS
int "Reconnection backoff time increment"
default 60
help
Time added to the reconnection timeout after each failed attempt in seconds.
The maximum reconnection timeout is defined by CLOUD_MODULE_BACKOFF_MAX_SECONDS.

config CLOUD_MODULE_BACKOFF_MAX_SECONDS
int "Maximum reconnection timeout"
default 3600
help
Maximum reconnection backoff value in seconds.

config CLOUD_MODULE_THREAD_STACK_SIZE
int "Thread stack size"
default 6144

config CLOUD_MODULE_MESSAGE_QUEUE_SIZE
int "Message queue size"
default 5
help
ZBus subscriber message queue size.

config CLOUD_MODULE_WATCHDOG_TIMEOUT_SECONDS
int "Watchdog timeout"
default 180
help
Timeout in seconds for the cloud module watchdog.
The timeout given in this option covers both:
* Waiting for an incoming message in zbus_sub_wait_msg().
* Time spent processing the message, defined by
CONFIG_CLOUD_MODULE_MSG_PROCESSING_TIMEOUT_SECONDS.
Ensure that this value exceeds CONFIG_CLOUD_MODULE_MSG_PROCESSING_TIMEOUT_SECONDS.
A small difference between the two can mean more frequent watchdog feeds, which increases
power consumption.


config CLOUD_MODULE_MSG_PROCESSING_TIMEOUT_SECONDS
int "Maximum message processing time"
default 120
help
Maximum time allowed for processing a single message in the module's state machine.
The value must be smaller than CONFIG_CLOUD_MODULE_WATCHDOG_TIMEOUT_SECONDS.

module = CLOUD_MODULE
module-str = Cloud
source "subsys/logging/Kconfig.template.log_config"

endif # CLOUD_MODULE
Loading