Hey guys im back at this project again after a little break.
i have added some notes to the code along the way.
Here is what im running into now. I have switched from a .php file to a .txt file thinking that may help. (it did not seam to make a difference)
i am thinking there is some sort of programming issue with the if else state meant seeing how the c print work just fine..... any ideas?
/*
DNS and DHCP-based Web client
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.donavonscreativeinnovations.com";
String location = "test.txt";
// Initialize the Ethernet client library
EthernetClient client;
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
//~~~~~// Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
//~~~~~// Serial.println("connected");
// Make a HTTP request:
client.println("GET http://www.donavonscreativeinnovations.com/test.txt");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
if ((c) >= 1){
// if the value from c = something more then 1 of equial to one then print the following
Serial.print("you have 1 new message!");
}
else {
// if the value from c = something less then 1 then print the following
Serial.print("no messages");
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
//~~~~~// Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
The problem i am having is when i upload to the arduino and i view the serial output it will say "you have 1 new message!" regardless of the value within the file.... so in other words if the value in the text file is 0 the script will still print you have 1 new message! and if you have a value of say 3 it will still print you have 1 new message! or if you have nothing or a 0 (zero) in the text folder it will still print you have 1 new message!.
What i want it to do is
if the value is equal to or greater then 1
Print "you have 1 new message!"
it if is less then 1
print "You don't have any messages at this time"
Thank you K5CZ for you response, I will give this a try....I think i may have tried this all ready don't remember off hand. I will keep everyone posted on how it works out tonight.
I changed my code to what you recommended (see below) and this is what i got......
Hyou have 1 new message!Tyou have 1 new message!Tyou have 1 new message!Pyou have 1 new message!/no messages1you have 1 new message!.no messages1you have 1 new message! no messages4you have 1 new message!0no messages4you have 1 new message! no messagesNyou have 1 new message!oyou have 1 new message!tyou have 1 new message! no messagesFyou have 1 new message!oyou have 1 new message!uyou have 1 new message!nyou have 1 new message!dyou have 1 new message!
no messages
no messagesDyou have 1 new message!ayou have 1 new message!tyou have 1 new message!eyou have 1 new message!:you have 1 new message! no messagesSyou have 1 new message!ayou have 1 new message!tyou have 1 new message!,no messages no messages0no messages2you have 1 new message! no messagesNyou have 1 new message!oyou have 1 new message!vyou have 1 new message! no messages2you have 1 new message!0no messages1you have 1 new message!3you have 1 new message! no messages0no messages3you have 1 new message!:you have 1 new message!5you have 1 new message!6you have 1 new message!:you have 1 new message!3you have 1 new message!7you have 1 new message! no messagesGyou have 1 new message!Myou have 1 new message!Tyou have 1 new message!
no messages
no messagesSyou have 1 new message!eyou have 1 new message!ryou have 1 new message!vyou have 1 new message!eyou have 1 new message!ryou have 1 new message!:you have 1 new message! no messagesAyou have 1 new message!pyou have 1 new message!ayou have 1 new message!cyou have 1 new message!hyou have 1 new message!eyou have 1 new message!
no messages
no messagesVyou have 1 new message!ayou have 1 new message!ryou have 1 new message!yyou have 1 new message!:you have 1 new message! no messagesAyou have 1 new message!cyou have 1 new message!cyou have 1 new message!eyou have 1 new message!pyou have 1 new message!tyou have 1 new message!-no messagesEyou have 1 new message!nyou have 1 new message!cyou have 1 new message!oyou have 1 new message!dyou have 1 new message!iyou have 1 new message!nyou have 1 new message!gyou have 1 new message!
no messages
no messagesCyou have 1 new message!oyou have 1 new message!nyou have 1 new message!nyou have 1 new message!eyou have 1 new message!cyou have 1 new message!tyou have 1 new message!iyou have 1 new message!oyou have 1 new message!nyou have 1 new message!:you have 1 new message! no messagescyou have 1 new message!lyou have 1 new message!oyou have 1 new message!syou have 1 new message!eyou have 1 new message!
no messages
no messagesCyou have 1 new message!oyou have 1 new message!nyou have 1 new message!tyou have 1 new message!eyou have 1 new message!nyou have 1 new message!tyou have 1 new message!-no messagesTyou have 1 new message!yyou have 1 new message!pyou have 1 new message!eyou have 1 new message!:you have 1 new message! no messagestyou have 1 new message!eyou have 1 new message!xyou have 1 new message!tyou have 1 new message!/no messageshyou have 1 new message!tyou have 1 new message!myou have 1 new message!lyou have 1 new message!;you have 1 new message! no messagescyou have 1 new message!hyou have 1 new message!ayou have 1 new message!ryou have 1 new message!syou have 1 new message!eyou have 1 new message!tyou have 1 new message!=you have 1 new message!Iyou have 1 new message!Syou have 1 new message!Oyou have 1 new message!-no messages8you have 1 new message!8you have 1 new message!5you have 1 new message!9you have 1 new message!-no messages1you have 1 new message!
no messages
no messages
no messages
no messages<you have 1 new message!hyou have 1 new message!1you have 1 new message!>you have 1 new message!4you have 1 new message!0no messages4you have 1 new message!:you have 1 new message! no messagesFyou have 1 new message!iyou have 1 new message!lyou have 1 new message!eyou have 1 new message! no messagesNyou have 1 new message!oyou have 1 new message!tyou have 1 new message! no messagesFyou have 1 new message!oyou have 1 new message!uyou have 1 new message!nyou have 1 new message!dyou have 1 new message!<you have 1 new message!/no messageshyou have 1 new message!1you have 1 new message!>you have 1 new message!
/*
DNS and DHCP-based Web client
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.donavonscreativeinnovations.com";
String location = "test.txt";
// Initialize the Ethernet client library
EthernetClient client;
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
//~~~~~// Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
//~~~~~// Serial.println("connected");
// Make a HTTP request:
client.println("GET /test.txt HTTP/1.0");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
if ((c) >= '1'){
// if the value from c = something more then 1 of equial to one then print the following
Serial.print("you have 1 new message!");
}
else {
// if the value from c = something less then 1 then print the following
Serial.print("no messages");
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
//~~~~~// Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
It looks like client is connected until session expired by timeout not by reading whole file from server. Unfortunately I have no experiences with this.