Updated SSID/Password mechanism
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -110,3 +110,4 @@ credentials.h
|
|||||||
|
|
||||||
# Project-specific ignores
|
# Project-specific ignores
|
||||||
# Add any project-specific files to ignore here
|
# Add any project-specific files to ignore here
|
||||||
|
main/Kconfig.projbuild
|
||||||
17
main/main.c
17
main/main.c
@ -9,11 +9,16 @@
|
|||||||
#include "ota_server.h"
|
#include "ota_server.h"
|
||||||
#include "led_strip.h"
|
#include "led_strip.h"
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
static const char *TAG = "MAIN";
|
static const char *TAG = "MAIN";
|
||||||
|
|
||||||
// WiFi credentials - Change these to your network
|
// WiFi credentials - Change these to your network
|
||||||
#define WIFI_SSID "YOUR_SSID"
|
// #define WIFI_SSID "YOUR_SSID"
|
||||||
#define WIFI_PASSWORD "YOUR_PASSWORD"
|
// #define WIFI_PASSWORD "YOUR_PASSWORD"
|
||||||
|
|
||||||
|
const char *ssid = CONFIG_WIFI_SSID;
|
||||||
|
const char *password = CONFIG_WIFI_PASSWORD;
|
||||||
|
|
||||||
// Application version
|
// Application version
|
||||||
#define APP_VERSION "1.0.0"
|
#define APP_VERSION "1.0.0"
|
||||||
@ -113,16 +118,16 @@ void app_main(void)
|
|||||||
char stored_pass[65] = {0};
|
char stored_pass[65] = {0};
|
||||||
|
|
||||||
// Force update with new credentials (remove this after first successful connection)
|
// Force update with new credentials (remove this after first successful connection)
|
||||||
ESP_LOGI(TAG, "Updating WiFi credentials - SSID: '%s'", WIFI_SSID);
|
ESP_LOGI(TAG, "Updating WiFi credentials - SSID: '%s'", ssid);
|
||||||
wifi_manager_set_credentials(WIFI_SSID, WIFI_PASSWORD);
|
wifi_manager_set_credentials(ssid, password);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Normal flow - only update if no credentials stored
|
// Normal flow - only update if no credentials stored
|
||||||
if (wifi_manager_get_credentials(stored_ssid, sizeof(stored_ssid),
|
if (wifi_manager_get_credentials(stored_ssid, sizeof(stored_ssid),
|
||||||
stored_pass, sizeof(stored_pass)) != ESP_OK) {
|
stored_pass, sizeof(stored_pass)) != ESP_OK) {
|
||||||
ESP_LOGI(TAG, "No stored WiFi credentials, saving default ones");
|
ESP_LOGI(TAG, "No stored WiFi credentials, saving default ones");
|
||||||
ESP_LOGI(TAG, "Setting SSID: '%s'", WIFI_SSID);
|
ESP_LOGI(TAG, "Setting SSID: '%s'", ssid);
|
||||||
wifi_manager_set_credentials(WIFI_SSID, WIFI_PASSWORD);
|
wifi_manager_set_credentials(ssid, password);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Found stored credentials - SSID: '%s'", stored_ssid);
|
ESP_LOGI(TAG, "Found stored credentials - SSID: '%s'", stored_ssid);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user