ESP8266 Developer Zone The Official ESP8266 Forum 2022-03-14T11:21:03+08:00 https://bbs.espressif.com:443/feed.php?f=62&t=75304 2022-03-14T11:21:03+08:00 2022-03-14T11:21:03+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75304&p=100763#p100763 <![CDATA[Re: ESP8266 successfully connects to computer wifi hotspot, but not home wifi]]>
e.g. net.dns.setdnsserver("8.8.8.8", 0)

Statistics: Posted by carlojoe — Mon Mar 14, 2022 11:21 am


]]>
2022-03-05T13:31:49+08:00 2022-03-05T13:31:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75304&p=100732#p100732 <![CDATA[ESP8266 successfully connects to computer wifi hotspot, but not home wifi]]>

Code:

-- start of relevant code
conn = nil


-- This code defines the variable "conn" as a command to create a client.
-- Documentation for net.createConnection can be found here. https://nodemcu.readthedocs.io/en/dev/en/modules/net/#netcreateconnection
-- The format of the variable & parameters are: net.createConnection(type, secure); i.e. Type = TCP
conn=net.createConnection(net.TCP, 0)


-- This code attempts to connect to the IFTTT Maker channel on port 80.
-- Documentation for the :dns function can be found here: https://nodemcu.readthedocs.io/en/dev/en/modules/net/#netsocketdns
-- If a connection can be made, then the connection function below will be executed, and the IP address printed.

conn:dns("maker.ifttt.com",function(conn,ip)

-- When connected to computer wifi, "ip" returns true and executes block.  When connected to home wifi "ip" returns false and the block is not executed.

    if (ip) then
        print("We can connect to " .. ip)
        conn:connect(80,ip)
    else
      dofile("3_delay.lua")
    end
end)

-- end of relevant code

Statistics: Posted by carlojoe — Sat Mar 05, 2022 1:31 pm


]]>