Skip to content

Commit

Permalink
add wifi AP mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Aug 7, 2024
1 parent 814d8c9 commit 4cde22e
Show file tree
Hide file tree
Showing 2 changed files with 237 additions and 42 deletions.
78 changes: 48 additions & 30 deletions components/network/include/maix_wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,50 @@ namespace maix::network::wifi
/**
* WiFi AP info
* @maixpy maix.network.wifi.AP_Info
*/
*/
class AP_Info
{
public:
/**
* WiFi AP info SSID
* @maixpy maix.network.wifi.AP_Info.ssid
*/
*/
std::vector<uint8_t> ssid;

/**
* WiFi AP info BSSID
* @maixpy maix.network.wifi.AP_Info.bssid
*/
*/
std::string bssid;

/**
* WiFi AP info security
* @maixpy maix.network.wifi.AP_Info.security
*/
*/
std::string security;

/**
* WiFi AP info channel
* @maixpy maix.network.wifi.AP_Info.channel
*/
*/
int channel;

/**
* WiFi AP info frequency
* @maixpy maix.network.wifi.AP_Info.frequency
*/
*/
int frequency;

/**
* WiFi AP info rssi
* @maixpy maix.network.wifi.AP_Info.rssi
*/
*/
int rssi;

/**
* WiFi AP info ssid_str
* @maixpy maix.network.wifi.AP_Info.ssid_str
*/
*/
std::string ssid_str()
{
return std::string(ssid.begin(), ssid.end());
Expand All @@ -71,13 +71,13 @@ namespace maix::network::wifi
* List WiFi interfaces
* @return WiFi interface list, string type
* @maixpy maix.network.wifi.list_devices
*/
*/
std::vector<std::string> list_devices();

/**
* Wifi class
* @maixpy maix.network.wifi.Wifi
*/
*/
class Wifi
{
public:
Expand All @@ -86,22 +86,22 @@ namespace maix::network::wifi
* @param iface wifi interface name, default is wlan0
* @maixpy maix.network.wifi.Wifi.__init__
* @maixcdk maix.network.wifi.Wifi.Wifi
*/
*/
Wifi(std::string iface = "wlan0");
~Wifi();

/**
* Get current WiFi ip
* @return ip, string type, if network not connected, will return empty string.
* @maixpy maix.network.wifi.Wifi.get_ip
*/
*/
std::string get_ip();

/**
* Get current WiFi MAC address
* @return ip, string type.
* @maixpy maix.network.wifi.Wifi.get_mac
*/
*/
std::string get_mac();

/**
Expand All @@ -110,14 +110,14 @@ namespace maix::network::wifi
* attention, first time call this method will auto matically read config from file, and if call connect method will set cache.
* @return SSID, string type.
* @maixpy maix.network.wifi.Wifi.get_ssid
*/
*/
std::string get_ssid(bool from_cache = true);

/**
* Get current WiFi ip
* @return ip, string type, if network not connected, will return empty string.
* @maixpy maix.network.wifi.Wifi.get_gateway
*/
*/
std::string get_gateway();

// std::string get_channel();
Expand All @@ -131,20 +131,20 @@ namespace maix::network::wifi
* WiFi start scan AP info around in background.
* @return If success, return err.Err.ERR_NONE, else means failed.
* @maixpy maix.network.wifi.Wifi.start_scan
*/
*/
err::Err start_scan();

/**
* Get WiFi scan AP info.
* @return wifi.AP_Info list.
* @maixpy maix.network.wifi.Wifi.get_scan_result
*/
*/
std::vector<network::wifi::AP_Info> get_scan_result();

/**
* Stop WiFi scan AP info.
* @maixpy maix.network.wifi.Wifi.stop_scan
*/
*/
void stop_scan();

/**
Expand All @@ -155,41 +155,59 @@ namespace maix::network::wifi
* @param timeout connect timeout internal, unit second.
* @return If success, return err.Err.ERR_NONE, else means failed.
* @maixpy maix.network.wifi.Wifi.connect
*/
*/
err::Err connect(const std::string &ssid, const std::string &password, bool wait = true, int timeout = 60);

/**
* Disconnect from WiFi AP.
* @return If success, return err.Err.ERR_NONE, else means failed.
* @maixpy maix.network.wifi.Wifi.disconnect
*/
*/
err::Err disconnect();

/**
* See if WiFi is connected to AP.
* @return If connected return true, else false.
* @maixpy maix.network.wifi.Wifi.is_connected
*/
*/
bool is_connected();
// std::string get_rssi();

// AP mode
/**
* Start WiFi AP.
* @param ssid SSID of AP.
* @param password password of AP, if no password, leave it empty.
* @param ip ip address of hostap, default empty string means auto generated one according to hardware.
* @param netmask netmask, default 255.255.255.0, now only support 255.255.255.0 .
* @param mode WiFi mode, default g(IEEE 802.11g (2.4 GHz)), a = IEEE 802.11a (5 GHz), b = IEEE 802.11b (2.4 GHz).
* @param channel WiFi channel number, 0 means auto select. MaixCAM not support auto, will default channel 1.
* @param hidden hidden SSID or not.
* @return If success, return err.Err.ERR_NONE, else means failed.
* @maixpy maix.network.wifi.Wifi.start_ap
*/
err::Err start_ap(const std::string &ssid, const std::string &password,
const std::string &ip = "192.168.66.1", const std::string &netmask = "255.255.255.0",
int channel = 1, bool hidden = false,
const std::string &ssid_5g = "", const std::string &password_5g = "",
int channel_5g = 36, bool hidden_5g = false,
int bandwidth = 20, int bandwidth_5g = 20
);
std::string mode = "g", int channel = 0,
const std::string &ip = "192.168.66.1", const std::string &netmask = "255.255.255.0",
bool hidden = false);

/**
* Stop WiFi AP.
* @return If success, return err.Err.ERR_NONE, else means failed.
* @maixpy maix.network.wifi.Wifi.stop_ap
*/
err::Err stop_ap();

/**
* Whether WiFi is AP mode
* @return True if AP mode now, or False.
* @maixpy maix.network.wifi.Wifi.is_ap_mode
*/
bool is_ap_mode();

private:
std::string _iface;
bool _ap_mode;
std::string _ssid;
bool _ssid_cached;
};

} // namespace maix::wifi

Loading

0 comments on commit 4cde22e

Please sign in to comment.