This commit is contained in:
@@ -1,38 +1,52 @@
|
||||
/*
|
||||
* MTG RFID Companion - Wi-Fi manager (Core 0)
|
||||
*
|
||||
* Phase 5 Step 5.1: Station-mode auto-connect with disconnect event
|
||||
* handling and reconnect back-off.
|
||||
* Station-mode multi-profile management with NVS persistence,
|
||||
* live network scanning, and boot auto-connect.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WIFI_MAX_PROFILES 5
|
||||
#define WIFI_SSID_MAX_LEN 32
|
||||
#define WIFI_PASS_MAX_LEN 64
|
||||
|
||||
typedef struct {
|
||||
char ssid[WIFI_SSID_MAX_LEN + 1];
|
||||
char password[WIFI_PASS_MAX_LEN + 1];
|
||||
} wifi_profile_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize the Wi-Fi subsystem (netif, driver, events).
|
||||
* @brief Initialize the Wi-Fi subsystem (netif, driver, events, NVS).
|
||||
* @return ESP_OK on success.
|
||||
*/
|
||||
esp_err_t wifi_manager_init(void);
|
||||
|
||||
/**
|
||||
* @brief Start station mode and attempt to connect to the configured AP.
|
||||
* @brief Start station mode and attempt to connect.
|
||||
* Checks NVS profiles first, scanning for the best in-range network,
|
||||
* falling back to compile-time Kconfig defaults.
|
||||
*/
|
||||
esp_err_t wifi_manager_start(void);
|
||||
|
||||
/**
|
||||
* @brief True if a real SSID is configured (non-empty, not the
|
||||
* `YOUR_...` placeholder). Station mode will actually run.
|
||||
* @brief True if a real SSID is configured in NVS or Kconfig.
|
||||
*/
|
||||
bool wifi_manager_sta_configured(void);
|
||||
|
||||
/**
|
||||
* @brief True if the STA has a valid IP.
|
||||
* @brief True if the STA currently has a valid IP address.
|
||||
*/
|
||||
bool wifi_manager_connected(void);
|
||||
|
||||
@@ -46,6 +60,45 @@ esp_err_t wifi_manager_wait_connected(TickType_t timeout_ticks);
|
||||
*/
|
||||
const char *wifi_manager_get_ip(void);
|
||||
|
||||
/**
|
||||
* @brief Get currently connected SSID name (or "Disconnected").
|
||||
*/
|
||||
const char *wifi_manager_get_connected_ssid(void);
|
||||
|
||||
/**
|
||||
* @brief Get current Wi-Fi RSSI signal strength in dBm (or 0 if disconnected).
|
||||
*/
|
||||
int8_t wifi_manager_get_rssi(void);
|
||||
|
||||
/**
|
||||
* @brief Perform a Wi-Fi scan and return detected access points.
|
||||
* Caller must free() *out_records when done.
|
||||
* @param[out] out_records Pointer to allocated array of records.
|
||||
* @param[out] out_count Number of records returned.
|
||||
*/
|
||||
esp_err_t wifi_manager_scan_networks(wifi_ap_record_t **out_records, uint16_t *out_count);
|
||||
|
||||
/**
|
||||
* @brief Save a Wi-Fi network profile into NVS.
|
||||
*/
|
||||
esp_err_t wifi_manager_save_profile(const char *ssid, const char *password);
|
||||
|
||||
/**
|
||||
* @brief Delete a saved network profile from NVS.
|
||||
*/
|
||||
esp_err_t wifi_manager_delete_profile(const char *ssid);
|
||||
|
||||
/**
|
||||
* @brief Retrieve all saved network profiles from NVS.
|
||||
* @return Count of profiles retrieved.
|
||||
*/
|
||||
int wifi_manager_get_saved_profiles(wifi_profile_t *out_profiles, int max_count);
|
||||
|
||||
/**
|
||||
* @brief Connect to a new Wi-Fi network immediately, optionally saving to NVS.
|
||||
*/
|
||||
esp_err_t wifi_manager_connect_new(const char *ssid, const char *password, bool save_to_nvs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user