Skip to content

Commit

Permalink
samples: cellular: nrf_cloud_coap_client: Add new sample
Browse files Browse the repository at this point in the history
This nRF Cloud CoAP client demonstrates using FOTA, messaging,
cellular positioning, A-GPS, and P-GPS over CoAP.

Get modem info IMEI and mfw. Init the modem, which waits for LTE
connection. Look up server IP. Init the client, including
looking up device IP with modem info.

Send real cell pos parameters, receive, decode, and display
location. Send cell pos back as fake GNSS PVT data.

Send fake temperature sensor data. Receive and process
MODEM and APP FOTA types.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
  • Loading branch information
plskeggs committed Jul 19, 2023
1 parent 15b03f6 commit a7789f6
Show file tree
Hide file tree
Showing 14 changed files with 1,689 additions and 0 deletions.
18 changes: 18 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2022 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf-cloud-coap-client)
zephyr_compile_definitions(PROJECT_NAME=${PROJECT_NAME})
find_program(ZCBOR zcbor REQUIRED)

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c src/handle_fota.c)
# NORDIC SDK APP END

zephyr_include_directories(src)
72 changes: 72 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "nRF Cloud CoAP client sample"

config NRF_CLOUD_COAP_CLIENT_SAMPLE_VERSION
string "The sample's version string"
default "1.0.0"

config COAP_FOTA_JOB_CHECK_RATE_MIN
int "Rate (minutes) at which this sample will check for FOTA updates"
default 1

config COAP_FOTA_DL_TIMEOUT_MIN
int "The time (minutes) allotted for a FOTA download to complete"
default 15
help
If the FOTA download does not complete in the allotted time,
the download will be cancelled and the job status will be
set as failed.

config COAP_FOTA_USE_NRF_CLOUD_SETTINGS_AREA
bool "Use the same settings area as the nRF Cloud FOTA library"
default y
help
Using the same settings area as the nRF Cloud FOTA library will
allow this sample to perform application-FOTA updates to applications
built with CONFIG_NRF_CLOUD_FOTA enabled.

config COAP_FOTA_SETTINGS_NAME
depends on !COAP_FOTA_USE_NRF_CLOUD_SETTINGS_AREA
string "Settings identifier for the COAP FOTA sample"
default "coap_fota_sample"
help
The root settings identifier for this application.
For application-FOTA, this value should also be found in your target application
so that the FOTA status can be properly reported to nRF Cloud.

config COAP_FOTA_SETTINGS_KEY_PENDING_JOB
depends on !COAP_FOTA_USE_NRF_CLOUD_SETTINGS_AREA
string "Settings item key for pending FOTA job info"
default "pending_job"
help
The settings item key where pending FOTA job info will be stored.
For application-FOTA, this value should also be found in your target application
so that the FOTA status can be properly reported to nRF Cloud.

config COAP_FOTA_USE_THREAD
bool "Use a thread to process FOTA in the background"
help
If not enabled, call the handle_fota_process() periodically. Otherwise, a
thread will process based on COAP_FOTA_JOB_CHECK_RATE_MIN.

config COAP_FOTA_THREAD_STACK_SIZE
int "CoAP FOTA Thread Stack Size (bytes)"
default 2048
help
Sets the stack size (in bytes) for the CoAP FOTA thread of the
sample.

module = NRF_CLOUD_COAP_CLIENT
module-dep = LOG
module-str = nRF Cloud CoAP Client Sample
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
endmenu # Application sample

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/* Use high drive mode on SPI pins that handle communication with nRF7002
* so that SCK frequency > 4 MHz can be used. */
&spi3_default {
group1 {
nordic,drive-mode = <NRF_DRIVE_H0H1>;
};
};

/* Disabled because of conflicts on P0.00 and P0.01 - Arduino pins D0 and D1
* (iovdd-ctrl-gpios and bucken-gpios in nrf7002ek, respectively). */
&uart1 {
status = "disabled";
};
41 changes: 41 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/overlay-debug.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# General config
CONFIG_DEBUG=y

# Logging
CONFIG_LOG=y
CONFIG_COAP_LOG_LEVEL_DBG=y
CONFIG_NRF_CLOUD_COAP_CLIENT_LOG_LEVEL_DBG=y
CONFIG_NRF_CLOUD_COAP_LOG_LEVEL_DBG=y
CONFIG_NRF_CLOUD_LOG_LEVEL_INF=y
CONFIG_NRF_CLOUD_GPS_LOG_LEVEL_INF=y
CONFIG_LOCATION_LOG_LEVEL_DBG=y
CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_WRN=y
CONFIG_NET_LOG=y
CONFIG_NET_OFFLOAD_LOG_LEVEL_WRN=y
CONFIG_NET_UDP_LOG_LEVEL_WRN=y
CONFIG_NET_SOCKETS_LOG_LEVEL_WRN=y
CONFIG_NET_IF_LOG_LEVEL_WRN=y
CONFIG_NET_CONFIG_LOG_LEVEL_WRN=y
CONFIG_DNS_RESOLVER_LOG_LEVEL_WRN=n
CONFIG_NET_CONTEXT_LOG_LEVEL_WRN=y
CONFIG_AT_HOST_LOG_LEVEL_WRN=y
CONFIG_DATE_TIME_LOG_LEVEL_INF=y
CONFIG_SETTINGS_LOG_LEVEL_INF=y
CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_INF=y

CONFIG_LOG_PRINTK=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y
CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y

# Modem library
CONFIG_NRF_MODEM_LIB_LOG_LEVEL_INF=y
CONFIG_NRF_MODEM_LOG=n
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Overlay to use nRF7002 EK on top of nrf9160 DK for Wi-Fi scanning

# Enable the Wi-Fi location method:
CONFIG_LOCATION_METHOD_WIFI=y
# Align this with CONFIG_NRF700X_SCAN_LIMIT.
# Also see comments for CONFIG_HEAP_MEM_POOL_SIZE.
CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT=10
CONFIG_NRF700X_SCAN_LIMIT=10

# Enable Wi-Fi drivers, (and the native NET stack so that the location library can access them)
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_NATIVE=y

# System settings
CONFIG_NEWLIB_LIBC=y

# Disable the supplicant and local networking features, since we don't need connectivity
CONFIG_WPA_SUPP=n
CONFIG_MBEDTLS=n
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n
CONFIG_NORDIC_SECURITY_BACKEND=n

# Stack/heap tweaks needed to support Wi-Fi.
# Heap allocation should be changed when CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT
# and CONFIG_NRF700X_SCAN_LIMIT (which should be the same value) are changed.
CONFIG_HEAP_MEM_POOL_SIZE=20000
CONFIG_NET_MGMT_EVENT_STACK_SIZE=2048

# NET tweaks needed to support Wi-Fi
CONFIG_NET_BUF_RX_COUNT=8
CONFIG_NET_BUF_TX_COUNT=8
CONFIG_NET_PKT_RX_COUNT=1
CONFIG_NET_PKT_TX_COUNT=1
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096
CONFIG_NET_TC_TX_COUNT=1
CONFIG_NET_MAX_CONTEXTS=5

CONFIG_NRF_CLOUD_COAP_LOG_LEVEL_DBG=y
CONFIG_LOCATION_LOG_LEVEL_DBG=y
19 changes: 19 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/overlay-offload-tls.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Networking
CONFIG_NET_NATIVE=n
CONFIG_NET_OFFLOAD=y
CONFIG_NET_SOCKETS_OFFLOAD=y

CONFIG_NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH=y

# Configure for using offloaded UDP and TLS
CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY=40
CONFIG_MODEM_KEY_MGMT=y

# Generate JWTs in the modem
CONFIG_MODEM_JWT=y
114 changes: 114 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# General config
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

CONFIG_DK_LIBRARY=y

# Mbed TLS logs include %zu formatters, which are not handled by the nano
# version of newlib
CONFIG_NEWLIB_LIBC_NANO=n

# Main thread
CONFIG_MAIN_STACK_SIZE=6144
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=6144

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_CONFIG_NEED_IPV6=n
CONFIG_NET_IPV4=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y

# Modem library
CONFIG_NRF_MODEM_LIB=y
CONFIG_NRF_MODEM_LIB_LOG_FW_VERSION_UUID=n

# Modem info
CONFIG_MODEM_INFO=y
CONFIG_MODEM_INFO_ADD_DEVICE=y
CONFIG_MODEM_INFO_ADD_NETWORK=y
CONFIG_MODEM_INFO_ADD_DATE_TIME=n
CONFIG_MODEM_INFO_ADD_SIM=n
CONFIG_MODEM_INFO_ADD_SIM_ICCID=n
CONFIG_MODEM_INFO_ADD_SIM_IMSI=n

# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_0_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y
CONFIG_AT_MONITOR_HEAP_SIZE=4096

# LTE link control
CONFIG_NET_L2_VIRTUAL=y

# Date/Time
CONFIG_DATE_TIME=y
CONFIG_DATE_TIME_AUTO_UPDATE=y
CONFIG_DATE_TIME_MODEM=y
CONFIG_DATE_TIME_NTP=n

CONFIG_FPU=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_NRF_CLOUD_COAP=y
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
CONFIG_COAP_CLIENT_STACK_SIZE=6144
CONFIG_COAP_CLIENT_THREAD_PRIORITY=0
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40

CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096

# Flash - Used by FOTA and PGPS
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_FCB=y

# MCUBOOT - Needed by FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_STREAM_FLASH_ERASE=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

CONFIG_REBOOT=y

# FOTA download
CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_DOWNLOAD_PROGRESS_EVT=y
CONFIG_DFU_TARGET=y
CONFIG_DOWNLOAD_CLIENT=y

CONFIG_LOG=y
CONFIG_NET_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_COAP_LOG_LEVEL_INF=y
CONFIG_NRF_CLOUD_COAP_LOG_LEVEL_INF=y
CONFIG_NRF_CLOUD_COAP_CLIENT_LOG_LEVEL_INF=y

CONFIG_LOCATION=y
CONFIG_LOCATION_METHOD_GNSS=y
CONFIG_LOCATION_METHOD_CELLULAR=y
CONFIG_LOCATION_DATA_DETAILS=y
CONFIG_LOCATION_LOG_LEVEL_INF=y

# GNSS assistance
CONFIG_NRF_CLOUD_AGPS=y
CONFIG_NRF_CLOUD_PGPS=y
CONFIG_NRF_CLOUD_PGPS_REQUEST_UPON_INIT=y
CONFIG_NRF_CLOUD_PGPS_NUM_PREDICTIONS=4
31 changes: 31 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/prj_qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# General config
CONFIG_TEST_RANDOM_GENERATOR=y

# CoAP
CONFIG_COAP=y

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_UDP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y

CONFIG_DNS_RESOLVER=y
CONFIG_DNS_SERVER_IP_ADDRESSES=y
CONFIG_DNS_SERVER1="8.8.8.8"

# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"

# Main thread
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=2048
19 changes: 19 additions & 0 deletions samples/cellular/nrf_cloud_coap_client/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sample:
name: nRF Cloud CoAP client sample
tests:
samples.nrf9160.nrf_cloud_coap_client:
build_only: true
integration_platforms:
- nrf9160dk_nrf9160_ns
platform_allow: nrf9160dk_nrf9160_ns nrf9161dk_nrf9161_ns
extra_args: OVERLAY_CONFIG=overlay-offload-tls.conf
tags: ci_build
sample.nrf9160.nrf_cloud_coap_client.nrf7002ek_wifi:
build_only: true
integration_platforms:
- nrf9160dk_nrf9160_ns
platform_allow: nrf9160dk_nrf9160_ns nrf9161dk_nrf9161_ns
extra_args: SHIELD=nrf7002ek
OVERLAY_CONFIG="overlay-nrf7002ek-wifi-scan-only.conf;overlay-offload-tls.conf"
DTC_OVERLAY_FILE="nrf9160dk_with_nrf7002ek.overlay"
tags: ci_build
Loading

0 comments on commit a7789f6

Please sign in to comment.