Statistics: Posted by carlojoe — Mon Mar 14, 2022 11:21 am
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