Hey there, i got Uno with Ethernet shield (W5100) i want to read variable and use it in code. For instance.
If in text file is 0 then digitalwrite on pin 10 LOW
If in text file is 1 then digitalwrite on ping 10 HIGH
#include <SPI.h>
#include <Ethernet.h>
const int relay = 10;
String relayState;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.arduino.php5.sk";
IPAddress ip(192, 168, 1, 254);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
; }
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
delay(1000);
// if you get a connection, report back via serial:
}
void loop() {
if (client.connect("www.arduino.php5.sk", 80)) {
client.println("GET /lumino/readme.txt"); //download text
client.println(" HTTP/1.1");
client.println("Host: www.arduino.php5.sk");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: ");
client.println(relayState.length());
client.println(relayState);
Serial.println(relayState.length());
Serial.println(relayState);
}
if (client.connected()){
Serial.println("odpojene");
client.stop();
}
}
This is my code, please edit it, i dont know how to do it correct.
1 or 0 can be changed in php file there: http://arduino.php5.sk/lumino/getcontents.php