Quickstart

Zephyr Integration

Integrate your Zephyr-based devices using Spotflow west module.

Select your development board
We'll tailor the quickstart guide for your specific hardware

Prerequisites

If you don't have Zephyr dependencies already installed, refer to the official Getting Started Guide for the instructions on how to install them for your operating system.

Create West Workspace

The following script will guide you through the creation of a new workspace that contains the Spotflow module and sample applications:

source <(curl --proto '=https' --tlsv1.2 -sSf https://downloads.spotflow.io/spotflowup.sh) --zephyr --board other

Alternatively, you can create the workspace manually by following these steps.

Configure Sample Application

To try out logging to Spotflow, let's configure the sample application. Fill in the required configuration options in <workspace-folder>/modules/lib/spotflow/zephyr/samples/logs/prj.conf:

CONFIG_NET_WIFI_SSID="<Your Wi-Fi SSID>"
CONFIG_NET_WIFI_PASSWORD="<Your Wi-Fi password>"

CONFIG_SPOTFLOW_DEVICE_ID="device-001" # Set unique identifier of your device
CONFIG_SPOTFLOW_INGEST_KEY="<your-ingest-key>"

If you’re using Ethernet, make sure the Ethernet cable is plugged in into the board and the network has internet access.

The CONFIG_SPOTFLOW_INGEST_KEY is a secret key that allows your device to authenticate with Spotflow. You can manage your ingest keys in the ingest keys page.

When using a custom board, you might need to adjust other configuration options to compile the example. Refer to the options for specific boards in our device SDK repository for inspiration.

Run Sample Application

Now, you are ready to build and flash your application to the device and start sending logs to Spotflow:

>_ Terminal
cd modules/lib/spotflow/zephyr/samples/logs
west build --pristine --board <your-board>
west flash

If you open the UART output from the device, it should be similar to this one:

[00:00:00.098,461] <dbg> spotflow_logging: init: Initializing spotflow logging backend
[00:00:02.825,807] <inf> fs_nvs: nvs_mount: 8 Sectors of 4096 bytes
[00:00:02.825,818] <inf> fs_nvs: nvs_mount: alloc wra: 5, f88
[00:00:02.825,824] <inf> fs_nvs: nvs_mount: data wra: 5, 47
[00:00:02.825,947] <inf> spotflow_net: spotflow_config_persistence_try_load: Persisted Spotflow configuration loaded
[00:00:02.825,957] <inf> spotflow_net: spotflow_config_init_sent_log_level: Initialized sent log level to 4
[00:00:02.825,968] <dbg> spotflow_net: spotflow_start_mqtt: Thread started with priority 14 and stack size 2560
[00:00:02.825,976] <inf> spotflow_logging: init: Spotflow logging backend initialized.
*** Booting Zephyr OS build 3568e1b6d5cd ***
[00:00:03.600,676] <inf> MAIN: main: Starting Spotflow logging example
[00:00:03.601,075] <dbg> spotflow_net: spotflow_mqtt_thread_entry: Starting Spotflow processing thread
[00:00:03.601,122] <inf> spotflow_net: wait_for_network: Waiting for network...
[00:00:04.600,860] <inf> spotflow_sample_wifi: connect_to_wifi: Connecting to SSID: TP-Link_B4F9_5G
[00:00:05.605,147] <inf> MAIN: main: Hello from Zephyr to Spotflow: 0
[00:00:07.605,285] <inf> MAIN: main: Hello from Zephyr to Spotflow: 1
[00:00:09.605,387] <inf> MAIN: main: Hello from Zephyr to Spotflow: 2
[00:00:11.605,495] <inf> MAIN: main: Hello from Zephyr to Spotflow: 3
[00:00:13.605,604] <inf> MAIN: main: Hello from Zephyr to Spotflow: 4
[00:00:15.502,302] <dbg> spotflow_net: l4_event_handler: Network connectivity established and IP address assigned
[00:00:15.502,519] <inf> spotflow_sample_wifi: wifi_event_handler: Connected to MyWifi
[00:00:15.502,618] <dbg> spotflow_net: spotflow_tls_init: TLS init
[00:00:15.502,638] <dbg> spotflow_net: spotflow_mqtt_thread_entry: Spotflow registered TLS credentials
[00:00:15.502,681] <dbg> spotflow_net: client_init: Resolving DNS
[00:00:15.508,154] <dbg> spotflow_net: spotflow_conn_helper_resolve_hostname: DNS resolved for mqtt.spotflow.io:8883
[00:00:15.508,199] <inf> spotflow_device_id: spotflow_get_device_id: Using Spotflow device ID: my-device-001
[00:00:15.508,219] <dbg> spotflow_net: client_init: Using secure transport
[00:00:15.605,775] <inf> MAIN: main: Hello from Zephyr to Spotflow: 5
[00:00:16.570,883] <dbg> spotflow_net: prepare_fds: Using secure
[00:00:16.751,104] <dbg> spotflow_net: mqtt_evt_handler: MQTT client connected!
[00:00:16.751,190] <inf> spotflow_net: spotflow_mqtt_establish_mqtt: MQTT connected!
[00:00:16.817,495] <dbg> spotflow_net: mqtt_evt_handler: SUBACK packet id: 5242
[00:00:16.817,519] <dbg> spotflow_net: mqtt_evt_handler: Subscription to desired configuration topic acknowledged
[00:00:17.606,119] <inf> MAIN: main: Hello from Zephyr to Spotflow: 6
[00:00:19.606,428] <inf> MAIN: main: Hello from Zephyr to Spotflow: 7
...

Learn more

How is this guide?