How arduino-libraries/wifi works
Project type and purpose
• This is an Arduino “WiFi” library (an SDK-style library) that exposes a simple C++ API to Arduino sketches, letting an Arduino board talk over Wi-Fi via the official Arduino WiFi Shield.
File structure
• Top-level “src/” folder holds the core C++ API: WiFi, WiFiClient, WiFiServer, WiFiUdp.
• Under src/utility a thin C “driver” layer lives: spi_drv, wifi_drv, server_drv, debug helpers, plus low-level definitions (wl_definitions, wl_types).
• “examples/” contains user-facing Arduino .ino sketches demonstrating how to use the API.
• “extras/” holds binary firmware blobs (wifiHD, wifi_dnld) and scripts/tools to upgrade the shield’s on-board AT32 microcontroller firmware.
• docs/, README.adoc, library.properties, keywords.txt provide documentation, build info, CI workflows in .github/workflows.
Key insights from the README
• The library plugs into the Arduino WiFi Shield hardware.
• It provides a standard Arduino-style C++ interface (WiFi, WiFiClient, etc.) that wraps an underlying C driver layer talking over SPI to an on-shield Atmel AT32 microcontroller that runs lwIP for TCP/IP.
Main components & relationships
a. Application Layer (Arduino Sketches)
• examples/*.ino
• Calls WiFi.h API classes (WiFi, WiFiClient, WiFiServer, WiFiUdp).
b. Library API Layer (C++ wrapper)
• src/WiFi.cpp/h, WiFiClient.cpp/h, etc.
• Implements high-level calls: begin(ssid), connect(), hostByName(), server(), udp().
c. Utility/Driver Layer (C layer)
• src/utility/spi_drv.cpp/h → abstracts the SPI bus on the Arduino MCU.
• src/utility/wifi_drv.cpp/h → wraps hardware protocol to the AT32.
• src/utility/server_drv.cpp/h → manages socket-style sessions over the firmware.
• debug.h → logging over Serial for debugging.
d. Atmel AT32 Microcontroller on Shield
• Pre-loaded firmware (wifiHD) implements IEEE802.11 MAC, TCP/IP stack (lwIP), DHCP, DNS, sockets.
• Receives SPI commands from driver, serves back network packets.
e. Wi-Fi Radio & External Network
• AT32’s Wi-Fi radio link to an Access Point → Router → Internet.
f. Firmware Tools (extras)
• Scripts and ELF/HEX binaries for flashing or upgrading the shield’s AT32 firmware (wifi_dnld).
Architectural patterns & design principles
• Layered architecture: Sketch → C++ API → C-based hardware abstraction → on-board firmware → network link → Internet.
• Adapter/Facade: WiFiClient etc. adapt low-level driver calls into Arduino-style APIs.
• Hardware abstraction: spi_drv isolates board-specific SPI calls; wifi_drv isolates protocol specifics.
• Separation of concerns: application vs. API vs. driver vs. firmware.