Table of Contents

Lab 12. Zephyr RTOS: Shell, LittleFS, Webserver

This lab walks you through building three Zephyr applications for Sparrow:

Verify your environment

Open a terminal in your Zephyr workspace and run:

cd ~/zephyrproject
source .venv/bin/activate

Then:

west --version
west boards | grep esp32c6

If the board (ESP32C6 Xiao) is listed and west works, continue.

Tip: If you switch branches or update modules often, use:
> west update

1. Common Project Layout

Each lab uses the same basic structure:

<APP_ROOT>/
  CMakeLists.txt
  prj.conf
  src/
    main.c
  boards/
    esp32c6_devkitc_esp32c6_hpcore.overlay
  (optional) Kconfig

Build command used in all labs:

west build -b esp32c6_devkitc/esp32c6/hpcore -p auto .

Flash:

west flash -d build --runner esp32

Monitor serial output:

screen <your_port_name> 115200

2. Sparrow Shell + Custom I2C Scan Command

Goal

Build a UART shell application that includes standard Zephyr shell commands and adds a custom command:

What you will build

Create the project

Create a new folder, e.g. sparrow_console and unzip the project here.

sparrow_shell_i2c_scan/
  CMakeLists.txt
  prj.conf
  src/main.c
  boards/esp32c6_devkitc_esp32c6_hpcore.overlay

Build, flash, and test

Build:

west build -b esp32c6_devkitc/esp32c6/hpcore -p auto .

Flash:

west flash -d build --runner esp32

Open the serial console and test:

Expected: you see a list of detected I2C addresses or “no devices found”.

Troubleshooting

3. Sparrow Shell + LittleFS Mounted From Internal Flash

Goal

Build a shell app that provides a “Linux-like” file navigation experience (as much as Zephyr supports), using:

Typical workflow in shell:

Build the Project

Create a new folder, e.g. sparrow_littlefs and unzip the project here.

Build, flash, test

Build:

west build -b esp32c6_devkitc/esp32c6/hpcore -p auto .

Flash:

west flash -d build --runner esp32

Test in shell:

Expected: you can navigate the mount point and list directory contents, create and view files, etc..

Troubleshooting

Assignment: Add a BME680 logging service with a new “bme_log” shell command, plus a background thread that appends CSV entries with uptime timestamps to a file named bme_log.dat.

Usage examples:

bme_log start 5
bme_log status
bme_log interval 10
bme_log stop
fs cat /lfs/logs/bme_log.dat

4. Wi‑Fi Webserver

Goal

Build a webserver that:

Important performance note (ESP32 Wi‑Fi memory)

Wi‑Fi + TLS stacks can be memory hungry. For a simple HTTP server:

Configure the Project

Create a new folder, e.g. sparrow_web and unzip the project here.

Build, flash, test

Build:

west build -b esp32c6_devkitc/esp32c6/hpcore -p auto .

Flash:

west flash -d build --runner esp32

The code runs a HTTP static file server backed by LittleFS and auto-started at boot; it serves files from /lfs/www on port 8080 and uses the HTTP server’s static_fs handler.

In the serial shell, you need to run the following commands:

1. Connect to WiFi:

wifi scan
wifi connect -s "SSID" -p "PASS" -k 1
wifi status

2. Check the webserver is up and running and get the board IP address:

net http
net iface

3. Write a simple index.html file into /lfs/www:

fs write /lfs/www/index.html -o 0 3c 68 31 3e 48 69 3c 2f 68 31 3e

4. Browse: http://[board-ip]:8080/

Expected:

Assignment: Add a dynamic HTTP endpoint that serves the current contents of bme_log.dat as an HTML page with a 10‑second auto‑refresh. So, if you conect to http://[board-ip]:8080/bme_log it will automatically serve the contents of the log file.