How lch-98/weather_information_system works
Project Type and Purpose
• This is an embedded IoT application running on a Raspberry Pi Pico W.
• It uses FreeRTOS for task scheduling, the Pico SDK for hardware abstraction, lwIP for network, HTTP to fetch weather data, NTP to sync time, and SPI to drive an LCD.
High-Level Components
A. Hardware
• Raspberry Pi Pico W (MCU + Wi-Fi)
• SPI-based LCD module
B. Firmware Layers
1. FreeRTOS Kernel (lib/FreeRTOS-Kernel)
2. Pico SDK (lib/pico-sdk + pico_sdk_import.cmake)
3. Network Stack (lwIP, configured via src/http_weather/lwipopts.h)
4. Application Tasks
– HTTP Weather Task (src/http_weather/http_weather.c/h)
– NTP Sync Task (src/http_weather/ntp_sync/ntp_client.c/h)
– Display Task (src/picow_lcd/display.c/h)
5. LCD Driver (src/picow_lcd/lcd_sdk/*.c/h)
C. Host-side Tools
• python_bitmap/*.py – generate C arrays for 8×16 and 16×16 Korean fonts, PNG bitmaps
File-to-Component Mapping (where each file “runs”)
• src/main.cpp
• Board and RTOS initialization
• Creates and schedules three tasks: HTTP, NTP, Display
• src/http_weather/http_weather.c/h
• Executes in HTTP Weather Task
• Uses lwIP’s socket APIs to GET Weather API, calls jsmn.h to parse JSON
• src/http_weather/json/jsmn.h
• JSON parser library; runs inside HTTP Weather Task
• src/http_weather/ntp_sync/ntp_client.c/h
• Executes in NTP Sync Task
• Sends/receives UDP to NTP servers to set system clock
• src/picow_lcd/display.c/h
• Executes in Display Task
• src/picow_lcd/lcd_sdk/*.c/h
• python_bitmap/*.py
Interactions and Data Flow
• At startup (main.cpp): initialize hardware → start FreeRTOS scheduler
• NTP Task ↔ External NTP Server: sync RTC → store current time in shared variable
• HTTP Task ↔ Weather API: fetch JSON → parse → store weather data in shared buffer
• Shared buffers or FreeRTOS queues guard data handoff between tasks
Architectural Patterns and Principles
• Layered Abstraction: hardware (SPI, GPIO) → drivers (lcd_sdk) → middleware (lwIP, JSON) → application tasks
• RTOS-based concurrency: separate tasks for I/O, network, display
• Modularity: clear separation of HTTP, NTP, display code in distinct directories
• Build System: CMake orchestrates pico-sdk and FreeRTOS as submodules
Technical Callouts
• FreeRTOS Kernel (task scheduling, mutexes/queues)
• LWIP Http Client (socket APIs configured by lwipopts.h)
• JSMN JSON parser (header-only library)
• SPI protocol and GPIO controls (in lcd.c/h)
• NTP over UDP for accurate RTC