Initial commit
This commit is contained in:
101
wifi_manager.h
Normal file
101
wifi_manager.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef WIFI_MANAGER_H
|
||||
#define WIFI_MANAGER_H
|
||||
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief WiFi connection status
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
WIFI_STATUS_DISCONNECTED = 0,
|
||||
WIFI_STATUS_CONNECTING,
|
||||
WIFI_STATUS_CONNECTED,
|
||||
WIFI_STATUS_ERROR
|
||||
} wifi_status_t;
|
||||
|
||||
/**
|
||||
* @brief WiFi event callback function type
|
||||
*
|
||||
* @param status Current WiFi status
|
||||
* @param ip_address IP address string (only valid when status is CONNECTED)
|
||||
*/
|
||||
typedef void (*wifi_event_callback_t)(wifi_status_t status, const char *ip_address);
|
||||
|
||||
/**
|
||||
* @brief Initialize WiFi manager
|
||||
*
|
||||
* @param ssid WiFi network name
|
||||
* @param password WiFi password
|
||||
* @param event_callback Optional callback function for WiFi events
|
||||
* @return esp_err_t ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t wifi_manager_init(const char *ssid, const char *password, wifi_event_callback_t event_callback);
|
||||
|
||||
/**
|
||||
* @brief Start WiFi connection
|
||||
*
|
||||
* @return esp_err_t ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t wifi_manager_start(void);
|
||||
|
||||
/**
|
||||
* @brief Stop WiFi connection
|
||||
*
|
||||
* @return esp_err_t ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t wifi_manager_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Get current WiFi connection status
|
||||
*
|
||||
* @return wifi_status_t Current WiFi status
|
||||
*/
|
||||
wifi_status_t wifi_manager_get_status(void);
|
||||
|
||||
/**
|
||||
* @brief Wait for WiFi connection with timeout
|
||||
*
|
||||
* @param timeout_ms Timeout in milliseconds (0 for indefinite wait)
|
||||
* @return true if connected, false if timeout
|
||||
*/
|
||||
bool wifi_manager_wait_for_connection(uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Get current IP address
|
||||
*
|
||||
* @param ip_str Buffer to store IP address string (minimum 16 chars)
|
||||
* @param buffer_size Size of the buffer
|
||||
* @return esp_err_t ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t wifi_manager_get_ip_address(char *ip_str, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize WiFi manager
|
||||
*
|
||||
* @return esp_err_t ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t wifi_manager_deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Check if WiFi is connected
|
||||
*
|
||||
* @return true if connected, false otherwise
|
||||
*/
|
||||
bool wifi_manager_is_connected(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WIFI_MANAGER_H
|
||||
Reference in New Issue
Block a user