LoginSignup
4
6

More than 5 years have passed since last update.

ESP8266 > Link > APモード > IPアドレスを設定する > WiFi.softAPConfig()

Last updated at Posted at 2016-05-21
使用機材
ESP-WROOM-02 > ユニバーサル基板実装

http://qiita.com/7of9/items/b21630802ec8a881cb02#comment-c468b3e0bea64220d317
にてSensorsystemで使うネットワークについて検討している中、以下のコメントをいただいていた。

ESP-8266をAPとする場合、
Wifi.softAPConfig(IPAddress(<ローカルIP>),IPAddress(<ゲートウェイ>),IPAddress(<サブネット>));
WiFi.softAP(<ssid>);
とすることで、任意のIPアドレスを設定できるようです。

その使用例は以下にある。
http://qiita.com/yanix/items/8bfc00db7cae75d4c6e6

実際にやってみた。

eps8266_160521_APwithIpAdr.ino
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

static const char *kSsid = "esp8266";
static const char *kPassword = "12345678";

ESP8266WebServer myServer(80);

void handleRoot() {
    myServer.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
    pinMode(4,OUTPUT);
    delay(1000);

    Serial.begin(115200);
    Serial.println();
    Serial.print("Configuring access point...");

#if 1 // set my IP
    WiFi.softAPConfig(IPAddress(192, 168, 79, 2), IPAddress(192, 168, 79, 1), IPAddress(255, 255, 255, 0));
#endif

    WiFi.softAP(kSsid, kPassword);
    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);

    myServer.on("/", handleRoot);
    myServer.begin();
    Serial.println("HTTP server started");
}

void loop() {
    myServer.handleClient();
}
結果
Configuring access point...AP IP address: 192.168.79.2
HTTP server started

確かに設定できた。

192.168.4.1という固定でなく、自由なIPアドレスを設定できることで、他の接続機器のIPの指定がフレキシブルになる。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6