Skip to content

Problem using Preferences with AutoConnect #375

Answered by Hieromon
MacGyverr asked this question in How can I?
Discussion options

You must be logged in to vote

@MacGyverr

So that it doesn't store every credential ever used just the latest one?

Here is snippet:

#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Preferences.h>
#include <AutoConnect.h>
extern "C" {
#include <esp_wifi.h>
}

const char* PREFS_NAMESPACE = "credential";
const char* PREFS_KEY = "credential";

Preferences prefs;
wifi_config_t w_config;

AutoConnect portal;
AutoConnectConfig config;

void onConnect(IPAddress& ip) {
  esp_err_t err;

  Serial.println("WiFi connected");
  if ((err = esp_wifi_get_config(WIFI_IF_STA, &w_config)) == ESP_OK) {
    Serial.printf("%.*s: ", sizeof(wifi_config_t::sta.ssid), w_config.sta.ssid);
    if (prefs.putBytes(PREFS_KEY…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@MacGyverr
Comment options

@Hieromon
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Hieromon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #374 on July 06, 2021 10:39.