libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
esp_wifi_client.hpp
1#pragma once
2
3#include "esp_def.hpp"
4
5#include "esp_event.h"
6#include "esp_netif.h"
7#include "esp_wifi.h"
8#include "net/wifi_client.hpp"
9
10namespace LibXR
11{
12
20{
21 public:
23
24
25 bool Enable() override;
26
27 void Disable() override;
28
29 WifiError Connect(const Config& config) override;
30
31 WifiError Disconnect() override;
32
33 bool IsConnected() const override;
34
35 IPAddressRaw GetIPAddress() const override;
36
37 MACAddressRaw GetMACAddress() const override;
38
39 WifiError Scan(ScanResult* out_list, size_t max_count, size_t& out_found) override;
40
41 int GetRSSI() const override;
42
43 private:
44 bool RegisterHandlers();
45 void UnregisterHandlers();
46 void ResetConnectionState();
47 void DrainEvents();
48
56 static void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id,
57 void* event_data);
58
59 static inline bool is_initialized_ =
60 false;
61 static inline esp_netif_t* netif_ = nullptr;
62
63 bool init_ok_ = false;
64 bool enabled_ = false;
65 bool handlers_registered_ = false;
66 bool connected_ = false;
67 bool got_ip_ = false;
68 char ip_str_[16] = {};
69 esp_event_handler_instance_t wifi_connected_handler_ = nullptr;
70 esp_event_handler_instance_t wifi_disconnected_handler_ = nullptr;
71 esp_event_handler_instance_t got_ip_handler_ = nullptr;
72 esp_event_handler_instance_t lost_ip_handler_ = nullptr;
73
75};
76
77} // namespace LibXR
ESP32 Wi-Fi 客户端实现 / ESP32 Wi-Fi client implementation.
MACAddressRaw GetMACAddress() const override
获取当前 MAC 地址 / Get MAC address
static bool is_initialized_
ESP 网络是否已初始化 / Netif initialized.
bool connected_
是否连接 / Whether WiFi is connected
IPAddressRaw GetIPAddress() const override
获取当前 IP 地址 / Get current IP address
LibXR::Semaphore semaphore_
状态同步信号量 / Event wait semaphore
WifiError Connect(const Config &config) override
连接到指定 WiFi 网络 / Connect to a WiFi network
void Disable() override
禁用网络接口(WiFi) / Disable the network interface
static esp_netif_t * netif_
ESP 默认 netif 对象 / Default netif.
bool enabled_
是否启用 / Whether WiFi is enabled
int GetRSSI() const override
获取当前 WiFi 信号强度(RSSI) / Get current signal strength
bool got_ip_
是否获取 IP / Whether IP is acquired
bool Enable() override
启用网络接口(WiFi) / Enable the network interface
WifiError Disconnect() override
断开当前 WiFi 连接 / Disconnect from the WiFi network
bool IsConnected() const override
检查是否已连接 / Check if currently connected
static void EventHandler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
事件处理回调 / Event handler callback
WifiError Scan(ScanResult *out_list, size_t max_count, size_t &out_found) override
扫描可用网络 / Scan for available WiFi networks
char ip_str_[16]
当前 IP 字符串 / Current IP string
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
Definition semaphore.hpp:23
WiFi 客户端接口 / WiFi Client Interface.
WifiError
WiFi 错误码 / Enumeration of WiFi error codes.
LibXR 命名空间
Definition ch32_can.hpp:14
原始 IPv4 地址 / Raw IPv4 address
Definition net.hpp:19
原始 MAC 地址 / Raw MAC address
Definition net.hpp:65
WiFi 连接配置 / WiFi connection configuration.
WiFi 扫描结果 / WiFi scan result.