Files
lucky-cat/components/platform/internal/wifi_portal.h
T

86 lines
2.5 KiB
C

#pragma once
#include "esp_err.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
void (*set_keep_awake)(bool keep_awake);
esp_err_t (*play_prompt_file)(const char *path);
} wifi_portal_behavior_hooks_t;
/**
* @brief Initialize Wi-Fi portal defaults and seed credentials.
*
* This writes the provided SSID/password into NVS if no credentials exist yet.
* The underlying Wi-Fi manager is initialized lazily when starting STA or AP.
*/
esp_err_t wifi_portal_init_defaults(const char *seed_ssid, const char *seed_password);
/**
* @brief Check if any Wi-Fi credentials are stored in NVS.
*/
bool wifi_portal_has_saved_credentials(void);
/**
* @brief Check whether the STA interface is connected (has an IP).
*
* This does not start/stop Wi-Fi; it only reports the current connection
* state.
*/
bool wifi_portal_sta_is_connected(void);
/**
* @brief Start the captive portal configuration AP.
*
* Stops the STA interface if running and launches the SoftAP/web portal.
*/
esp_err_t wifi_portal_start_config_ap(const char *ssid_prefix);
/**
* @brief Attempt to connect to a saved Wi-Fi network.
*
* Stops the portal if it is running, starts the station interface and waits
* for the connection to succeed within the provided timeout (milliseconds).
*/
esp_err_t wifi_portal_connect_sta(int timeout_ms);
/**
* @brief Trial-connect with credentials without persisting them first.
*
* On success, the trial credentials atomically replace the saved credential
* list. On failure, the previous in-memory and NVS credentials remain intact.
*/
esp_err_t wifi_portal_connect_sta_with_credentials(const char *ssid,
const char *password,
int timeout_ms);
esp_err_t wifi_portal_reconnect_sta(int timeout_ms);
esp_err_t wifi_portal_stop_sta(void);
/**
* @brief Save Wi-Fi credentials into NVS.
*
* The saved credentials become the highest priority network.
*/
esp_err_t wifi_portal_save_credentials(const char *ssid, const char *password);
/**
* @brief Clear all saved Wi-Fi credentials.
*
* This wipes the SsidManager list (Wi-Fi driver stays initialized).
*/
esp_err_t wifi_portal_clear_saved_credentials(void);
/**
* @brief Register behavior hooks for keep-awake and voice prompts.
*
* Passing NULL clears registered hooks and falls back to no-op behavior.
*/
void wifi_portal_set_behavior_hooks(const wifi_portal_behavior_hooks_t *hooks);
#ifdef __cplusplus
}
#endif