Skip to content

Commit

Permalink
add wifi get_ssid api and optimize build doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed May 30, 2024
1 parent 29c88f7 commit 0803b78
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/3rd_party/sdl/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def add_file_downloads(confs : dict) -> list:
sha256sum = "888b8c39f36ae2035d023d1b14ab0191eb1d26403c3cf4d4d5ede30e66a4942c"
else:
raise Exception(f"version {version} not support")
sites = ["https://github.com/sipeed/MaixCDK/releases/tag/v0.0.0"]
sites = ["https://github.com/libsdl-org/SDL/releases"]
filename = f"SDL2-{version}.tar.gz"
path = "sdl_srcs"
check_file = f'SDL2-{version}'
Expand Down
11 changes: 11 additions & 0 deletions components/network/include/maix_wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ namespace maix::network::wifi
*/
std::string get_mac();

/**
* Get current WiFi SSID
* @param from_cache if true, will not read config from file, direct use ssid in cache.
* 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.
Expand Down Expand Up @@ -178,6 +187,8 @@ namespace maix::network::wifi
private:
std::string _iface;
bool _ap_mode;
std::string _ssid;
bool _ssid_cached;
};

} // namespace maix::wifi
Expand Down
31 changes: 31 additions & 0 deletions components/network/port/linux/maix_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,35 @@ bssid / frequency / signal level / flags / ssid
(unsigned char)ifr.ifr_hwaddr.sa_data[5]);
return mac;
}

/**
* Get current WiFi SSID
* @return SSID, string type.
* @maixpy maix.network.wifi.Wifi.get_ssid
*/
std::string Wifi::get_ssid(bool from_cache)
{
if((!from_cache) || !_ssid_cached)
{
fs::File *f = fs::open("/boot/wifi.ssid", "r");
if(f)
{
std::string *ssid = f->readline();
_ssid = *ssid;
_ssid_cached = true;
delete ssid;
delete f;
}
else
{
_ssid = "";
_ssid_cached = true;
}
}
return _ssid;
}


std::string Wifi::get_gateway()
{
// get gateway ip
Expand All @@ -384,6 +413,8 @@ bssid / frequency / signal level / flags / ssid
err::Err Wifi::connect(const std::string &ssid, const std::string &password, bool wait, int timeout)
{
uint64_t t = time::time();
_ssid = ssid;
_ssid_cached = true;
#if PLATFORM_MAIXCAM
// write ssid to /boot/wifi.ssid and password to /boot/wifi.pass
// then opoen /etc/init.d/S30wifi restart
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/dev/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pip install -U -r requirements.txt # 安装依赖
cd projects/hello_world
maixcdk menuconfig
```
然后在选项`Platform`中选择你的设备名,然后按`ESC`按键,再按`Y`保存退出。
根据提示选择设备平台,会出来一个界面可以配置一些参数,初次使用用默认的参数即可(用默认的参数也可以不执行 menuconfig, 直接执行 build 命令),然后按`ESC`按键,再按`Y`保存退出。

```shell
maixcdk build
Expand Down

0 comments on commit 0803b78

Please sign in to comment.