First, What Is It
- Protocol: the "language rules" devices use to communicate — how data is arranged, sent, and acknowledged.
- Layering: split complex communication into layers, each handling one job and only talking to its neighbors — like a company's front desk → department → warehouse.
- Ai-WB2 protocol stack overview: radio (Wi-Fi 4 / BLE) → IP networking (lwIP) → application protocols (HTTP/MQTT/SNTP...); each layer has its SDK implementation and example.
Breaking Down the Principle
1. Network Protocol Classification
Protocols grouped by function, including those used by Ai-WB2:
| Category | Protocols | Role | Tutorial page |
|---|---|---|---|
| Wireless link | Wi-Fi (802.11), BLE | Physical radio, network access | Wi-Fi Intro, BLE Intro |
| Network layer | IP, ICMP | Addressing and routing ("to whom") | TCP/IP Intro |
| Transport layer | TCP, UDP | Reliable/unreliable delivery ("how") | TCP Client, UDP Client |
| Application layer | HTTP/S, MQTT/S, SNTP, DNS, WebSocket | Business-oriented data formats | HTTP Intro, MQTT, SNTP |
| Application layer (BLE) | GATT/ATT, HID | Data organization after BLE connection | BLE & GATT |
2. OSI vs TCP/IP Layer Mapping
The common four-layer (TCP/IP) model is a simplified OSI seven-layer model:
| TCP/IP 4-layer | OSI 7-layer (roughly) | Typical protocols | Analogy |
|---|---|---|---|
| Application | Application/Presentation/Session | HTTP, MQTT, SNTP, DNS | Letter content |
| Transport | Transport | TCP, UDP | Courier label (registered/regular mail) |
| Network | Network | IP, ICMP | Delivery address |
| Link | Data link/Physical | Wi-Fi 802.11, Ethernet | Courier transport |
3. Data Encapsulation: One Envelope Inside Another
Each layer adds its "envelope" when sending; the receiver strips them layer by layer:
This is why packet captures show layer after layer of headers — each header was added by one protocol layer.
4. Ai-WB2 Protocol Stack Implementation
In code: Wi-Fi starts with wifi_task_create + fhost_init, the network stack with tcpip_init (lwIP), and BLE with btble_controller_init + hci_driver_init + bt_enable.
How the SDK Implements It
- Related pages: TCP/IP Intro, Wi-Fi Intro, Ai-WB2 BLE Intro
Any networking example initializes "Wi-Fi + lwIP" at startup:
tcpip_init(NULL, NULL); /* start the lwIP stack */
xTaskCreate(wifi_start_firmware_task, "wifi init", 1024, NULL, 10, NULL); /* start Wi-Fi firmware */
/* After getting an IP, TCP/UDP/HTTP/MQTT examples can work */Common Exam & Interview Questions
What are the four TCP/IP layers and one protocol each?
Application (HTTP/MQTT), Transport (TCP/UDP), Network (IP/ICMP), Link (Wi-Fi/Ethernet).
Why encapsulate data layer by layer when sending?
Each layer handles one job (port → IP → MAC) and only adds its own header; the receiver strips them in reverse. This is why layered protocols interoperate across vendors.
What do IP and TCP each solve?
IP routes to the right device (addressing); TCP provides reliable delivery (ports, sequence numbers, ACK/retransmission). One handles address, the other handles delivery quality.
Which layer is Wi-Fi? How does it relate to TCP/IP?
Wi-Fi (802.11) is link/physical layer; TCP/IP runs on top of it. "Connected to Wi-Fi" only means the link is up — you still need an IP (DHCP) to use network protocols.
How do BLE and Wi-Fi protocol stacks differ?
BLE is a separate stack (controller + HCI + host GAP/GATT) that does not run IP/TCP; Wi-Fi goes through IP networking. Both can coexist (shared antenna, time-multiplexed), but the protocol systems differ.
Have questions?
For any other questions, visit the unified Q&A and discussion board: Ai-Thinker Discussions

