hai all,
Let me describe my scenario first .
Basically i am having a web server in my laptop and running a client program in arduino.
when ever i change the status of a an appliance from the web page ,it gets saved in a text file.
Now am trying to read the content of file for determining the status of the appliance.
But the problem arises when i read the text file and printed the character in the file.
if the status was ON ,value written in txt file was 1 and 3 for OFF status.
However the value getting printed in serial terminal is -1.
is there any way to be sure if the download of the text file was success or not ??
i am attaching the code .If there is any logical mistake in the code please do bring it out.
Any help is appreciated.
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
float value=0.72;
int c;
int i=0;
char str[200];
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x3E, 0x9F};
// Enter the IP address for Arduino
IPAddress ip(169,254,229,5);
char server[] = "169.254.229.8";
EthernetClient client;
TextFinder finder(client);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
}
void loop() {
// Connect to the server (your computer or web page)
if (client.connect(server, 80)) {
Serial.println("Connected 1st");
client.print("GET /example/project/page2.php?");
client.print("value=");
client.print(value);
client.println(" HTTP/1.1");
client.println("Host:169.254.229.8");
client.println();
}
else {
Serial.println("--> connection failed\n");
}
if(client.connected()){
Serial.println("connected 2nd");
client.println("GET http://example/project/LEDstate.txt"); //download text
int c = client.read();
Serial.println(c);
if (c=='1'){
Serial.println("on");
}
if (c=='3'){
Serial.println("off");
}
client.stop();
}
else{
Serial.println("no data got");
client.stop();
}
}