ESP8266 successfully connects to computer wifi hotspot, but not home wifi

carlojoe
Posts: 2
Joined: Sat Mar 05, 2022 1:25 pm

ESP8266 successfully connects to computer wifi hotspot, but not home wifi

Postby carlojoe » Sat Mar 05, 2022 1:31 pm

My ESP8266 sends a call to IFTTT when a switch completes. When I connect the ESP8266 to my computer's wifi hot spot (which is ethernet wired into the home Netgear router), the call is sent successfully. However, when I attempt to connect the ESP8266 to the home wifi connected to the same home Netgear router, the call is not successfully sent out. And, when I look at the router logs it does show the registered MAC address of the ESP8266 and shows the assigned IP address. Nothing is blocked. If helpful, the code remains unchanged in both instances (other than changing the wifi login credentials). Also 6+ months ago the ESP8266 successfully connected to the home wifi as well. Any guidance on this head-scratching problem would be greatly appreciated.

Code: Select all

-- 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

carlojoe
Posts: 2
Joined: Sat Mar 05, 2022 1:25 pm

Re: ESP8266 successfully connects to computer wifi hotspot, but not home wifi

Postby carlojoe » Mon Mar 14, 2022 11:21 am

Turns out the problem was due to the DNS server being used on the home wifi was not reachable by the ESP. Once I set the DNS server explicitly on the ESP, everything worked great while using the home wifi.

e.g. net.dns.setdnsserver("8.8.8.8", 0)

Who is online

Users browsing this forum: No registered users and 7 guests