-->
Page 1 of 2

PANIC: wifi.sta is nil

PostPosted: Thu Apr 12, 2018 4:50 pm
by Alexsander Magalhães
Hello everyone.
Im facing an issue for some days that I dont understand. I think its easier to show you.

First I call this function:

Code: Select allfunction 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:

Code: Select allfunction 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:

Code: Select allPANIC: 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.

Re: PANIC: wifi.sta is nil

PostPosted: Sun Apr 15, 2018 3:50 am
by marcelstoer
First I suggest you take a recent firmware. If you build it with the cloud builder or the Docker image it'll print to info about the firmware on start. That info will be helpful for debugging.

https://nodemcu.readthedocs.io/en/latest/en/build/

Re: PANIC: wifi.sta is nil

PostPosted: Mon Apr 16, 2018 10:56 am
by Alexsander Magalhães
marcelstoer wrote:First I suggest you take a recent firmware. If you build it with the cloud builder or the Docker image it'll print to info about the firmware on start. That info will be helpful for debugging.


Hello! First thanks for the answer, I was hoping that you could answer me.
I just built a fresh firmware from the cloud. I used master and NodeMCU PyFlasher.

This is what I got on the first run:
https://ibb.co/f6Cne7

Then I copied my init.lua inside using ESPlorer and got this:
Code: Select allSoft restart by user command
node.restart()
>
 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 26948, room 16
tail 4
chksum 0x3d
load 0x3ffe8000, len 2192, room 4
tail 12
chksum 0x7e
ho 0 tail 12 room 4
load 0x3ffe8890, len 136, room 12
tail 12
chksum 0x50
csum 0x50
Œãìƒoì’{‚ûN| (one line of gibberish)


NodeMCU custom build by frightanic.com
   branch: master
   commit: 67027c0d05f7e8d1b97104e05a3715f6ebc8d07f
   SSL: false
   modules: adc,file,gpio,net,node,pwm,sjson,tmr,uart,wifi
 build created on 2018-04-16 13:55
 powered by Lua 5.1.4 on SDK 2.2.1(cfd48f3)
lua: cannot open init.lua
> print(uart.setup(0, 115200, 8, 0, 1, 1 ))
115200
>
Communication with MCU...
Got answer! AutoDetect firmware...

Can't autodetect firmware, because proper answer not received.


Actually I have no clue.

Re: PANIC: wifi.sta is nil

PostPosted: Tue Apr 17, 2018 12:22 pm
by Alexsander Magalhães
On another note, what I'm trying to do is essentially configure the station after the softap is running a TCP server.

It can be done without node reset, right?
I thought it was simple