Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:laboratoare:2025:lab12 [2026/01/03 18:24]
dan.tudose [What you will build]
iothings:laboratoare:2025:lab12 [2026/01/03 23:05] (current)
dan.tudose [Build, flash, test]
Line 16: Line 16:
 </​code>​ </​code>​
  
-If the board is listed and west works, continue.+If the board (ESP32C6 Xiao) is listed and west works, continue.
  
 > Tip: If you switch branches or update modules often, use: > Tip: If you switch branches or update modules often, use:
Line 73: Line 73:
     * ''​i2c_scan''​     * ''​i2c_scan''​
  
-==== Step 1: Create the project ==== +==== Create the project ==== 
-Create a new folder, e.g. ''​sparrow_shell_i2c_scan''​ and add the standard layout: +Create a new folder, e.g. ''​sparrow_console''​ and unzip the project {{:iothings:​laboratoare:​2025:​sparrow_console.zip|here}}.
 <​code>​ <​code>​
 sparrow_shell_i2c_scan/​ sparrow_shell_i2c_scan/​
Line 84: Line 83:
 </​code>​ </​code>​
  
-==== Step 2: Configure prj.conf ==== +==== Build, flash, and test ====
-Use a prj.conf that enables: +
-  * UART console +
-  * Shell backend over serial +
-  * I2C subsystem +
- +
-Put your known-good configuration here: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 1 prj.conf HERE> +
-</​code>​ +
- +
-Checklist (ensure these are enabled in some form): +
-  * ''​CONFIG_SERIAL=y''​ +
-  * ''​CONFIG_CONSOLE=y''​ +
-  * ''​CONFIG_UART_CONSOLE=y''​ +
-  * ''​CONFIG_SHELL=y''​ +
-  * ''​CONFIG_SHELL_BACKEND_SERIAL=y''​ +
-  * ''​CONFIG_I2C=y''​ +
- +
-==== Step 3: Board overlay (I2C pins + console) ==== +
-Your overlay must: +
-  * Set console/​shell UART device (if required on your Sparrow setup) +
-  * Configure I2C pins (SDA/SCL) to match Sparrow wiring +
- +
-Place your working overlay: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 1 overlay HERE> +
-</​code>​ +
- +
-==== Step 4: Implement the custom shell command ==== +
-Your ''​src/​main.c''​ should: +
-  * Initialize shell (often automatic if autostart is enabled) +
-  * Register the custom command handler that scans I2C +
-  * Print results (found addresses, errors, etc.) +
- +
-Place your working code: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 1 main.c HERE> +
-</​code>​ +
- +
-==== Step 5: Build, flash, and test ====+
 Build: Build:
  
Line 137: Line 93:
  
 <code bash> <code bash>
-west flash+west flash -d build --runner esp32
 </​code>​ </​code>​
  
Line 157: Line 113:
  
  
-===== 3. Lab 2 — Sparrow Shell + LittleFS Mounted From Internal Flash =====+===== 3. Sparrow Shell + LittleFS Mounted From Internal Flash =====
  
 ==== Goal ==== ==== Goal ====
Line 172: Line 128:
   * create/read files (depending on enabled commands)   * create/read files (depending on enabled commands)
  
-==== Step 1: Start from Lab 1 ==== +==== Build the Project ​====
-Copy Lab 1 project to a new folder, e.g. ''​sparrow_shell_lfs''​.+
  
-==== Step 2: Update prj.conf for filesystem support ==== +Create a new folder, e.g. ''​sparrow_littlefs''​ and unzip the project {{:iothings:​laboratoare:​2025:​sparrow_littlefs.zip|here}}.
-Enable: +
-  * file system support +
-  * LittleFS +
-  * flash map support +
-  * fs shell commands+
  
-Place your known-good configuration:​ +====  Build, flash, test ====
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 2 prj.conf HERE> +
-</​code>​ +
- +
-Checklist (ensure these are enabled in some form): +
-  * ''​CONFIG_FILE_SYSTEM=y''​ +
-  * ''​CONFIG_FILE_SYSTEM_LITTLEFS=y''​ +
-  * ''​CONFIG_FLASH=y''​ +
-  * ''​CONFIG_FLASH_MAP=y''​ +
-  * ''​CONFIG_FLASH_PAGE_LAYOUT=y''​ (often required) +
-  * ''​CONFIG_FS_SHELL=y''​ (or equivalent in your tree) +
- +
-> If your Zephyr tree provides a separate Kconfig symbol for file system shell, keep it enabled as in your working setup. +
- +
-==== Step 3: Add a flash partition for LittleFS ==== +
-Your overlay must define a partition in flash. Example concept: +
- +
-  * ''​storage_partition''​ label +
-  * ''​label = "​storage"''​ +
-  * a safe region that does not overlap existing partitions +
- +
-**Important:​** The partition address/​size depends on the board’s flash layout. +
- +
-Place your working overlay: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 2 overlay HERE> +
-</​code>​ +
- +
-==== Step 4: Mount LittleFS at boot (recommended) ==== +
-Your ''​main.c''​ should: +
-  * Create/​declare an ''​fs_mount_t''​ with: +
-    * mount point (example: ''/​lfs''​) +
-    * storage dev pointing to flash area ID for ''​storage''​ +
-  * call ''​fs_mount()''​ +
-  * print whether mount succeeded +
- +
-Place your working code: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 2 main.c HERE> +
-</​code>​ +
- +
-==== Step 5: Build, flash, test ====+
 Build: Build:
  
Line 237: Line 142:
  
 <code bash> <code bash>
-west flash+west flash -d build --runner esp32
 </​code>​ </​code>​
  
Line 244: Line 149:
   * ''​fs''​ (to see available fs commands)   * ''​fs''​ (to see available fs commands)
   * ''​ls /''​   * ''​ls /''​
-  * ''​ls /​lfs''​ (if mounted at boot)+  * ''​ls /​lfs''​ (it is mounted at boot)
   * ''​cd /​lfs''​   * ''​cd /​lfs''​
   * ''​pwd''​   * ''​pwd''​
 +  * ''​fs mkdir /​lfs/​folder1''​
 +  * ''​fs write /​lfs/​folder1/​hello.txt -o 0 48 65 6c 6c 6f 20 57 6f 72 6c 64 21''​
 +  * ''​fs cat /​lfs/​folder1/​hello.txt''​
  
-Expected: you can navigate the mount point and list directory contents.+Expected: you can navigate the mount point and list directory contents, create and view files, etc..
  
 ==== Troubleshooting ==== ==== Troubleshooting ====
Line 261: Line 169:
     * verify ''​CONFIG_FS_SHELL''​ (and any related symbols) are enabled     * verify ''​CONFIG_FS_SHELL''​ (and any related symbols) are enabled
  
 +<​note>​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. ​
  
-===== 4. Lab 3 — Wi‑Fi Webserver ​+ BME680 Sensor Data =====+Usage examples: 
 + 
 +> bme_log start 5 
 +> bme_log status 
 +> bme_log interval 10 
 +> bme_log stop 
 +> fs cat /​lfs/​logs/​bme_log.dat 
 + 
 +</​note>​ 
 +===== 4. Wi‑Fi Webserver =====
  
 ==== Goal ==== ==== Goal ====
Line 268: Line 186:
   * connects to Wi‑Fi (WPA2‑PSK)   * connects to Wi‑Fi (WPA2‑PSK)
   * obtains an IPv4 address via DHCP   * obtains an IPv4 address via DHCP
-  ​* reads BME680 sensor data periodically +  * serves ​a web page to browser  
-  ​* serves ​the latest sensor values ​to any browser ​that connects to: +
-    * ''​http://<​device-ip>:<​port>/''​+
  
 ==== Important performance note (ESP32 Wi‑Fi memory) ==== ==== Important performance note (ESP32 Wi‑Fi memory) ====
Line 278: Line 195:
   * limit concurrent connections (1 client at a time is fine for a lab)   * limit concurrent connections (1 client at a time is fine for a lab)
  
-==== Step 1: Create ​the project ​==== +==== Configure ​the Project ​====
-Create a new folder, e.g. ''​sparrow_web_bme680''​ using the standard layout.+
  
-==== Step 2: Kconfig settings (prj.conf) ==== +Create a new folder, e.g. ''​sparrow_web''​ and unzip the project {{:iothings:​laboratoare:​2025:​sparrow_littlefs_ws.zip|here}}.
-Enable: +
-  * networking core +
-  * sockets +
-  * DHCPv4 +
-  * Wi‑Fi mgmt +
-  * logging +
-  * sensor subsystem + BME680 driver+
  
-Place your working configuration:​ +====  Build, flash, test ====
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 3 prj.conf HERE> +
-</​code>​ +
- +
-Checklist (ensure these are enabled in some form): +
-  * ''​CONFIG_NETWORKING=y''​ +
-  * ''​CONFIG_NET_IPV4=y''​ +
-  * ''​CONFIG_NET_DHCPV4=y''​ +
-  * ''​CONFIG_NET_SOCKETS=y''​ +
-  * ''​CONFIG_NET_TCP=y''​ +
-  * ''​CONFIG_WIFI=y''​ +
-  * ''​CONFIG_NET_L2_WIFI_MGMT=y''​ +
-  * ''​CONFIG_SENSOR=y''​ +
-  * ''​CONFIG_BME680=y''​ +
-  * ''​CONFIG_I2C=y''​ +
- +
-==== Step 3: Wi‑Fi credentials configuration ==== +
-If your app uses custom Kconfig symbols for SSID/​password,​ include your working Kconfig file and the prj.conf entries. +
- +
-Place your working Kconfig: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 3 Kconfig HERE> +
-</​code>​ +
- +
-In prj.conf, you will typically have: +
- +
-<​code>​ +
-<PASTE YOUR WORKING SSID/​PASSWORD Kconfig assignments HERE> +
-</​code>​ +
- +
-> **Security tip:** Avoid committing real credentials to version control. +
- +
-==== Step 4: Devicetree overlay (I2C + BME680) ==== +
-Your overlay must: +
-  * configure I2C pins for Sparrow +
-  * define the BME680 node with the proper I2C address (commonly 0x76 or 0x77) +
- +
-Place your working overlay: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 3 overlay HERE> +
-</​code>​ +
- +
-==== Step 5: main.c (Wi‑Fi + DHCP + HTTP + sensor sampling) ==== +
-Your application should: +
-  * register Wi‑Fi and IPv4 events (optional but very helpful) +
-  * trigger scan/​connect +
-  * start DHCP when Wi‑Fi link is up +
-  * poll BME680 and store last sample in a global struct +
-  * run a simple HTTP server thread: +
-    * accept connection +
-    * respond with a plain text or JSON payload +
- +
-Place your working code: +
- +
-<​code>​ +
-<PASTE YOUR WORKING Lab 3 main.c HERE> +
-</​code>​ +
- +
-==== Step 6: Build, flash, test ====+
 Build: Build:
  
Line 362: Line 209:
  
 <code bash> <code bash>
-west flash+west flash -d build --runner esp32
 </​code>​ </​code>​
  
-Open serial output and note the printed IP address. 
-From a machine on the same LAN, open: 
  
-  * ''​http:​//<​device-ip>:<​port>/''​+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.
  
-Expected: +In the serial shell, you need to run the following commands:
-  * browser receives a response containing ​the latest sensor values+
  
-==== Troubleshooting ==== +1Connect to WiFi
-  * No Wi‑Fi logs: +<​code>​ 
-    * raise log level (e.g. default level or module-specific) +wifi scan 
-    * ensure Wi‑Fi mgmt is enabled +wifi connect -s "​SSID"​ -p "​PASS"​ -k 1 
-  * No IP address+wifi status 
-    * verify DHCP is enabled +</code>
-    * ensure DHCP is started after link is up +
-  * “memory allocation failed” from Wi‑Fi adapter: +
-    * reduce concurrent HTTP clients +
-    * reduce buffer sizes (HTTP response buffer) +
-    * avoid repeated dynamic allocations in the HTTP thread +
-    * consider increasing heap pool size only if you have flash/RAM headroom +
-  * Browser connects but gets no response: +
-    * verify socket calls are using Zephyr’s socket headers +
-    * verify server binds to INADDR_ANY on the chosen port +
-    * ensure response includes valid HTTP headers and CRLF+
  
- +2Check the webserver is up and running and get the board IP address: 
-===== 5Lab Deliverables ===== +<​code>​ 
- +net http 
-For each lab, record: +net iface
-  * the commit hash or archive name of your working project +
-  * the build command used +
-  * screenshots or logs showing: +
-    * Lab 1: ''​i2c_scan''​ output +
-    * Lab 2: ''​ls /​lfs''​ and ''​pwd''​ +
-    * Lab 3: printed ​IP address ​+ browser response output +
- +
-Optional: include a short README in each project with: +
-  * wiring notes (SDA/SCL pins, BME address) +
-  * shell prompt and commands +
-  * filesystem mount point +
-  * HTTP port and example URL +
- +
- +
-===== 6. Appendix — Useful Commands ===== +
- +
-==== Clean rebuild ==== +
-<​code ​bash+
-rm -rf build +
-west build -b esp32c6_devkitc/​esp32c6/​hpcore -p auto .+
 </​code>​ </​code>​
  
-==== Inspect devicetree output ==== +3. Write a simple index.html file into ''/​lfs/www''​
-After build: +<​code>​fs write /​lfs/​www/​index.html -o 0 3c 68 31 3e 48 69 3c 2f 68 31 3e</​code>​
-  * ''​build/zephyr/zephyr.dts''​+
  
-Search for: +4. Browsehttp://​[board-ip]:​8080/​
-  * ''​flash0''​ +
-  * ''​partitions''​ +
-  * your ''​storage''​ partition +
-  * your I2C and BME680 nodes+
  
-==== Inspect .config ==== 
-After build: 
-  * ''​build/​zephyr/​.config''​ 
  
-Search for+Expected
-  * ''​CONFIG_SHELL''​ +  * browser receives a response containing "​Hi"​
-  * ''​CONFIG_FILE_SYSTEM''​ +
-  * ''​CONFIG_WIFI''​ +
-  * ''​CONFIG_NET_SOCKETS''​+
  
 +<​note>​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.</​note>​
  
-====== End of Lab ====== 
  
iothings/laboratoare/2025/lab12.1767457473.txt.gz · Last modified: 2026/01/03 18:24 by dan.tudose
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0