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

User avatar
By BryanLee
#20762 at my wits end trying to figure out what's going wrong. I'm connecting to my wifi AP. I create the socket connection. I send the proper http get string. However my callback function is never executed. For that matter, I added a send callback function and it isn't executed either.

Code: Select allmajorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();node.info()
print("NodeMCU "..majorVer.."."..minorVer.."."..devVer)
wifi.setmode(wifi.STATION)
wifi.sta.config("Manetheren","lightburnme")
wifiStatus = 0
wifiRetries = 0
while (wifiStatus ~= 5) do
   wifi.sta.connect()
   wifiRetries = wifiRetries + 1
   wifiTimeout = 0
   wifiStatus=wifi.sta.status()
   while (wifiTimeout < 5 and wifiStatus ~= 5) do
      tmr.delay(5000000)
      wifiStatus=wifi.sta.status()
      wifiTimeout = wifiTimeout + 1
   end
   if (wifiRetries == 5 and wifiStatus ~= 5) then
      node.reset()
   end
end
print("Wifi Retries "..wifiRetries)
print("Wifi Connection Time "..wifiTimeout)
print(wifi.sta.status())
print(wifi.sta.getip())

hostname="www.google.com"
host="74.125.196.106"
relURL="/"


conn=net.createConnection(net.TCP, 0)
conn:on("connection", function(sck) print("connection made") end)
conn:on("receive", function(sck, c) print("receive callback") print(c) end )
conn:connect(80,host)
connSend="GET "..relURL.." HTTP/1.1\r\nHost: "..hostname.."\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n"
print("---------")
print(connSend)
print("---------")
conn:send(connSend, function(sent) print("connection sent") end)


The results:

Code: Select allNodeMCU 0.9.5
Wifi Retries 1
Wifi Connection Time 0
5
192.168.1.100   255.255.255.0   192.168.1.1
---------
GET / HTTP/1.1
Host: www.google.com
Connection: keep-alive
Accept: */*


---------


That ugly code at the start is sort of a "failed to connect to wifi" check. Any advice is greatly appreciated.
User avatar
By BryanLee
#20825 Yes, I have performed a tcpdump on the wifi router (running dd-wrt). And I can verify that it is connected to the host, and that the host sends back the proper http response and content.