Zephyr

Advanced configuration for Zephyr

This guide describes various advanced configuration options for the Zephyr module.

Device ID

Kconfig option

Easiest way to set device ID is by using the CONFIG_SPOTFLOW_DEVICE_ID Kconfig option in your prj.conf file:

prj.conf
CONFIG_SPOTFLOW_DEVICE_ID="your-device-id"

If setting the device ID via Kconfig works for you, there is no need to investigate other options and we recommend sticking with this approach.

Setting device ID at runtime

However, in more complex scenarios, Kconfig option may not be sufficient, especially when device ID is not known at compile time or needs to be set dynamically.

In such cases, define function spotflow_override_device_id that returns a string with the device ID. Inside this function, you can implement the logic to determine the device ID at runtime and Spotflow device module will call this function to get the device ID.

src/main.c
const char* spotflow_override_device_id()
{
	return "my_nrf7002dk_test";
}

Although this approach allows to setting device ID dynamically, it most cases the function should contain deterministic logic returning consistent values across device reboots. Random or frequently changing will prevent you from efficiently analyzing device-specific behavior and performance as well as it might lead to increase subscription usage in terms of number of registered devices.

Hardware Info Interface

If no device ID is explicitly provided, the Spotflow device module will try to use the Zephyr's Hardware Info Interface to retrieve the device ID via hwinfo_get_device_id(...) function.

Cloud hostname and port

By default, the Spotflow device module connects to the Spotflow cloud at mqtt.spotflow.io on port 8883 which is a standard port used for MQTT over TLS.

In case you need to change these settings (e.g. due to using proxy), following Kconfig options are available:

prj.conf
CONFIG_SPOTFLOW_CLOUD_HOSTNAME="mqtt.spotflow.io"
CONFIG_SPOTFLOW_CLOUD_PORT=8883

Storing sensitive information in the configuration files

Most of the configuration options are typically not sensitive and thus is it safe and beneficial to version them in the Git or other version control system. However, some options such as Ingestion Key or WiFi passwords are sensitive and it is a security issue to store them in the version control.

For such cases, we recommend store the sensitive options in a separate credentials.conf file that is not tracked by version control and merge them into the resulting configuration during build.

Thread priorities and stack size

Spotflow device module is using a separate thread to send data via MQTT.

To modify priority of this thread, enable SPOTFLOW_MQTT_THREAD_CUSTOM_PRIORITY option and choose the custom priority via SPOTFLOW_MQTT_THREAD_PRIORITY.

To modify stack size of this thread, use SPOTFLOW_PROCESSING_THREAD_STACK_SIZE option.

prj.conf
CONFIG_SPOTFLOW_MQTT_THREAD_CUSTOM_PRIORITY=y
CONFIG_SPOTFLOW_MQTT_THREAD_PRIORITY=14
CONFIG_SPOTFLOW_PROCESSING_THREAD_STACK_SIZE=2560

Build ID

To disable generating and embedding build ID, disable SPOTFLOW_GENERATE_BUILD_ID option.

Disabling build ID will prevent Spotflow from automatically linking logs and core dumps with the uploaded ELF files. However, the ELF files can still be linked manually to specific core dumps.

prj.conf
CONFIG_SPOTFLOW_GENERATE_BUILD_ID=n

Internal logging

To adjust default log level of internal Spotflow device module logging, use the SPOTFLOW_MODULE_DEFAULT_LOG_LEVEL option.

prj.conf
CONFIG_SPOTFLOW_MODULE_DEFAULT_LOG_LEVEL=3

Changing minimal log severity from portal

The Spotflow device module allows you to update the minimal severity of sent log messages during runtime by changing its value in the portal.

By default, all log messages are sent, and you can use this option to reduce the log volume when needed. Alternatively, you can use the Kconfig option SPOTFLOW_DEFAULT_SENT_LOG_LEVEL to start sending initially, for example, only errors and warnings, and increase the verbosity only when needed.

If CONFIG_SPOTFLOW_SETTINGS=n, the minimal log severity is not persisted on the device. In this case, the Spotflow device module uses SPOTFLOW_DEFAULT_SENT_LOG_LEVEL from the device start and loads the latest value set from the portal after it connects to the Spotflow cloud. As a result, logs might not be filtered in the way you want until the connection is established.

Therefore, in order to persist the minimal log severity to the device and use it right from the device start, enable the Zephyr settings subsystem and one of its backends, such as the non-volatile storage (NVS) backend:

prj.conf
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y

CONFIG_SPOTFLOW_SETTINGS=y will be set by default when CONFIG_SETTINGS=y is set.

How is this guide?