autoplant: upgrade to esp32, but enterprise wifi isn't working right.
This commit is contained in:
parent
cfa67aea37
commit
c5fcf90119
1 changed files with 25 additions and 39 deletions
|
@ -2,7 +2,20 @@
|
|||
#include <string>
|
||||
|
||||
// #include <ArduinoJson.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
#ifdef WIFI_ENTERPRISE_ENABLED
|
||||
// Ref https://github.com/martinius96/ESP32-WPA2-enterprise/blob/master/ESP32_WPA2enterprise.ino
|
||||
#include "esp_wpa2.h"
|
||||
#include "esp_wifi.h"
|
||||
#endif
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
#ifdef MQTT_NO_TLS
|
||||
#include <WiFiClient.h>
|
||||
#else
|
||||
#include <WiFiClientSecure.h>
|
||||
#endif
|
||||
|
||||
#include "./lib/pubsubclient/PubSubClient.h"
|
||||
#include "./lib/pubsubclient/PubSubClient.cpp"
|
||||
|
@ -52,50 +65,23 @@ PubSubClient mqtt;
|
|||
|
||||
Adafruit_BME280 bme; // I2C
|
||||
|
||||
#ifdef WIFI_ENTERPRISE_ENABLED
|
||||
// Ref https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
#include "wpa2_enterprise.h"
|
||||
#include "c_types.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
void connect_wifi() {
|
||||
#ifndef WIFI_ENTERPRISE_ENABLED
|
||||
Serial.print("personal");
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
#else
|
||||
Serial.print("enterprise");
|
||||
// Ref https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
|
||||
// Setting ESP into STATION mode only (no AP mode or dual mode)
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
|
||||
struct station_config wifi_config;
|
||||
// Ref https://github.com/martinius96/ESP32-WPA2-enterprise/blob/master/ESP32_WPA2enterprise.ino
|
||||
// For ESP32 ONLY! For esp8266, see the code with the esp8266-last tag, which is the last commit that supports the esp8266.
|
||||
WiFi.disconnect(true);
|
||||
// 'esp_wifi_sta_wpa2_ent_set_identity' was not declared in this scope :-(
|
||||
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)WIFI_ENTERPRISE_USERNAME, strlen(WIFI_ENTERPRISE_USERNAME));
|
||||
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)WIFI_ENTERPRISE_USERNAME, strlen(WIFI_ENTERPRISE_USERNAME));
|
||||
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)WIFI_ENTERPRISE_PASSWORD, strlen(WIFI_ENTERPRISE_PASSWORD));
|
||||
esp_wifi_sta_wpa2_ent_enable();
|
||||
|
||||
memset(&wifi_config, 0, sizeof(wifi_config));
|
||||
strcpy((char*)wifi_config.ssid, WIFI_SSID);
|
||||
strcpy((char*)wifi_config.password, WIFI_ENTERPRISE_PASSWORD);
|
||||
|
||||
wifi_station_set_config(&wifi_config);
|
||||
// wifi_set_macaddr(STATION_IF,target_esp_mac);
|
||||
|
||||
wifi_station_set_wpa2_enterprise_auth(1);
|
||||
|
||||
// Clean up to be sure no old data is still inside
|
||||
wifi_station_clear_cert_key();
|
||||
wifi_station_clear_enterprise_ca_cert();
|
||||
wifi_station_clear_enterprise_identity();
|
||||
wifi_station_clear_enterprise_username();
|
||||
wifi_station_clear_enterprise_password();
|
||||
wifi_station_clear_enterprise_new_password();
|
||||
|
||||
wifi_station_set_enterprise_identity((uint8*)WIFI_ENTERPRISE_USERNAME, strlen(WIFI_ENTERPRISE_USERNAME));
|
||||
wifi_station_set_enterprise_username((uint8*)WIFI_ENTERPRISE_USERNAME, strlen(WIFI_ENTERPRISE_USERNAME));
|
||||
wifi_station_set_enterprise_password((uint8*)WIFI_ENTERPRISE_PASSWORD, strlen((char*)WIFI_ENTERPRISE_PASSWORD));
|
||||
|
||||
|
||||
wifi_station_connect();
|
||||
WiFi.begin(WIFI_SSID);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue