All checks were successful
ESP32 Build & Release / build (push) Successful in 6m41s
104 lines
2.6 KiB
C
104 lines
2.6 KiB
C
/*
|
|
* MTG RFID Companion - Wi-Fi manager (Core 0)
|
|
*
|
|
* 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, NVS).
|
|
* @return ESP_OK on success.
|
|
*/
|
|
esp_err_t wifi_manager_init(void);
|
|
|
|
/**
|
|
* @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 in NVS or Kconfig.
|
|
*/
|
|
bool wifi_manager_sta_configured(void);
|
|
|
|
/**
|
|
* @brief True if the STA currently has a valid IP address.
|
|
*/
|
|
bool wifi_manager_connected(void);
|
|
|
|
/**
|
|
* @brief Block until connected or timeout. Returns ESP_OK if connected.
|
|
*/
|
|
esp_err_t wifi_manager_wait_connected(TickType_t timeout_ticks);
|
|
|
|
/**
|
|
* @brief Get the STA IP address as a string (or "No Wi-Fi" if disconnected).
|
|
*/
|
|
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 |