-->
Page 2 of 4

Re: Show sensorreading on external webserver

PostPosted: Tue Dec 02, 2014 4:31 pm
by Erni
Ok,
Here is the example with dns lookup.
Thanks to gerardwr and scargill


Code: Select allfile.remove("client.lua")
file.remove("client.lua")
file.open("client.lua","w+")
host="www.ernstc.dk"
ipnr=0
file.writeline([[tmr.alarm(30000, 1, function()]])
file.writeline([[sk=net.createConnection(net.TCP, 0)]])
file.writeline([[sk:dns(host,function(conn,ip) ]])
file.writeline([[ipnr=ip]])
file.writeline([[end)]])
file.writeline([[conn=net.createConnection(net.TCP, 0) ]])
file.writeline([[    conn:on("receive", function(conn, payload) print(payload) end )]])
file.writeline([[    conn:connect(80,ipnr)]])
file.writeline([[    conn:send("GET /esp.php?tekst="..adc.read(0) .."&heap="..node.heap().." HTTP/1.1\r\nHost: "..host.."\r\n"]])
file.writeline([[        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")]])
file.writeline([[end)]])
file.close()

Re: Show sensorreading on external webserver

PostPosted: Tue Dec 02, 2014 5:14 pm
by gerardwr
Erni wrote:Ok,
Here is the example with dns lookup.


Nice work!

May I suggest to consider changing the title on your opening post into something that better describes the Example. That will help me find it later when I need it ;)

Code: Select allExample of a webclient with DNS lookup

Re: Example of a webclient with DNS lookup

PostPosted: Tue Dec 02, 2014 6:30 pm
by Erni
Yes good idea with a more descriptive title ;)

Just tried it with pushingbox (sending a email.), works fine
The only thing that needs change for others is devid=vxxxxxxx

Code: Select allfile.remove("pushing.lua")
file.open("pushing.lua","w+")
host="api.pushingbox.com"
ipnr=0
file.writeline([[tmr.alarm(30000, 1, function()]])
file.writeline([[sk=net.createConnection(net.TCP, 0)]])
file.writeline([[sk:dns(host,function(conn,ip) ]])
file.writeline([[ipnr=ip]])
file.writeline([[end)]])
file.writeline([[conn=net.createConnection(net.TCP, 0) ]])
file.writeline([[    conn:on("receive", function(conn, payload) print(payload) end )]])
file.writeline([[    conn:connect(80,ipnr)]])
file.writeline([[    conn:send("GET /pushingbox?devid=vxxxxxxx HTTP/1.1\r\nHost: "..host.."\r\n"]])
file.writeline([[        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")]])
file.writeline([[end)]])
file.close()

Re: Example of a webclient with DNS lookup

PostPosted: Wed Dec 03, 2014 3:08 am
by gerardwr
Good man!