print("Starting...") if pcall(function () print("Open config") dofile("config.lc") end) then print("STN NAME: " .. stnname) print("STN PASSWORD: " ..stnpsw) print("SSID: " .. ssid) print("WIFI PASSWORD: " .. password) if (tschanid ~= nil and tsapikey ~= nil) then print("TS CHANNEL ID: " .. tschanid) print("TS API KEY: " .. tsapikey) end if (wuapiid ~= nil and wuapikey ~= nil) then print("WU API ID: " .. wuapiid) print("WU API KEY: " .. wuapikey) end if (obitoken ~= nil and obidevid ~= nil) then print("OBIDOTS TOKEN: " .. obitoken) print("OBIDOTS DEVICE ID: " .. obidevid) end print("Connecting to WIFI...") --Configuring WiFi as STATION wifi.setmode(wifi.STATION) wifi.sta.config(ssid,password) wifi.sta.connect() if (ipaddr ~= nil and netmask ~= nil and gateway ~= nil) then print("IP Address: " .. ipaddr) print("Netmask: " .. netmask) print("Gateway IP: " .. gateway) wifi.sta.setip({ip=ipaddr,netmask=netmask,gateway=gateway}) print("Port: " .. wsport) end timeout = 0; tmr.alarm(1, 1000, 1, function() if wifi.sta.getip() == nil then print("Waiting for IP connection... " .. timeout) timeout = timeout + 1 if timeout >= 60 then print("Aborting attempt to connect to IP and rebooting back to original wifi configuration mode...") file.remove('config.lc') node.restart() end else tmr.stop(1) print("Connected, IP is "..wifi.sta.getip()) print("Ready for my own custom code!") dofile("main_bme280.lua") end end) else print("Enter configuration mode") dofile("init_ap.lua") end