15
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP32でWPA2-enterpriseに接続する(EPA-PEAP)

Posted at

WPA2entripriseに接続できたよぉぉぉ、思い立ってちょっと長かったのと日本語でなかったので記録しておく。

#前提条件
##使用機材
ESP32-WROOM-32D Dev-kit(秋月で入手)
ESP32-WROOM-32 Arduino IoT Express mk2(aitendoで入手)
##開発環境
Arduino IDE 1.8.5
##無線接続先条件
WPA2-enterprise
EAP-PEAP MS-CHAPv2
##証明書検証
してない

情報元

eduroam用のプログラム流用が一番簡単
参照:https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino

#コード
設定に必要なところだけコメント入れておく。

wpa2-peap.ino

//ライブラリ当然
#include <WiFi.h> //Wifi library
#include <esp_wpa2.h> //wpa2 library for connections to Enterprise networks

//IDとかの定義
#define EAP_IDENTITY "匿名IDとか呼ばれるもの" //if connecting from another corporation, use 
identity@organisation.domain in Eduroam 
#define EAP_USERNAME "ユーザー名"
#define EAP_PASSWORD "パスワード" //your Eduroam password
const char* ssid = "SSID"; // (Eduroam) SSID
const char* host = "接続確認のホスト名"; //external server domain for HTTP connection 
after authentification Example"arduino.php5.sk"
int counter = 0;

//セットアップ
void setup() {
//シリアル速度
Serial.begin(115200);
delay(10);
//
  Serial.println();
  Serial.print("Connecting to network: ");
  Serial.println(ssid);
//WiFi.disconnectはtrueを入れないと切ってくれない
  WiFi.disconnect(true);  //disconnect form wifi to set new wifi connection
//WiFi.modeは必須
  WiFi.mode(WIFI_STA); //init wifi mode
  esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); 
//provide identity
 esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_USERNAME, strlen(EAP_USERNAME)); 
//provide username --> identity and username is same
  esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); 
//provide password
  esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default
  esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function
  WiFi.begin(ssid); //connect to wifi
delay(1000);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    counter++;
    if(counter>=60){ //after 30 seconds timeout - reset board
      ESP.restart();
    }
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address set: "); 
  Serial.println(WiFi.localIP()); //print LAN IP
}
void loop() {
  if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network
    counter = 0; //reset counter
    Serial.println("Wifi is still connected with IP: "); 
    Serial.println(WiFi.localIP());   //inform user about his IP address
  }else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
    WiFi.begin(ssid);      
  }
  while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
    delay(500);
    Serial.print(".");
    counter++;
    if(counter>=60){ //30 seconds timeout - reset board
    ESP.restart();
    }
  }
  Serial.print("Connecting to website: ");
  Serial.println(host);
  WiFiClient client;
  if (client.connect(host, 80)) {
    String url = "/rele/rele1.txt";
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + 
"User-Agent: ESP32\r\n" + "Connection: close\r\n\r\n"); 

     while (client.connected()) {
      String line = client.readStringUntil('\n');
      if (line == "\r") {
        break;
      }
    }
    String line = client.readStringUntil('\n');
   Serial.println(line);
  }else{
      Serial.println("Connection unsucessful");
  }  
}

#ハマりどころ
guru meditation error of type loadprohibited occurred on core 0. exception was unhandled.が出てどうにもならない
→Arduino core for the ESP32を更新する

ArduinoIDEのファイル>環境設定から追加のボードマネージャーURLを追記
ツール>ボード>ボードマネージャー から更新してesp32 by Espressif Systemsをインストール
ツール>ボード からESP32 Dev Moduleを選ぶ

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?