0

A part of my project need to get datas from an ESP8266 with php script. I tested this script and i don't know why i can get the datas in an iframe element and nothing with file_get_content function. In iframe element my browser displayes "Hello my friend!" as wanted:

The ESP8266 server mode at 192.168.4.1 address, part of code:

String webpage = "<div id='div1'>Hello</div>";
webpage += "<div id='div2'>my</div>";
webpage += "<div id='div3'>friend!</div>";
String cipSend = "AT+CIPSEND=";
cipSend += 0;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";
sendData(cipSend,1000,DEBUG);
sendData(webpage,1000,DEBUG);
sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);

The php script:

<html>
 <body>
 <iframe src="http://192.168.4.1/?cmd=SS,0,0,"></iframe>
 <?php
 $url="http://192.168.4.1/?cmd=SS,0,0,";
 $lines_string = file_get_contents($url);
 echo htmlspecialchars($lines_string);
?>
 </body>
</html>

If i replace the url by:

$url=https://arduino.stackexchange.com

It works with php script,so what is the issue with the ESP8266 ?

asked Nov 20, 2018 at 13:50
4
  • Where does the PHP run? I think your PHP is running on a remote server, while the ESP is on a local network (behind a NAT), with a local IP address. The remote server can't access your local network, while you browser can. Commented Nov 20, 2018 at 16:35
  • Php script is running on php home server Linux machine. I can send all i want to the ESP8266 by wifi. Commented Nov 20, 2018 at 16:38
  • Is your home server on the same network (/subnet)? Can you curl/gwet the url from your home server? Commented Nov 20, 2018 at 16:42
  • No home network. Just php server (localhost) and ESP8266 as access point. Commented Nov 20, 2018 at 17:13

1 Answer 1

1

To process the request by php, you must send valid HTTP response. The browser tolerates too much.

String webpage = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
webpage += "<div id='div1'>Hello</div>";
answered Nov 20, 2018 at 18:12
1
  • PERFECT !!! I can get "Hello" with <code> file_get_contents("192.168.4.1/?cmd=SS,0,0,"); </code> Commented Nov 20, 2018 at 18:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.