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() {}
WiFi connect using saved provisioning data (ssid/password)
-
- Posts: 2
- Joined: Tue Jun 04, 2024 8:47 am
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: WiFi connect using saved provisioning data (ssid/password)
WiFi has 2 methods to retrieve the STA login info. Once you connect you can retrieve them.
WiFi.SSID() and WiFi.psk()
WiFi.SSID() and WiFi.psk()
-
- Posts: 2
- Joined: Tue Jun 04, 2024 8:47 am
Re: WiFi connect using saved provisioning data (ssid/password)
Thank you for the additional details, however I need to get the ssid/password from memory on bootup to initiate the wifi connection to the previously provisioned AP.
Re: WiFi connect using saved provisioning data (ssid/password)
You can use Preferences library which is built-in to the espressif-arduino framework. Preferences act as if it was eeprom.Volition42 wrote: ↑Tue Jun 04, 2024 10:31 pmThank you for the additional details, however I need to get the ssid/password from memory on bootup to initiate the wifi connection to the previously provisioned AP.
The first time you will have to just store your creditials programatically. After that you can just pull your credentials out of storage.
There are a couple of examples in the framework to help you get started.
Who is online
Users browsing this forum: No registered users and 76 guests