Im facing an issue for some days that I dont understand. I think its easier to show you.
First I call this function:
function conHIB()
wifi.setmode(wifi.STATIONAP)
wifi.setphymode(wifi.PHYMODE_N)
AP_CFG={}
[...]
wifi.ap.config(AP_CFG)
wifi.ap.setip(AP_IP_CFG)
wifi.ap.dhcp.config(AP_DHCP_CFG)
wifi.ap.dhcp.start()
station_cfg={}
station_cfg.ssid = ""
station_cfg.pwd = ""
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg)
end
Then I create a TCP server.
When I get the pass and ssid for the station to connect, I call this function:
function conSTA()
station_cfg={}
station_cfg.ssid = _G.wifi
station_cfg.pwd = _G.senha
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg) -- this creates an error
wifi.sta.connect()
end
But then I get a PANIC error from ESPlorer console on the commented line, like:
PANIC: unprotected error in call to Lua API (attempt to index field 'sta' (a nil value))
I thought wifi. was a global object that I could use like _G. variables.
In fact, everything works fine if I just send the blocks separately to the console.
I can configure AP, STA, change wifi.setmode to whatever I want and it behaves accordingly.
I recall having problems with the TCP server when other functions took too much time to return, but I dont think this is the case.
I can post the whole code, its just about 300 lines, actually Im willing to share, I just didnt do it without showing this first.
Thanks in advance.