As the title says... Chat on...

User avatar
By xtal
#30828 Heres a snippit I use..
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("NETGEAR","mikeis12345")

tmr.alarm(0, 1000, 1, function(QQ)   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)

Seems like I tried the Status and decided that it only workes when connected as AP
User avatar
By Keith Richardson
#31378 I had a lot of problems getting a reliable method of connecting to an AP. This code I have found to be bullet proof (so far)

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("ssid", "password")

function Success()
   tmr.stop(0)
   print("IP: " .. wifi.sta.getip())
   wifi.sta.eventMonStop()   
   wifi.sta.eventMonReg(wifi.STA_GOTIP, "unreg")
   dofile("program.lua")
end

function Failure()
   print("Unable to connect")
   wifi.sta.eventMonStop()   
   wifi.sta.eventMonReg(wifi.STA_GOTIP, "unreg")
   return 0
end
   
tmr.alarm(0,30000,0, function() Failure() end)
wifi.sta.connect()
wifi.sta.eventMonReg(wifi.STA_GOTIP, function() Success() end)
wifi.sta.eventMonStart()



This is my init.lua, program.lua is where the actual application lives. I will eventually remove the print statements, and success or failure will be indicated by a green or red LED lighting for a few seconds.
User avatar
By lakkimsetty
#31845 Hello xtal,

I tried,
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("HelloMike", "mikeis12345")           -- The passwd is wrong.

tmr.alarm(0, 1000, 1, function()   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)

and,
Code: Select allwifi.setmode(wifi.STATIONAP)
wifi.sta.config("HelloMike", "mikeis12345")           -- The passwd is wrong.

tmr.alarm(0, 1000, 1, function()   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)


They always get status = 1.
Code: Select allwifi.setmode(wifi.STATIONAP)
wifi.sta.config("HelloMike", "mikeis12345", "so:me:th:in:gm:ac")           -- The passwd is wrong, MAC is correct.

tmr.alarm(0, 1000, 1, function()   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)

But if I give a BSSID in wifi.sta.config() then they return as status = 3 when wrong passwd is given.

Did you experience the same? Do you have a snippet that you can share which throws the status = 2?
User avatar
By xtal
#31852 I'm using this with Float-DEV 0.9.6 20150704 Firmware
I'm having no issues... The QQ is optional
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("12345-NETGEAR81","mikeis12345")    ---SSID    and PASSWORD

tmr.alarm(0, 1000, 1, function(QQ)   
   print("Try Connecting:")
   ip, nm, gw=wifi.sta.getip()
  if ip ~= nil then         
      print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)         
      tmr.stop(0)
   end
end)


I could increase the time [ie] tmr.alarm(0, 3000, 1, function(QQ)
-- 3 seconds depends signal strength/conectivity/traffic

this works also:
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PW")     --PWmust be at least 8

tmr.alarm(0, 1000, 1, function()
   ip = wifi.sta.status() 
   print("Connect Status: "..ip)
  if ip == 5 then                     
      tmr.stop(0)
      ip, nm, gw=wifi.sta.getip()
      print("\nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)     
   end
end)