I got my esp8266 module a few days ago and have been experimenting with it since then. I could successfully create a local server and do some basic led control.
But I am facing problems trying to get data from a php script. I want the esp to connect to my server and get the data that is stored in my server.
There is a text file in my server. A php script reads the data from this text file and echoes this. I'm trying to catch this echoed data in my lua script.
Here is the php script (button_read.php):
<?php
$txt = file_get_contents("../text_files/button_text.txt");
echo $txt;
?>
And this is my lua script (init.lua):
wifi.setmode(wifi.STATION)
tmr.alarm(0, 1000, 0, function()
wifi.sta.config("my_ssid", "my_pwd")
if(wifi.sta.getip()==nil) then
print("Connecting...")
else
tmr.stop(0)
end
end)
print(wifi.sta.getip())
sk = net.createConnection(net.TCP,0)
sk:on("receive", function(sck, s) print(s) print("received") end)
sk:connect(80, "www.my_website.com")
sk:send("GET /php_files/button_read.php HTTP/1.1\r\nHost: www.my_website.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
I am using the ESPlorer IDE. When I run my script, I get a 'nil' in my console.
I'm not sure if my approach is right here. Any help would be gladly appreciated.