Chat freely about anything...

User avatar
By faramon
#65575 Hi,

if I have init.lua:
Code: Select allapp = require("application")
    config = require("config")
    setup = require("setup")
   
    function startup()
        setup.start()
    end
    tmr.alarm(0,9000,0,startup)

and in setup.lua:
Code: Select alllocal module = {}

module.timeout = 0;
local function wifi_wait_ip() 
  if wifi.sta.getip()== nil then
    print("IP unavailable, Waiting..."..module.timeout)
    module.timeout = module.timeout + 1
    if(module.timeout >= 10) then
        node.restart()
    end
  else
    tmr.stop(1)
    print("\n====================================")
    print("ESP8266 mode is: " .. wifi.getmode())
    print("MAC address is: " .. wifi.ap.getmac())
    print("IP is "..wifi.sta.getip())
    print("====================================")
    app.start()
  end
end

local function wifi_start(list_aps) 
    if list_aps then
        for key,value in pairs(list_aps) do
            if config.SSID and config.SSID[key] then
                wifi.setmode(wifi.STATION);
                wifi.sta.config(key,config.SSID[key])
                wifi.sta.connect()
                print("Connecting to " .. key .. " ...")
                --config.SSID = nil  -- can save memory
                tmr.alarm(1, 2500, 1, wifi_wait_ip)
            print("Connected!")
            end
        end
    else
        print("Error getting AP list")
        node.restart()
    end
end

function module.start()
  print("Configuring Wifi ...")
  wifi.setmode(wifi.STATION)
  wifi.sta.getap(wifi_start)
end

return module

will node.restart() in function wifi_wait_ip() restart whole NodeMcu?
I ask because for now instead of init.lua I have test.lua and this node.restart() shows some error in ESPlorer. Last night I went error, I will try to upload error that raise up, but now I'am not have my laptop and NodeMcu with me.

Thanx,
Faramon
Last edited by faramon on Fri May 05, 2017 3:13 am, edited 1 time in total.
User avatar
By faramon
#65576 I found post about node.restart() http://www.esp8266.com/viewtopic.php?f=19&t=2741&start=4
and I think I get same error: "ets Jan 8 2013,rst cause:4, boot mode:(3,6) ... (rest of boot message)"

But what this mean: The node.restart() schedules a reboot event, but the event itself doesn't fire until the current Lua processing completes? That lua scripts have to finish? how to finish proccess to fire event node.restart() immediate?

Thanx,
Faramon