ステーションモードでWiFiに接続する
ネットワークに接続し、IPアドレスを表示します。
「ステーションモードでWiFiに接続する」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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に接続する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「ステーションモードでWiFiに接続する」で何を学びますか?
ネットワークに接続し、IPアドレスを表示します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「ステーションモードでWiFiに接続する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- IoTにESP32とESP8266を使う理由
- IDEにESPボードを追加する
- ステーションモードでWiFiに接続する
- アクセスポイントの設定ページを動かす