0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

安いWi-Fi機能付きのESP8266マイコンを試す(WPS対応 ちょっただけ進展編)

Posted at

前の記事

準備編

応用編

WPS失敗編

Arudiono IDEで使う

作りたかった機能

WPS接続する!

ソース変えて+うまくいくルーターあり。前に、うまくいかないルータはうまくいかない・・。

つながらなかったサーバ

- 内容
メーカー IOデータ
製品 WN-DX1167GR
ファームウェアバージョン 1.11.000
ブートコードのバージョン 1.24.06
IPアドレス割当 DHCP

つながったサーバ

- 内容
メーカー PLANEX
製品 MZK-MF300N2
ファームウェアバージョン 1.14
IPアドレス割当 DHCP

試行した結果

試行その1

試行1.WiFi.begin() + beginWPSConfig()編
WiFi.begin() +beginWPSConfig編スケッチ
たぶん、WiFi.begin()もbeginWPSConfig()もいる様子。

スケッチ(色付けてみたwww)

#include <ESP8266WiFi.h>

//  Wi-Fi接続関連
const unsigned long WIFI_CONNECTED_CHECK_MS = 500;
const unsigned long WIFI_CONNECTED_TIMEOUT  = 60000;

void setup() {
  Serial.begin(SERIAL_SPEED);
  Serial.println("");

  //  WiFi接続
  ConnectedStatus = false;
  ConnectedStatus = startWPSPBC();
}

bool Wifi_connectWait() {
  int wait=0;
  Serial.println("Plase wait. WiFi connecting");
  while (wait < WIFI_CONNECTED_TIMEOUT) {
    if (WiFi.status() == WL_CONNECTED) {
      Serial.println("WiFi connected");
      return true;
    }
    Serial.print(".");
    wait += WIFI_CONNECTED_CHECK_MS;
    delay(WIFI_CONNECTED_CHECK_MS);
    Serial.println(wait);
  }
  Serial.println("Connect timed out");

  return false;
}

bool startWPSPBC() {
  bool wpsSuccess;

  //  初期設定
  WiFi.mode(WIFI_STA);
  WiFi.begin("","");
  delay(WIFI_CONNECTED_CHECK_MS);
  WiFi.disconnect();

  // wpstest.ino
  Serial.println("WPS config start");
  WiFi.beginWPSConfig();
  wpsSuccess = Wifi_wait();

  if(wpsSuccess) {
    String newSSID = WiFi.SSID();
    if(newSSID.length() > 0) {
      //  newSSIDが割り当てられたら成功
      Serial.printf("WPS finished. Connected successfull to SSID '%s'\n", newSSID.c_str());
      Serial.println("WPS config success.");
      Serial.print("WPS Connected. local IP address: ");
      Serial.println(WiFi.localIP());
    }
  } else {
    Serial.println("WPS config fault.");
  }

  return wpsSuccess; 
}

謝辞

以下の記事を参考に作りました。

最後に

スケッチコードはCC BY-SA 4.0(著作者の情報とCCライセンス継承はお願いします。商用利用・改変・再配布は問題なし)です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?