Anyway the simplest way to test if table X contains element Y is just to say
if X[Y] then
-- . . .
end
Explore... Chat... Share...
if X[Y] then
-- . . .
end
print("Scanning for networks..")
function listap(tbl)
for k,v in pairs(tbl) do
print(k.." : "..v)
end
end
wifi.sta.getap(listap)
-- tmr.delay(10000) --> use tmr.alarm instead
tmr.alarm(0, 10000, 0, function()
--Connect if network available, create if not found
if tbl["TestAP"] then
tmr.stop(0)
print("Found Network TestAP")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
--dofile("yourfile.lua")
end
end)
else
tmr.stop(0)
print("Network not Found! Creating..")
cfg={}
cfg.ssid="TestAP"
cfg.pwd="87654321"
wifi.ap.config(cfg)
print(wifi.ap.getip())
end
end )
local tbl = {"bacon","apples","TestAP"}
print("Concatenated string ",table.concat(tbl,", "))
if tbl["TestAP"] then
print("it worked!")
else
print("Not found")
end
print("Set up wifi mode..")
wifi.setmode(wifi.STATIONAP)
wifi.sta.config("TestAP","87654321")
local tbl = {}
--Scan for available networks
print("Scanning for networks..")
function listap(tbl)
for k,v in pairs(tbl) do
print(k.." : "..v)
end
if tbl["TestAP"] then
print("Found Network TestAP")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
--dofile("yourfile.lua")
end
end)
else
print("Network not Found! Creating..")
cfg={}
cfg.ssid="TestAP"
cfg.pwd="87654321"
wifi.ap.config(cfg)
print(wifi.ap.getip())
end
end
wifi.sta.getap(listap)
ssid = 'MySSID'
found = nil
wifi.setmode(wifi.STATIONAP)
wifi.sta.getap(function(t)
--for k,v in pairs(t) do print(k.." : "..v) end
found = t[ssid] or false
end)
tmr.alarm(0, 500, 1, function()
if (found == nil) then
print('scanning...')
else
tmr.stop(0)
if (found == false) then
print('not found')
else
print('found', ssid, found)
end
end
end)
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]