在站点模式下连接 WiFi
加入您的网络并打印 IP 地址
在站点模式下连接 WiFi 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Arduino & IoT Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Arduino & IoT Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What Station Mode Is
When your board joins an existing network like a phone joins WiFi, that is Station mode. Your router is the host; the ESP is a guest. 📶
Include the Library
Everything starts by including the WiFi library. That one line gives you connect, status, and address functions.
#include <WiFi.h>Store Your Credentials
Save your network name and password in const char variables. Keeping them near the top makes them easy to update later.
const char* ssid = "MyNetwork";
const char* password = "secret123";SSID Is the Network Name
The SSID is simply the WiFi name you tap on your phone. It must match exactly, including capital letters and spaces.
Set the Mode
Tell the chip to act as a client with WiFi.mode(). Setting station mode keeps it from accidentally becoming its own hotspot.
WiFi.mode(WIFI_STA);Start the Connection
Kick things off with WiFi.begin(), passing your ssid and password. This starts the handshake with the router.
WiFi.begin(ssid, password);Connecting Takes Time
Joining is not instant. You wait in a loop and check WiFi.status() until it reports WL_CONNECTED.
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}Show Progress Dots
Printing a dot each loop gives friendly feedback. When the dots stop, your board has successfully joined the network.
Grab Your IP Address
Once connected, the router hands your board an IP address. Read it with WiFi.localIP() so you know how to reach the device.
Serial.println(WiFi.localIP());The IP Identifies the Device
That IP address is your board's home on the network. You type it in a browser later to open pages your ESP serves.
When It Will Not Connect
Stuck on dots forever? Double-check the password and SSID, and remember ESP boards only join 2.4 GHz networks, not 5 GHz.
Quick Check
After WiFi.begin runs, how do you confirm the board actually joined the network?
Recap
You joined a router in Station mode: include WiFi, set credentials, call begin, wait for WL_CONNECTED, then print your IP. 🎉
常见问题解答
「在站点模式下连接 WiFi」课时是免费的吗?
是的 — 「在站点模式下连接 WiFi」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。
「在站点模式下连接 WiFi」这节课中我会学到什么?
加入您的网络并打印 IP 地址 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Arduino & IoT Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「在站点模式下连接 WiFi」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?
能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 为什么物联网选择 ESP32 和 ESP8266
- 将 ESP 开发板添加到 IDE
- 在站点模式下连接 WiFi
- 运行接入点设置页面