WiFi connect using saved provisioning data (ssid/password)
Posted: Tue Jun 04, 2024 9:08 am
I want my ESP32-WROOM-32 to check if there is stored provisioning data. If there is, use it to connect to that WiFi. If there is not, start provisioning again.
I have the following code working but I don't know of a way to get the stored provisioning data (ssid/password) from memory to use for connecting, this would prevent the need for hardcoding the ssid/password.
#include "WiFiProv.h"
#include "WiFi.h"
const char *pop = "abcd1234";
const char *service_name = "PROV_123";
const char *service_key = NULL;
bool reset_provisioned = true;
const char *ssid = "HomeWiFi";
const char *password = "NotPa55word";
void setup() {
--Serial.begin(115200);
--int CONNECT_ATTEMPTS_MAX = 10;
--int connectAttempts = 0;
--WiFi.mode(WIFI_STA);
--WiFi.begin(ssid, password);
--delay(1000);
--Serial.print("\nConnecting to WiFi ");
--while (WiFi.status() != WL_CONNECTED && connectAttempts < CONNECT_ATTEMPTS_MAX) {
----Serial.print('.');
----delay(1000);
----connectAttempts++;
--}
--if (WiFi.status() != WL_CONNECTED) {
----Serial.println("Begin Provisioning using BLE");
----uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };
----WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name, service_key, uuid, reset_provisioned);
----log_d("ble qr");
----WiFiProv.printQR(service_name, pop, "ble");
----while (WiFi.status() != WL_CONNECTED) {
------Serial.print('.');
------delay(1000);
----}
--}
--if (WiFi.status() == WL_CONNECTED) {
----Serial.println("\nConnected to WiFi:"+WiFi.localIP());
--} else {
----Serial.print("\nDisconnected from WiFi");
--}
}
void loop() {}
I have the following code working but I don't know of a way to get the stored provisioning data (ssid/password) from memory to use for connecting, this would prevent the need for hardcoding the ssid/password.
#include "WiFiProv.h"
#include "WiFi.h"
const char *pop = "abcd1234";
const char *service_name = "PROV_123";
const char *service_key = NULL;
bool reset_provisioned = true;
const char *ssid = "HomeWiFi";
const char *password = "NotPa55word";
void setup() {
--Serial.begin(115200);
--int CONNECT_ATTEMPTS_MAX = 10;
--int connectAttempts = 0;
--WiFi.mode(WIFI_STA);
--WiFi.begin(ssid, password);
--delay(1000);
--Serial.print("\nConnecting to WiFi ");
--while (WiFi.status() != WL_CONNECTED && connectAttempts < CONNECT_ATTEMPTS_MAX) {
----Serial.print('.');
----delay(1000);
----connectAttempts++;
--}
--if (WiFi.status() != WL_CONNECTED) {
----Serial.println("Begin Provisioning using BLE");
----uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };
----WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name, service_key, uuid, reset_provisioned);
----log_d("ble qr");
----WiFiProv.printQR(service_name, pop, "ble");
----while (WiFi.status() != WL_CONNECTED) {
------Serial.print('.');
------delay(1000);
----}
--}
--if (WiFi.status() == WL_CONNECTED) {
----Serial.println("\nConnected to WiFi:"+WiFi.localIP());
--} else {
----Serial.print("\nDisconnected from WiFi");
--}
}
void loop() {}