autoplant: implement enterprise wifi support

This commit is contained in:
Starbeamrainbowlabs 2021-12-14 15:53:49 +00:00
parent 68cd7ac8a8
commit 3d42f3270b
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -45,6 +45,52 @@ 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
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#else
// 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;
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();
#endif
}
float read_analog(int channel) {
const char* bin = std::bitset<8>(channel).to_string().c_str();
@ -96,7 +142,8 @@ void setup() {
// https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
// TODO Add support for enterprise WiFi here so we can connect to eduroam
Serial.print("WIFI: ");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
connect_wifi();
int attempts = 0;
while (WiFi.status() != WL_CONNECTED) {