Skip to content

Instantly share code, notes, and snippets.

Last active November 28, 2023 09:17
  • Star 26 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ESP8266 Wi-Fi WPA2 Enterprise example
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
#include "wpa2_enterprise.h"
#include "c_types.h"
// SSID to connect to
char ssid[] = "TEST_KRA";
char username[] = "matheus_garbelini";
char identity[] = "matheus_garbelini";
char password[] = "testtest";
uint8_t target_esp_mac[6] = {0x24, 0x0a, 0xc4, 0x9a, 0x58, 0x28};
void setup() {
Serial.printf("SDK version: %s\n", system_get_sdk_version());
Serial.printf("Free Heap: %4d\n",ESP.getFreeHeap());
// Setting ESP into STATION mode only (no AP mode or dual mode)
struct station_config wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config));
strcpy((char*)wifi_config.ssid, ssid);
strcpy((char*)wifi_config.password, password);
// Clean up to be sure no old data is still inside
wifi_station_set_enterprise_identity((uint8*)identity, strlen(identity));
wifi_station_set_enterprise_username((uint8*)username, strlen(username));
wifi_station_set_enterprise_password((uint8*)password, strlen((char*)password));
while (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connected");
Serial.println("IP address: ");
void loop() {
Copy link

Just a heads up everyone, if identity is not set, it will not be empty, it is acutually set to

Here's my version of the above with websocket, works with peap mschapv2 at my uni:

Copy link

alvarovaro commented Apr 5, 2021

Hi, I'm getting this message from the Serial Monitor constantly. I am using a NodeMCU v1.0 board. I already set Erase Flash option to All flash contents but did not work.

Any comments on how to solve it?

,,,,,,,,,,pm open,type:2 0
14:40:29.211 -> ,,,,,,,,,,,,,,,,,,,,state: 5 -> 0 (2)
14:40:48.703 -> rm 0
14:40:48.703 -> pm close 7
14:40:48.703 -> reconnect
14:40:48.805 -> scandone
14:40:48.805 -> state: 0 -> 2 (b0)
14:40:48.805 -> state: 2 -> 3 (0)
14:40:48.805 -> state: 3 -> 5 (10)
14:40:48.805 -> add 0
14:40:48.805 -> aid 1
14:40:48.805 -> cnt
14:40:49.204 -> ,,,,,,,,,,pm open,type:2 0
14:40:59.208 -> ,,,,,,,,

Copy link

ziogianni commented Apr 5, 2021 via email

Copy link

Hi, thanks for yout reply.

The certs are in the following format :
char ssid[] = "CNIOPROF";
char username[] = "";
char identity[] = "
char password[] = "xxxx";
That should be hex, right?

Regarding the TLS, I am using a nodemcu board whose TLS version is 1.2. How can I chech which versions are supported by the server?

After all what I do is basically uploading that code to the nodemcu.

I am quite new to this Arduino environment. Thanks for your patience.

Copy link

bear-zd commented Dec 4, 2022

I meet the same problem when use the code above. Using arduino IDE.
hardware: ESP-12F ESP8266MOD
using NodeMCU 1.0(ESP-12E)_ and erase all flash content
after it connect the wifi , it just keep about 8 second and then restart. Why this happened and if there is a valid method to solve this?

Copy link

ziogianni commented Dec 4, 2022 via email

Copy link

ziogianni commented Feb 25, 2023 via email

Copy link

igurug commented Nov 10, 2023

Thanks a lot! I had so much troubles working with esp8266 in the University. Now the problem is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment