zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【ESP8266之LUA开发】八、SSID和PWD的保存与读取

开发 读取 保存 lua Esp8266 pwd
2023-09-11 14:20:36 时间

SSID及PWD的保存和读取

模块启动的时候查看一下设置的wifi.ap.configwifi.sta.config
如果有就设置原来保存的,没有设置才设置成程序中的,
然后进行打印相应的ssidpwd

写入函数之前保存参数的方法×××.save = true --保存

...
cfg={}
cfg = wifi.ap.getconfig(true)
if  cfg.ssid == nil then
    cfg.ssid="Hellow8266"
    cfg.pwd="11223344"
end

print("APssid: "..cfg.ssid)
if  cfg.pwd == nil then
    print("APpwd: nil")
else
    print("APpwd: "..cfg.pwd)
end 
cfg.save = true  
wifi.ap.config(cfg)




apcfg={}
apcfg = wifi.sta.getconfig(true)
if  apcfg.ssid == nil then
    apcfg.ssid="qqqqq"
    apcfg.pwd="11223344"
end
print("APssid: "..apcfg.ssid)
if  apcfg.pwd == nil then
    print("Stationpwd: nil")
else
    print("Stationpwd: "..apcfg.pwd)
end 
apcfg.save = true 
wifi.sta.config(apcfg)
wifi.sta.autoconnect(1)
...