I inserted a global 'owip' in init.lua and changed the structure a bit:
print("Connecting to wifi...")
wifi.setmode(wifi.STATION)
wifi.sta.config("xxx","xxx")
owip=nil
tmr.alarm(0, 1000, 1, function()
print(".")
ip = wifi.sta.getip()
if ( ( ip ~= nil ) and ( ip ~= "0.0.0.0" ) )then
print(ip)
tmr.stop(0)
sk=net.createConnection(net.TCP, 0)
sk:dns("api.openweathermap.org",function(conn,ip)
owip=ip
sk = nil
collectgarbage("collect")
dofile("weatherStation.lc")
end)
end
end )
In weatherStation.lua change the conn:connect line to:
conn:connect(80,owip)
Don't forget to compile.
Since then I have no problems any more. Hope that works for you as well.