How alexsousadev/wifi-init works
• Pico W Hardware (Embedded Client):
– Firmware: Written in C using the Pico SDK and compiled by CMake.
– Wi‑Fi & Communication Modules:
▪ The “wifi-connection” module (from utils/wifi-connection) initializes the onboard Wi‑Fi chip (CYW43) and connects to the selected wireless network.
▪ The “send-data-to-server” module (from utils/send-data-to-server) is responsible for constructing and sending HTTP requests over TCP.
– lwIP Stack: Provides the lightweight TCP/IP protocol support.
– Utility Code (e.g., wifi-test.c) that ties the initialization and communication together.
• Local Server (Backend Server):
– Node.js/Express Server: Located under the “server” directory, which is built using TypeScript (server.ts) and uses Express to create an endpoint (/receber) that receives JSON data.
– Server Dependencies: package.json and package-lock.json, which manage libraries like Express.
• Supporting Configuration and Build Files:
– CMakeLists.txt and pico_sdk_import.cmake: Define the build configuration for the Pico firmware.
– lwipopts.h: Contains custom network stack configuration used by the Pico application.
– .gitignore, .vscode: Provide additional development environment settings.
Relationships and Data Flow
• The Pico W connects to a specified local Wi‑Fi network using the initialization functions from the “wifi-connection” module.
• Once connected, the Pico W continuously sends a formatted HTTP POST request to the server using a TCP connection formed by the lwIP stack. This request is assembled by the “send-data-to-server” code (with its steps of creating a TCP PCB, converting the server IP, connecting, composing the HTTP header and JSON body, and calling tcp_write and tcp_output).
• The HTTP request contains the “dado” value (the counter) in JSON format, which the server (via the Express app on route “/receber”) receives and logs to the console.
• Error handling occurs in both the embedded firmware (e.g., connection failure, tcp_callback on sent_data) and on the server side.
Architectural Patterns and Technologies
• Separation of Concerns: The project neatly separates the embedded code (hardware-level, network library use, and C-based build configuration) from the server logic written in Node.js/Express.
• Client-Server Architecture: The Pico W serves as a client that periodically assembles and sends its data to a server endpoint.
• Modular Design: The “utils” folder indicates a modular approach where specific functionalities (Wi‑Fi connection versus data sending) are isolated.
• Use of Standard Libraries and SDKs: Pico SDK, lwIP library, and Node.js with Express represent common technologies in embedded and full-stack development.