LoginSignup
20
23

More than 5 years have passed since last update.

ESP8266でWPSを実装してみる

Last updated at Posted at 2016-04-22

http://bbs.espressif.com/viewtopic.php?t=1096
ソース元はこちら

ESP-WROOM-02にはWPSでWiFiの設定をすることができる環境がつくられているようなのでその解説と結果を報告します。

環境

Arduino IDE 1.6.7
Arduino core for ESP8266 WiFi chip (https://github.com/esp8266/Arduino) v2.2.0

Arduino coreのバージョンが古いと実装されてない可能性があります。

コード

wps.ino
#include <ESP8266WiFi.h>

void Wifi_wait();
void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  //WiFi.begin("","")このようにすることでWPSで保存したデータがある場合そちらに接続するようになる
  WiFi.begin("", "");
  Wifi_wait();
  // Wifiに接続していないときにはWPSを開始します
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("\nAttempting connection ...");
    WiFi.beginWPSConfig();
    Wifi_wait();
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("Connected!");
      Serial.println(WiFi.localIP());
      Serial.println(WiFi.SSID());
      Serial.println(WiFi.macAddress());
    } else {
      Serial.println("Connection failed!");
    }
  } else {
    Serial.println("\nConnection already established.");
  }
}

void loop() {
}

void Wifi_wait() {
  int wait=0;
  Serial.println("WiFi connecting");
  while (wait < 20) {
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("WiFi connected");
      return;
    }
    Serial.print(".");
    wait++;
    delay(250);
  }
  Serial.println("Connect timed out");
}

使いかた

Wifiに接続失敗したときにWPSで設定中のルータをさがしに行きます。

WPSで設定中のものがあったとき、ESP-WROOM-02はそのルータから設定を取得し、今後そのルータに接続するようになります。

Wifiに詳しくない人でもESP-WROOM-02を手軽に扱えるようになる技術だと思います、

結果

私の所持しているWifiルータではWPSでの接続は成功しませんでした…

それは、私の持っているWifiルータが悪いのかもしれないのでもしよければ、試して成功したかどうか教えてください。

20
23
4

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
20
23