Am able to get "Date: " line from payload.
See below for code.
Now.... I want to similarly GET data from a website that I am separately serving from an Arduino, that posts a page saying whether my garage door is up or down.
It is at http://ub.dyndns.org:8247/
Have tried all sorts of things in conn:connect(80,'google.com') line and
"Host: google.com\r\n".. lines.
Am NOT seeing the html of my Arduino web page in the payload of:
conn:on("receive", function(conn, payload)
Have tried using local IP addresses too without success.
I.e.: "Host: 192.168.1.77:8247.com\r\n"..
and
conn:connect(8247,'192.168.1.77')
(I am forwarding port 8247 to 192.168.1.77 in my router.)
No success there either.
Any ideas what to do to capture html of my http://ub.dyndns.org:8247/ into "payload".
Thanks for helping me.
Been working on this for days.
Code of "googleTime.lua" follows:
-- retrieve the current time from Google
-- tested on NodeMCU 0.9.5 build 20150108
conn=net.createConnection(net.TCP, 0)
conn:on("connection",function(conn, payload)
conn:send("HEAD / HTTP/1.1\r\n"..
"Host: google.com\r\n"..
"Accept: */*\r\n"..
"User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
"\r\n\r\n")
end)
conn:on("receive", function(conn, payload)
print('\nRetrieved in '..((tmr.now()-t)/1000)..' milliseconds.')
print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
+6,string.find(payload,"Date: ")+35))
conn:close()
end)
t = tmr.now()
conn:connect(80,'google.com')