- Sat Nov 19, 2016 6:17 am
#58376
In case somebody is interested in my progress or giving me some further information I managed some things in the meanwhile. I had a look at some examples with the ESP as a webserver but I would like to use it as a client but anyway. I recognized that the request header information "keep-alive" is keeping alive the connection
what I was basically doing wrong is that I did not understood what "event driven" really means. I implemented a additional event driven function into the conn:on("connection"...) function called "conn:on("sent"...). The result was that I can now send the 1024 float numbers in multiple chunks and close the connection after a few cycles when the string is sent.
Now I would like to establish a new connection directly after I closed the old one but if I put a conn:connect(...) into the event conn:on("disconnect"...) the esp reboots. I do not want to have a additional or multpile connections I only want to have only one. Hopefully somebody can tell help me out with this because I do not understand what is the problem when I want to reconnect after a disconnect. Maybe someone can make a suggestion about other solutions websockets or whatesver. Thanks a lot
bets regards
sille
Code: Select allarray = {}
b = 100
function send_string(value, index)
conn:send("GET /Test/FWRITE.php?" --ändern in measure.php
.."x_axis="..value
.."&y_axis="..index
.." HTTP/1.1\r\n"
.."Host: 192.168.4.\r\n"
--.."Keep-Alive: timeout=5 max=2\r\n"
.."Connection: keep-alive\r\n"
--.."Connection: close\r\n"
.."Accept: */*\r\n"
.."User-Agent: Mozilla/4.0 "
.."(compatible; esp8266 Lua; "
.."Windows NT 5.1)\r\n"
.."\r\n")
end
conn = nil
conn = net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) success = true print(payload) end)
conn:on("connection", function(conn, payload) print('\nConnected')
send_string("new_data_line", 0)
j = 0
conn:on("sent", function(conn, payload) print ("\nsent")
for i = 0, b do
array[i] = 70.1111
end
a = table.concat(array, ",")
print(node.heap())
send_string(a, b)
j = j + 1
if j > 5 then conn:close() end
end)
end)
conn:on("disconnection", function(conn, payload) print('\nDisconnected')
conn:connect(80, "my_IP")
end)
conn:connect(80,'my_IP')