mn_wifi_ap.hpp
Go to the documentation of this file.
1 
20 #ifndef __MINILIB_NET_WIFI_AP_H__
21 #define __MINILIB_NET_WIFI_AP_H__
22 
23 #include "../mn_config.hpp"
24 
25 #include "../net/mn_basic_ip4_address.hpp"
26 #include "mn_wifi.hpp"
27 
28 namespace mn {
29  namespace device {
30 
36  public:
37 
41 
46  basic_network_device("wifiap") { }
50  ~basic_wifi_ap() { stop(true); }
51 
52  basic_wifi_ap(const basic_wifi_ap& other) = delete;
53  basic_wifi_ap& operator = (const basic_wifi_ap& other) = delete;
54 
77  int start(const char* ssid, auth_mode_t mode = auth_mode_t::Open, const char* passphrase = "",
78  bool storeCfgToFlash = false,
79  bool ipv6 = false, int channel = 13, bool ssid_hidden = false,
80  int max_connection = 4);
81 
86  int set_ipinfo(const ip4_adress_t& local_ip, const ip4_adress_t& gateway, const ip4_adress_t& subnet);
87 
92  int get_ipinfo(ip4_adress_t& local_ip, ip4_adress_t& gateway, ip4_adress_t& subnet) override {
93  local_ip = get_ip(); if(local_ip == MNNET_IPV4_ADDRESS_NONE) return -1;
94  gateway = get_gateway(); if(gateway == MNNET_IPV4_ADDRESS_NONE) return -2;
95  subnet = get_netmask(); if(subnet == MNNET_IPV4_ADDRESS_NONE) return -3;
96 
97  return 0;
98  }
103  bool stop(bool wifioff) override;
104 
109  virtual ip4_adress_t get_ip();
114  virtual ip4_adress_t get_broadcast();
119  virtual ip4_adress_t get_gateway();
124  virtual ip4_adress_t get_netmask();
125 
131  virtual const char* get_hostname();
137  virtual bool set_hostname(const char* hostname);
144  virtual uint8_t* get_mac(uint8_t* mac);
150  virtual const char* get_mac();
156  virtual uint32_t get_connected();
157 
161  operator uint32_t() { return get_connected(); }
165  operator ip4_adress_t() { return get_ip(); }
169  operator const char*() { return get_hostname(); }
170 
171  // basic_network_device
172  public:
173  int stop() override { return stop(true) ? 0 : 1; }
174  int open() override { if(is_enable()) return 0; else return -1; }
175  bool is_enable() override { return (get_mode() != WIFI_MODE_NULL); }
176  bool is_stream_support() override { return false; }
177  protected:
184  tcpip_adapter_ip_info_t get_ip_infos();
185 
189  virtual void on_wifi_event(esp_event_base_t event_base, int32_t event_id, void* event_data) override;
190 
194  virtual void on_start(esp_event_base_t event_base, void* event_data) { }
198  virtual void on_stop(esp_event_base_t event_base, void* event_data) { }
202  virtual void on_connected(esp_event_base_t event_base,void* event_data) { }
206  virtual void on_disconnected(esp_event_base_t event_base, void* event_data) { }
210  virtual void on_probereqrec(esp_event_base_t event_base, void* event_data) { }
211 
212  };
213  }
214 }
215 
216 
217 #endif // __MINILIB_NET_WIFI_AP_H__
static bool start()
Initialize the underlying TCP/IP stack.
Definition: mn_basic_netif.cpp:139
Definition: mn_network_device.hpp:30
Wifi AP class for the esp32.
Definition: mn_wifi_ap.hpp:34
virtual const char * get_hostname()
Get the hostname.
Definition: mn_wifi_ap.cpp:164
virtual void on_probereqrec(esp_event_base_t event_base, void *event_data)
Call on WIFI_EVENT_AP_PROBEREQRECVED event.
Definition: mn_wifi_ap.hpp:210
net::basic_ip4_address ip4_adress_t
Definition: mn_wifi_ap.hpp:38
virtual uint32_t get_connected()
Get the number of connected stations.
Definition: mn_wifi_ap.cpp:194
int get_ipinfo(ip4_adress_t &local_ip, ip4_adress_t &gateway, ip4_adress_t &subnet) override
Get IPv4 infos, local ip, gateway and subnet.
Definition: mn_wifi_ap.hpp:92
int stop() override
Closes device.
Definition: mn_wifi_ap.hpp:173
virtual ip4_adress_t get_ip()
Get Tte IPv4 address of the WiFi AP device.
Definition: mn_wifi_ap.cpp:217
int open() override
Opens device.
Definition: mn_wifi_ap.hpp:174
virtual ip4_adress_t get_broadcast()
Get the broadcast IP address,.
Definition: mn_wifi_ap.cpp:227
virtual void on_wifi_event(esp_event_base_t event_base, int32_t event_id, void *event_data) override
The basic wife event handler.
Definition: mn_wifi_ap.cpp:267
~basic_wifi_ap()
Basic destructor, stopped the Wifi.
Definition: mn_wifi_ap.hpp:50
virtual ip4_adress_t get_gateway()
Get the gateway IP address,.
Definition: mn_wifi_ap.cpp:232
virtual void on_start(esp_event_base_t event_base, void *event_data)
Call on WIFI_EVENT_AP_START event.
Definition: mn_wifi_ap.hpp:194
int set_ipinfo(const ip4_adress_t &local_ip, const ip4_adress_t &gateway, const ip4_adress_t &subnet)
Set IPv4 infos, local ip, gateway and subnet.
Definition: mn_wifi_ap.cpp:114
virtual ip4_adress_t get_netmask()
Get the netmask IP address,.
Definition: mn_wifi_ap.cpp:242
bool is_enable() override
Definition: mn_wifi_ap.hpp:175
virtual void on_connected(esp_event_base_t event_base, void *event_data)
Call on WIFI_EVENT_AP_STACONNECTED event.
Definition: mn_wifi_ap.hpp:202
bool is_stream_support() override
Definition: mn_wifi_ap.hpp:176
basic_wifi_ap(const basic_wifi_ap &other)=delete
basic_wifi_ap()
Construct the wifi ap object.
Definition: mn_wifi_ap.hpp:45
tcpip_adapter_ip_info_t get_ip_infos()
Get interface's IP address information.
Definition: mn_wifi_ap.cpp:207
virtual bool set_hostname(const char *hostname)
Set the hostname, only work when wifi are started.
Definition: mn_wifi_ap.cpp:175
virtual void on_stop(esp_event_base_t event_base, void *event_data)
Call on WIFI_EVENT_AP_STOP event.
Definition: mn_wifi_ap.hpp:198
virtual const char * get_mac()
Get the MAC of the WiFi AP device as string.
Definition: mn_wifi_ap.cpp:252
virtual void on_disconnected(esp_event_base_t event_base, void *event_data)
Call on WIFI_EVENT_AP_STADISCONNECTED event.
Definition: mn_wifi_ap.hpp:206
basic_wifi_ap & operator=(const basic_wifi_ap &other)=delete
wifi_mode_t get_mode(void)
Get current operating mode of WiFi.
Definition: mn_basic_wifi_net_if.cpp:63
A basic class for wifi.
Definition: mn_wifi.hpp:43
basic_wifi(const interface_t &type)
Construct this object.
Definition: mn_wifi.cpp:37
auth_mode
Authenticate modes.
Definition: mn_wifi.hpp:48
wifi_interface_type
Definition: mn_wifi.hpp:59
This class represents an internet (IP) version 6 host address.
Definition: mn_basic_ip4_address.hpp:38
#define MNNET_IPV4_ADDRESS_NONE
Definition: mn_basic_ip4_address.hpp:28
This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
Definition: mn_allocator_typetraits.hpp:25