function sendData()
print ("ts="..tstamp() .. "&id=".. node.chipid() .. "&ap=" .. this_ssid .. "&rssi=" .. best_rssi)
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,"192.168.1.40") -- local server: corv
conn:send("GET /8266-boot.php?ts="..tstamp() .. "&id=".. node.chipid() .. "&ap=" .. this_ssid .. "&rssi=" .. best_rssi .. " HTTP/1.1\r\n")
conn:send("Host: corv\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn) conn:close() end)
conn:on("disconnection", function(conn) end)
end
which connects to a file called 8266-boot.php on the server that contains this:
<http><head>
<title>Form reply</title>
</head>
<body>
<?php
$TS=$_GET["ts"];
$K=$_GET["id"];
$AP=$_GET["ap"];
$RSSI=$_GET["rssi"];
$F=fopen("/tmp/8266-started.txt","a");
fprintf($F, date("D d-F-Y H:i:s")." timestamp=$TS, device ID was $K AP=$AP, RSSI=$RSSI");
fprintf($F,"\n");
fclose($F);
echo "Thank You\n";
?>
</body>
</html>
This works great at sending data from the 8266 to the server and the data is saved to the local file just as you'd expect. But I can't get anything sent back to the 8266.
On the 8266, I have a line conn:on("receive", function(conn, payload) print(payload) end)
which is supposed to catch stuff sent by the server and print it on the 8266 serial port. It doesn't.
Can someone please suggest what I need to add to the PHP file to send data back to the 8266. I'm hoping the replies will be of the form:
"just add this line ..... to your PHP file".
With thanks
Pete