Compare commits

...

2 Commits

Author SHA1 Message Date
Starbeamrainbowlabs 3d42f3270b
autoplant: implement enterprise wifi support 2021-12-14 15:53:49 +00:00
Starbeamrainbowlabs 68cd7ac8a8
fixup 2021-12-14 15:35:51 +00:00
2 changed files with 49 additions and 2 deletions

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) {

View File

@ -13,7 +13,7 @@
// The port to connect to.
// 1883 = unencrypted, 8883 = encrypted
// Connections are encrypted by default. There isn't currently a way to disable it.
#define MQTT_PORT "8883"
#define MQTT_PORT 8883
// The username to authenticate with when connecting to the MQTT server.
#define MQTT_USERNAME "autoplant"
// The password to authenticate with when connecting to the MQTT server.