Skip to content

Commit

Permalink
fix: wlan.connect支持指定bssid
Browse files Browse the repository at this point in the history
先让lua函数支持传bssid,然后再到bsp增加实现

https://gitee.com/openLuat/LuatOS/issues/I9L2WP
  • Loading branch information
wendal committed May 7, 2024
1 parent 9928d0f commit f3df433
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion components/wlan/luat_lib_wlan.c
Expand Up @@ -110,10 +110,11 @@ static int l_wlan_ready(lua_State* L){

/*
作为STATION时,连接到指定AP
@api wlan.connect(ssid, password, auto_reconnect)
@api wlan.connect(ssid, password, auto_reconnect, bssid)
@string AP的ssid
@string AP的password,可选
@int 0关闭自动重连,1开启自动重连.当前强制开启自动重连
@string AP的bssid,可选,必须是6字节
@return bool 发起连接成功返回true,否则返回false.注意,不代表连接AP成功!!
@usage
Expand All @@ -124,14 +125,23 @@ wlan.connect("myap")
-- 特殊模式, 重用之前的ssid和密码,本次直接连接
-- 注意, 前提是本次上电后已经传过ssid和或password,否则必失败
wlan.connect()
-- 特殊模式, 使用ssid和密码,本次连接指定bssid, 2024.5.7新增
local bssid = string.fromHex("00182946365f")
wlan.connect("myap", "12345678", 1, bssid)
*/
static int l_wlan_connect(lua_State* L){
const char* ssid = luaL_optstring(L, 1, "");
const char* password = luaL_optstring(L, 2, "");
size_t len = 0;
luat_wlan_conninfo_t info = {0};
info.auto_reconnection = 1;
memcpy(info.ssid, ssid, strlen(ssid));
memcpy(info.password, password, strlen(password));
const char* bssid = luaL_optlstring(L, 4, "", &len);
if (len == 6) {
memcpy(info.bssid, bssid, 6);
}

int ret = luat_wlan_connect(&info);
lua_pushboolean(L, ret == 0 ? 1 : 0);
Expand Down

0 comments on commit f3df433

Please sign in to comment.