luat_lib_wlan.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. @module wlan
  3. @summary wifi操作
  4. @catalog 外设API
  5. @version 1.0
  6. @date 2022.09.30
  7. @demo wlan
  8. @tag LUAT_USE_WLAN
  9. @usage
  10. --[[
  11. 提醒:
  12. 对于仅支持wifiscan的模块, 仅 init/scan/scanResult 函数是可用的
  13. 例如: Air780E/Air600E/Air780EG等仅支持wifiscan
  14. ]]
  15. */
  16. #include "luat_base.h"
  17. #include "luat_wlan.h"
  18. #define LUAT_LOG_TAG "wlan"
  19. #include "luat_log.h"
  20. uint32_t ipaddr_addr(const char *cp);
  21. static inline void to_ipv4(const char* data, uint8_t* dst) {
  22. uint32_t tmpip = ipaddr_addr(data);
  23. dst[3] = (tmpip >> 24) & 0xFF;
  24. dst[2] = (tmpip >> 16) & 0xFF;
  25. dst[1] = (tmpip >> 8) & 0xFF;
  26. dst[0] = (tmpip >> 0) & 0xFF;
  27. }
  28. /*
  29. 初始化
  30. @api wlan.init()
  31. @return bool 成功返回true,否则返回false
  32. */
  33. static int l_wlan_init(lua_State* L){
  34. int ret = luat_wlan_init(NULL);
  35. lua_pushboolean(L, ret == 0 ? 1 : 0);
  36. return 1;
  37. }
  38. /*
  39. 设置wifi模式
  40. @api wlan.setMode(mode)
  41. @int wifi模式
  42. @return bool 成功返回true,否则返回false
  43. @usage
  44. -- 设置为AP模式, 广播ssid, 接收wifi客户端的链接
  45. wlan.setMode(wlan.AP)
  46. -- 设置为STATION模式, 也是初始化后的默认模式
  47. wlan.setMode(wlan.STATION)
  48. -- 混合模式, 做AP又做STATION
  49. wlan.setMode(wlan.APSTA)
  50. */
  51. static int l_wlan_mode(lua_State* L){
  52. int mode = LUAT_WLAN_MODE_STA;
  53. if (lua_isinteger(L, 1)) {
  54. mode = lua_tointeger(L, 1);
  55. }
  56. else if (lua_isinteger(L, 2)) {
  57. mode = lua_tointeger(L, 2);
  58. }
  59. if (mode <= LUAT_WLAN_MODE_NULL || mode >= LUAT_WLAN_MODE_MAX) {
  60. mode = LUAT_WLAN_MODE_STA;
  61. }
  62. // switch (mode)
  63. // {
  64. // case LUAT_WLAN_MODE_NULL:
  65. // LLOGD("wlan mode NULL");
  66. // break;
  67. // case LUAT_WLAN_MODE_STA:
  68. // LLOGD("wlan mode STATION");
  69. // break;
  70. // case LUAT_WLAN_MODE_AP:
  71. // LLOGD("wlan mode AP");
  72. // break;
  73. // case LUAT_WLAN_MODE_APSTA:
  74. // LLOGD("wlan mode AP-STATION");
  75. // break;
  76. // default:
  77. // break;
  78. // }
  79. luat_wlan_config_t conf = {
  80. .mode = mode
  81. };
  82. int ret = luat_wlan_mode(&conf);
  83. lua_pushboolean(L, ret == 0 ? 1 : 0);
  84. return 1;
  85. }
  86. /*
  87. 作为STATION时,是否已经连接上AP,且获取IP成功
  88. @api wlan.ready()
  89. @return bool 已经连接成功返回true,否则返回false
  90. */
  91. static int l_wlan_ready(lua_State* L){
  92. lua_pushboolean(L, luat_wlan_ready());
  93. return 1;
  94. }
  95. /*
  96. 作为STATION时,连接到指定AP
  97. @api wlan.connect(ssid, password, auto_reconnect, bssid)
  98. @string AP的ssid
  99. @string AP的password,可选
  100. @int 0关闭自动重连,1开启自动重连.当前强制开启自动重连
  101. @string AP的bssid,可选,必须是6字节
  102. @return bool 发起连接成功返回true,否则返回false.注意,不代表连接AP成功!!
  103. @usage
  104. -- 普通模式,带密码
  105. wlan.connect("myap", "12345678")
  106. -- 普通模式,不带密码
  107. wlan.connect("myap")
  108. -- 特殊模式, 重用之前的ssid和密码,本次直接连接
  109. -- 注意, 前提是本次上电后已经传过ssid和或password,否则必失败
  110. wlan.connect()
  111. -- 特殊模式, 使用ssid和密码,本次连接指定bssid, 2024.5.7新增
  112. local bssid = string.fromHex("00182946365f")
  113. wlan.connect("myap", "12345678", 1, bssid)
  114. */
  115. static int l_wlan_connect(lua_State* L){
  116. const char* ssid = luaL_optstring(L, 1, "");
  117. const char* password = luaL_optstring(L, 2, "");
  118. size_t len = 0;
  119. luat_wlan_conninfo_t info = {0};
  120. info.auto_reconnection = 1;
  121. memcpy(info.ssid, ssid, strlen(ssid));
  122. memcpy(info.password, password, strlen(password));
  123. const char* bssid = luaL_optlstring(L, 4, "", &len);
  124. if (len == 6) {
  125. memcpy(info.bssid, bssid, 6);
  126. }
  127. int ret = luat_wlan_connect(&info);
  128. lua_pushboolean(L, ret == 0 ? 1 : 0);
  129. return 1;
  130. }
  131. /*
  132. 作为STATION时,断开AP
  133. @api wlan.disconnect()
  134. */
  135. static int l_wlan_disconnect(lua_State* L){
  136. (void)L;
  137. luat_wlan_disconnect();
  138. return 0;
  139. }
  140. /*
  141. 扫描wifi频段
  142. @api wlan.scan()
  143. @usage
  144. -- 注意, wlan.scan()是异步API,启动扫描后会马上返回
  145. -- wifi扫描成功后, 会有WLAN_SCAN_DONE消息, 读取即可
  146. sys.subscribe("WLAN_SCAN_DONE", function ()
  147. local results = wlan.scanResult()
  148. log.info("scan", "results", #results)
  149. for k,v in pairs(results) do
  150. log.info("scan", v["ssid"], v["rssi"], (v["bssid"]:toHex()))
  151. end
  152. end)
  153. -- 下面演示的是初始化wifi后定时扫描,请按实际业务需求修改
  154. sys.taskInit(function()
  155. sys.wait(1000)
  156. wlan.init()
  157. while 1 do
  158. wlan.scan()
  159. sys.wait(15000)
  160. end
  161. end)
  162. */
  163. static int l_wlan_scan(lua_State* L){
  164. (void)L;
  165. luat_wlan_scan();
  166. return 0;
  167. }
  168. /*
  169. 获取wifi扫描结果
  170. @api wlan.scanResult()
  171. @return table 扫描结果
  172. @usage
  173. -- 用法请查阅 wlan.scan() 函数
  174. */
  175. static int l_wlan_scan_result(lua_State* L) {
  176. int ap_limit = luaL_optinteger(L, 1, 20);
  177. if (ap_limit > 32)
  178. ap_limit = 32;
  179. else if (ap_limit < 8)
  180. ap_limit = 8;
  181. lua_newtable(L);
  182. luat_wlan_scan_result_t *results = luat_heap_malloc(sizeof(luat_wlan_scan_result_t) * ap_limit);
  183. if (results == NULL) {
  184. LLOGE("out of memory when malloc scan result");
  185. return 1;
  186. }
  187. memset(results, 0, sizeof(luat_wlan_scan_result_t) * ap_limit);
  188. int len = luat_wlan_scan_get_result(results, ap_limit);
  189. for (int i = 0; i < len; i++)
  190. {
  191. lua_newtable(L);
  192. lua_pushstring(L, (const char *)results[i].ssid);
  193. lua_setfield(L, -2, "ssid");
  194. // lua_pushfstring(L, "%02X%02X%02X%02X%02X%02X", results[i].bssid[0],
  195. // results[i].bssid[1],
  196. // results[i].bssid[2],
  197. // results[i].bssid[3],
  198. // results[i].bssid[4],
  199. // results[i].bssid[5]);
  200. lua_pushlstring(L, (const char *)results[i].bssid, 6);
  201. lua_setfield(L, -2, "bssid");
  202. lua_pushinteger(L, results[i].ch);
  203. lua_setfield(L, -2, "channel");
  204. lua_pushinteger(L, results[i].rssi);
  205. lua_setfield(L, -2, "rssi");
  206. lua_seti(L, -2, i + 1);
  207. }
  208. luat_heap_free(results);
  209. return 1;
  210. }
  211. /*
  212. 配网
  213. @api wlan.smartconfig(mode)
  214. @int 配网模式, 默认为esptouch, 若传0则主动停止配网
  215. @return bool 启动成功或停止成功, 返回true, 否则返回false
  216. @usage
  217. wlan.smartconfig()
  218. local ret, ssid, passwd = sys.waitUntil("SC_RESULT", 180*1000) -- 最多等3分钟
  219. log.info("sc", ret, ssid, passwd)
  220. -- 详细用法请查看demo
  221. */
  222. static int l_wlan_smartconfig(lua_State *L) {
  223. int tp = luaL_optinteger(L, 1, LUAT_SC_TYPE_ESPTOUCH);
  224. if (tp == LUAT_SC_TYPE_STOP) {
  225. luat_wlan_smartconfig_stop();
  226. lua_pushboolean(L, 1);
  227. }
  228. else {
  229. int ret = luat_wlan_smartconfig_start(tp);
  230. lua_pushboolean(L, ret == 0 ? 1 : 0);
  231. }
  232. return 1;
  233. }
  234. /*
  235. 获取mac
  236. @api wlan.getMac(tp, hexstr)
  237. @int 设置何种mac地址,对ESP32系列来说,只能设置STA的地址,即0,默认值也是0
  238. @bool 是否转HEX字符, 默认是true,即输出hex字符串
  239. @return string MAC地址,十六进制字符串形式 "AABBCCDDEEFF" 或原始数据
  240. log.info("wlan mac", wlan.getMac())
  241. */
  242. static int l_wlan_get_mac(lua_State* L){
  243. uint8_t tmp[6] = {0};
  244. char tmpbuff[16] = {0};
  245. luat_wlan_get_mac(luaL_optinteger(L, 1, 0), (char*)tmp);
  246. if (lua_isboolean(L, 2) && !lua_toboolean(L, 2)) {
  247. lua_pushlstring(L, (const char*)tmp, 6);
  248. }
  249. else {
  250. sprintf_(tmpbuff, "%02X%02X%02X%02X%02X%02X", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
  251. lua_pushstring(L, tmpbuff);
  252. }
  253. return 1;
  254. }
  255. /*
  256. 设置mac
  257. @api wlan.setMac(tp, mac)
  258. @int 设置何种mac地址,对ESP32系列来说,只能设置STA的地址,即0
  259. @string 待设置的MAC地址,长度6字节
  260. @return bool 成功返回true,否则返回false
  261. @usage
  262. -- 设置MAC地址, 2023-03-01之后编译的固件可用
  263. local mac = string.fromHex("F01122334455")
  264. wlan.setMac(0, mac)
  265. -- 部分模块支持恢复默认MAC, 例如esp32系列
  266. -- 在2023-11-01 之后编译的固件可用
  267. local mac = string.fromHex("000000000000")
  268. wlan.setMac(0, mac)
  269. */
  270. static int l_wlan_set_mac(lua_State* L){
  271. // int id = luaL_optinteger(L, 1, 0);
  272. const char* mac = luaL_checkstring(L, 2);
  273. int ret = luat_wlan_set_mac(luaL_optinteger(L, 1, 0), mac);
  274. lua_pushboolean(L, ret == 0 ? 1 : 0);
  275. return 1;
  276. }
  277. /*
  278. 获取ip,仅STATION或APSTA模式下有意义
  279. @api wlan.getIP()
  280. @return string ip地址,当前仅返回ipv4地址,例如 "192.168.1.25"
  281. */
  282. static int l_wlan_get_ip(lua_State* L){
  283. char tmpbuff[16] = {0};
  284. luat_wlan_get_ip(luaL_optinteger(L, 1, 0), tmpbuff);
  285. lua_pushstring(L, tmpbuff);
  286. return 1;
  287. }
  288. /*
  289. 启动AP
  290. @api wlan.createAP(ssid, passwd, gateway, netmask, channel, opts)
  291. @string AP的SSID,必填
  292. @string AP的密码,可选
  293. @string AP的网关地址, 默认192.168.4.1
  294. @string AP的网关掩码, 默认255.255.255.0
  295. @int AP建立的通道, 默认6
  296. @table AP的配置选项, 可选
  297. @return bool 成功创建返回true,否则返回false
  298. @usage
  299. -- 注意, 调用本AP时,若wifi模式为STATION,会自动切换成 APSTA
  300. wlan.createAP("luatos1234", "12341234")
  301. -- 设置网关IP,掩码, 通道, 2023.7.13 新增, BSP未必支持
  302. -- wlan.createAP("luatos1234", "12341234", "192.168.4.1", "255.255.255.0", 6)
  303. -- opts更多配置项, 2024.3.5新增
  304. --[[
  305. {
  306. hidden = false, -- 是否隐藏SSID, 默认false,不隐藏
  307. max_conn = 4 -- 最大客户端数量, 默认4
  308. }
  309. ]]
  310. */
  311. #include "lwip/opt.h"
  312. #include "lwip/ip_addr.h"
  313. #include "lwip/netif.h"
  314. static int l_wlan_ap_start(lua_State *L) {
  315. size_t ssid_len = 0;
  316. size_t password_len = 0;
  317. luat_wlan_apinfo_t apinfo = {0};
  318. const char* ssid = luaL_checklstring(L, 1, &ssid_len);
  319. const char* password = luaL_optlstring(L, 2, "", &password_len);
  320. const char* gateway = luaL_optstring(L, 3, "192.168.4.1");
  321. const char* netmask = luaL_optstring(L, 4, "255.255.255.0");
  322. if (strlen(gateway) > 7) {
  323. to_ipv4(gateway, apinfo.gateway);
  324. }
  325. if (strlen(netmask) > 7) {
  326. to_ipv4(netmask, apinfo.netmask);
  327. }
  328. apinfo.channel = (uint8_t)luaL_optinteger(L, 5, 6);
  329. if (ssid_len < 1) {
  330. LLOGE("ssid MUST NOT EMTRY");
  331. return 0;
  332. }
  333. if (ssid_len > 32) {
  334. LLOGE("ssid too long [%s]", ssid);
  335. return 0;
  336. }
  337. if (password_len > 63) {
  338. LLOGE("password too long [%s]", password);
  339. return 0;
  340. }
  341. if (lua_istable(L, 6)) {
  342. lua_getfield(L, 6, "hidden");
  343. apinfo.hidden = lua_toboolean(L, -1);
  344. lua_pop(L, 1);
  345. lua_getfield(L, 6, "max_conn");
  346. apinfo.max_conn = lua_tonumber(L, -1);
  347. lua_pop(L, 1);
  348. }
  349. memcpy(apinfo.ssid, ssid, ssid_len);
  350. memcpy(apinfo.password, password, password_len);
  351. int ret = luat_wlan_ap_start(&apinfo);
  352. if (ret)
  353. LLOGD("apstart ret %d", ret);
  354. lua_pushboolean(L, ret == 0 ? 1 : 0);
  355. return 1;
  356. }
  357. /**
  358. 关闭AP功能
  359. @api wlan.stopAP()
  360. @return bool 成功创建返回true,否则返回false
  361. @usage
  362. wlan.stopAP()
  363. */
  364. static int l_wlan_ap_stop(lua_State *L) {
  365. int ret = luat_wlan_ap_stop();
  366. if (ret)
  367. LLOGD("apstop ret %d", ret);
  368. lua_pushboolean(L, ret == 0 ? 1 : 0);
  369. return 1;
  370. }
  371. /*
  372. 获取信息,如AP的bssid,信号强度, STA联网后可获取
  373. @api wlan.getInfo()
  374. @return table 详情,键值对形式
  375. @usage
  376. log.info("wlan", "info", json.encode(wlan.getInfo()))
  377. --[[
  378. 典型输出
  379. {
  380. "bssid" : "xxxxxx",
  381. "rssi" : -89,
  382. "gw" : "192.168.1.1"
  383. }
  384. ]]
  385. */
  386. static int l_wlan_get_info(lua_State *L) {
  387. uint8_t buff[48] = {0};
  388. char buff2[32] = {0};
  389. lua_newtable(L);
  390. luat_wlan_get_ap_bssid((char*)buff);
  391. sprintf_(buff2, "%02X%02X%02X%02X%02X%02X", buff[0], buff[1], buff[2], buff[3], buff[4], buff[5]);
  392. lua_pushstring(L, buff2);
  393. lua_setfield(L, -2, "bssid");
  394. memset(buff, 0, 48);
  395. luat_wlan_get_ap_gateway((char*)buff);
  396. lua_pushstring(L, (const char*)buff);
  397. lua_setfield(L, -2, "gw");
  398. lua_pushinteger(L, luat_wlan_get_ap_rssi());
  399. lua_setfield(L, -2, "rssi");
  400. return 1;
  401. }
  402. /*
  403. 读取或设置省电模式
  404. @api wlan.powerSave(mode)
  405. @int 省电模式,可选, 传入就是设置, 例如wlan.PS_NONE
  406. @return int 当前省电模式/设置后的省电模式
  407. @usage
  408. -- 请查阅常量表 PS_NONE/PS_MIN_MODEM/PS_MAX_MODEM
  409. log.info("wlan", "PS", wlan.powerSave(wlan.PS_NONE))
  410. -- 本API于 2023.03.31 新增
  411. */
  412. static int l_wlan_powerSave(lua_State *L) {
  413. int mode = 0;
  414. if (lua_isinteger(L, 1)) {
  415. mode = luaL_checkinteger(L, 1);
  416. luat_wlan_set_ps(mode);
  417. }
  418. mode = luat_wlan_get_ps();
  419. lua_pushinteger(L, mode);
  420. return 1;
  421. }
  422. /*
  423. 读取或设置Hostname
  424. @api wlan.hostname(id, new_name)
  425. @int STA为0, AP为1. 本参数需要2025.2.25及之后编译的固件
  426. @string 新的hostname,可选, 传入就是设置
  427. @return string 当前的hostname或者设置后的hostname
  428. @usage
  429. -- 本API于 2023.07.23 新增
  430. -- 本函数应该在wlan.init之前设置好, 最晚应早于wlan.connect
  431. -- hostname的默认值是 "LUATOS_" + 设备的MAC值
  432. -- 例如: LUATOS_0022EECC2399
  433. -- 老写法, 直接设置STA的hostname
  434. wlan.hostname("我的wifi物联网设备")
  435. -- 新的API, 支持设置STA或AP的hostname, 也可以分别取
  436. wlan.hostname(1, "myhost")
  437. wlan.hostname(0) -- 取STA的hostname
  438. */
  439. static int l_wlan_get_set_hostname(lua_State *L) {
  440. int id = 0;
  441. if (lua_type(L, 1) == LUA_TNUMBER) {
  442. id = luaL_checkinteger(L, 1);
  443. if (lua_type(L, 2) == LUA_TSTRING) {
  444. size_t len = 0;
  445. const char* hostname = luaL_checklstring(L, 2, &len);
  446. if (len > 0) {
  447. if (len > 31) {
  448. LLOGE("hostname is too long");
  449. return 0;
  450. }
  451. luat_wlan_set_hostname(id, hostname);
  452. }
  453. }
  454. }
  455. if (lua_type(L, 1) == LUA_TSTRING) {
  456. size_t len = 0;
  457. const char* hostname = luaL_checklstring(L, 1, &len);
  458. if (len > 0) {
  459. if (len > 31) {
  460. LLOGE("hostname is too long");
  461. return 0;
  462. }
  463. luat_wlan_set_hostname(0, hostname);
  464. }
  465. }
  466. const char* tmp = luat_wlan_get_hostname(id);
  467. lua_pushstring(L, tmp);
  468. return 1;
  469. }
  470. /*
  471. 设置Station模式下的IP获取模式
  472. @api wlan.staIp(dhcp_enable, ip, netmask, gateway)
  473. @bool 是否启用DHCP,默认是true
  474. @string 本机IP地址,例如192.168.2.200, 禁用DHCP时必填
  475. @string 本机IP掩码,例如255.255.255.0, 禁用DHCP时必填
  476. @string 本机IP网关,例如192.168.2.1, 禁用DHCP时必填
  477. @return bool 成功返回true,否则返回false
  478. @usage
  479. -- 本API于 2023.10.06 新增
  480. -- 本函数需要在wlan.init之后才允许调用
  481. -- 启用DHCP, 默认也是启用DHCP,这里是演示API使用
  482. wlan.staIp(true)
  483. -- 禁用DHCP,自行设置IP/掩码/网关
  484. wlan.staIp(false, "192.168.2.200", "255.255.255.0", "192.168.2.1")
  485. */
  486. static int l_wlan_set_sta_ip(lua_State *L) {
  487. luat_wlan_station_info_t info = {
  488. .dhcp_enable = 1
  489. };
  490. const char *data = NULL;
  491. size_t len = 0;
  492. // 是否DHCP
  493. if (lua_isinteger(L, 1))
  494. info.dhcp_enable = luaL_optinteger(L, 1, 1);
  495. else if (lua_isboolean(L, 1))
  496. info.dhcp_enable = lua_toboolean(L, 1);
  497. // 本地IP
  498. data = luaL_optlstring(L, 2, "192.168.1.201", &len);
  499. to_ipv4(data, info.ipv4_addr);
  500. // 掩码
  501. data = luaL_optlstring(L, 3, "255.255.255.0", &len);
  502. to_ipv4(data, info.ipv4_netmask);
  503. // 网关
  504. data = luaL_optlstring(L, 4, "192.168.1.1", &len);
  505. to_ipv4(data, info.ipv4_gateway);
  506. int ret = luat_wlan_set_station_ip(&info);
  507. lua_pushboolean(L, ret == 0 ? 1 : 0);
  508. return 1;
  509. }
  510. #include "rotable2.h"
  511. static const rotable_Reg_t reg_wlan[] =
  512. {
  513. { "init", ROREG_FUNC(l_wlan_init)},
  514. { "scan", ROREG_FUNC(l_wlan_scan)},
  515. { "scanResult", ROREG_FUNC(l_wlan_scan_result)},
  516. #ifndef LUAT_USE_WLAN_SCANONLY
  517. { "mode", ROREG_FUNC(l_wlan_mode)},
  518. { "setMode", ROREG_FUNC(l_wlan_mode)},
  519. { "ready", ROREG_FUNC(l_wlan_ready)},
  520. { "connect", ROREG_FUNC(l_wlan_connect)},
  521. { "disconnect", ROREG_FUNC(l_wlan_disconnect)},
  522. // 配网相关
  523. { "smartconfig", ROREG_FUNC(l_wlan_smartconfig)},
  524. { "getIP", ROREG_FUNC(l_wlan_get_ip)},
  525. { "getInfo", ROREG_FUNC(l_wlan_get_info)},
  526. { "getMac", ROREG_FUNC(l_wlan_get_mac)},
  527. { "setMac", ROREG_FUNC(l_wlan_set_mac)},
  528. { "hostname", ROREG_FUNC(l_wlan_get_set_hostname)},
  529. { "powerSave", ROREG_FUNC(l_wlan_powerSave)},
  530. { "staIp", ROREG_FUNC(l_wlan_set_sta_ip)},
  531. // AP相关
  532. { "createAP", ROREG_FUNC(l_wlan_ap_start)},
  533. { "stopAP", ROREG_FUNC(l_wlan_ap_stop)},
  534. // wifi模式
  535. //@const NONE WLAN模式,停用
  536. {"NONE", ROREG_INT(LUAT_WLAN_MODE_NULL)},
  537. //@const STATION WLAN模式,STATION模式,主动连AP
  538. {"STATION", ROREG_INT(LUAT_WLAN_MODE_STA)},
  539. //@const AP WLAN模式,AP模式,接受STATION连接
  540. {"AP", ROREG_INT(LUAT_WLAN_MODE_AP)},
  541. //@const AP WLAN模式,混合模式
  542. {"STATIONAP", ROREG_INT(LUAT_WLAN_MODE_APSTA)},
  543. // 配网模式
  544. //@const STOP 停止配网
  545. {"STOP", ROREG_INT(LUAT_SC_TYPE_STOP)},
  546. //@const ESPTOUCH esptouch配网, V1
  547. {"ESPTOUCH", ROREG_INT(LUAT_SC_TYPE_ESPTOUCH)},
  548. //@const AIRKISS Airkiss配网, 微信常用
  549. {"AIRKISS", ROREG_INT(LUAT_SC_TYPE_AIRKISS)},
  550. //@const ESPTOUCH_AIRKISS esptouch和Airkiss混合配网
  551. {"ESPTOUCH_AIRKISS", ROREG_INT(LUAT_SC_TYPE_ESPTOUCH_AIRKISS)},
  552. //@const ESPTOUCH_V2 esptouch配网, V2, 未测试
  553. {"ESPTOUCH_V2", ROREG_INT(LUAT_SC_TYPE_ESPTOUCH_V2)},
  554. //@const PS_NONE 关闭省电模式
  555. {"PS_NONE", ROREG_INT(0)},
  556. //@const PS_MIN_MODEM 最小Modem省电模式
  557. {"PS_MIN_MODEM", ROREG_INT(1)},
  558. //@const PS_MAX_MODEM 最大Modem省电模式
  559. {"PS_MAX_MODEM", ROREG_INT(2)},
  560. #endif
  561. { NULL, ROREG_INT(0)}
  562. };
  563. LUAMOD_API int luaopen_wlan( lua_State *L ) {
  564. luat_newlib2(L, reg_wlan);
  565. return 1;
  566. }