Hello, I am having some difficulties with reading from a php file. The code for the PHP file and the Arduino is below
PHP Code
<?php
sleep(10);
echo "Hello World";
?>
Arduino Code
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x7E, 0xAE };
IPAddress server(192,168,1,223);
IPAddress ipAddress(192,168,1,224);
IPAddress myDNS(8,8,8,8);
IPAddress myGateway(192,168,1,1);
IPAddress mySubnet(255,255,255,0);
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ipAddress, myDNS, myGateway, mySubnet);
delay(1000);
Serial.println("connecting...");
if(client.connect(server, 80))
{
Serial.println("Connected");
client.println("GET /print.php");
client.println("HTTP/1.1");
client.println("Host: /localhost");
client.println("user-agent: arduino/somethingorother");
client.println();
delay(1000);
}
}
void loop()
{
if(client.available())
{
char c = client.read();
Serial.print(c);
delay(500);
}
else
{
Serial.println("Disconnecting");
client.stop();
delay(1000);
}
delay(1000);
}
The php file waits for 10 seconds and then echos "Hello World". When I run the code in the Arduino and check the Serial Monitor I get "Disconnecting" and after 10 seconds passed I still get "Disconnecting". Now if I want the Arduino to get the updates that happened in the PHP file what do I do? Do I make multiple HTTP Requests?
Thank You