To connect an ESP8266 with Ziggo hotspot, I need to use a certificate.
I can not get it working so far. No idea why it is not connecting.
Here's the code I made (changed the user/password ofcourse):
/**************************************************************************************
* ESP8266 verbinden met Ziggo hotspot
***************************************************************************************/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <wpa2_enterprise.h>
#include "mytime.h"
#ifdef DEBUG_ESP_PORT
#define DEBUG_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#else
#define DEBUG_MSG(...)
#endif
const char ssid[] = "Ziggo";
const char ssident[] = "12345678";
const char ssuser[] = "12345678";
const char sspass[] = "abcdefghijklmno";
struct station_config wifi_config;
bool wifiOk = false;
const char ziggo_cert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIFZTCCA02gAwIBAgIQMRRC4yx40plHb1I51cU4BDANBgkqhkiG9w0BAQsFADBF
MRMwEQYDVQQKEwpaaWdnbyBCLlYuMQswCQYDVQQGEwJOTDEhMB8GA1UEAxMYWmln
Z28gUHVibGljIFJvb3RDQSAtIEcxMB4XDTE0MDYyNjEyMzYxOFoXDTM0MDYyNjEy
MzYxOFowRTETMBEGA1UEChMKWmlnZ28gQi5WLjELMAkGA1UEBhMCTkwxITAfBgNV
BAMTGFppZ2dvIFB1YmxpYyBSb290Q0EgLSBHMTCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBAL7u99oSjtFHKcjs3NFNiojGDyjcTIYmowMkKPFRWD+QjBA8
t1Gkddc0CpsEvbdzLY6oArJYmmMTayMXeOp1wdXfGKBgvnWieehNH39vzBlQjby0
9U/iKm0O2pMzwK6XocpOh6Dy3vxnyv/XdTkuL6WU2KuhYLOZ8VWX8AmbUN5hKnEr
6bwAsTvj6afOloMFPxynFHdiKYr3E75rGUC5K3u+H7dbJyWbbCUmaBT/GAkMPhj6
2uPicWIxfNVI3ER1cKwvfMUULYNuJ6g2GNEs1yImrZ6ktVAMMogF1dGHomR/kuAA
z73H09pCx4IxzxRCWCKEfQydk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N
09r0QvCKsI1paz0iBjzfIy7qrTZeD1Q4zPTN0dR93ENugauWgL5B8L8+UfED7W0H
r3SUD6YaIGzrDf8Qv02XcHQX5Bt3e+UbmYR1IR0QSsERn8DA4kEMXvA=
-----END CERTIFICATE-----
)EOF";
void wifi_connect()
{
WiFi.mode(WIFI_STA);
wifi_set_opmode(STATION_MODE);
memset(&wifi_config, 0, sizeof(wifi_config));
strcpy((char*)wifi_config.ssid, ssid);
strcpy((char*)wifi_config.password, sspass);
wifi_station_set_config(&wifi_config);
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_disable_time_check(true); // geen tijd controle
// wifi_station_set_enterprise_identity((u8*)ssident, strlen(ssident));
wifi_station_set_enterprise_username((u8*)ssuser, strlen(ssuser));
wifi_station_set_enterprise_password((u8*)sspass, strlen(sspass));
wifi_station_set_enterprise_ca_cert((u8*)ziggo_cert, sizeof(ziggo_cert));
wifi_station_connect();
}
void setup()
{
setTime(20, 45, 0, 28, 8, 2021);
Serial.begin(115200);
delay(2000);
DEBUG_MSG("bootup...\n");
Serial.println(euroDateTime(true));
wifi_connect();
}
void loop()
{
if (!wifiOk && WiFi.status() == WL_CONNECTED)
{
Serial.println("WiFi verbonden");
Serial.print("IP: ");
Serial.println(WiFi.localIP().toString());
Serial.print("MAC: ");
Serial.println(WiFi.macAddress());
Serial.print("Router: ");
Serial.println(WiFi.BSSIDstr());
wifiOk = true;
}
delay(1000);
}