SurferTim,
Big fan of yours because of your ethernet bug solution for v1.0 IDE :)
I am working on the same project with KodiakBear.
I wrote the following code simultaneously with him. Mine is working well. The following code is working on my computer(Windows 7) without stalling. I 've tried it on 2 different XP computers and it does not stall on them as well. But we are not sure it will not stall somewhere, sometime.
#include
#include
#include
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "192.168.1.12";
EthernetClient client;
TextFinder finder( client );
void setup()
{
// Open serial communications and wait for port to open:
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Serial.begin(9600);
while (!Serial)
{;} // wait for serial port to connect. Needed for Leonardo only
// 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 /data.php");
client.write("GET /data.php HTTP/1.0\r\n\r\n");
}
else
{
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
} //END OF SETUP
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
Serial.println("Client available");
//begin get user count
finder.find("#"); //get user count
long user_count = finder.getValue();
Serial.print("User Count:");
Serial.print(user_count);
Serial.println("");
//end get user count
//begin get car choice
finder.find("[");
long car_type = finder.getValue();
Serial.print("Car Type:");
Serial.print(car_type);
Serial.println("");
// end get car choice
// begin get first user speed
finder.find("<");
long speed_1 = finder.getValue();
Serial.print("Speed 1:");
Serial.print(speed_1); // end get first user speed
Serial.println("");
// end get first user speed
// begin get second user speed
finder.find("{");
long speed_2 = finder.getValue();
Serial.print("Speed 2:");
Serial.print(speed_2);
Serial.println("");
// end get second user speed
client.stop();
//client.flush();
/* int motor1_hiz = speed_1/4;
digitalWrite(motor1_input_1, HIGH);
digitalWrite(motor1_input_2, LOW);
analogWrite(motor1_en,motor1_hiz);
int motor2_hiz = speed_2/4;
digitalWrite(motor2_input_1, HIGH);
digitalWrite(motor2_input_2, LOW);
analogWrite(motor2_en,motor2_hiz); */
}
delay(100);
/* if (!client.connected())
{
Serial.println("Client is not connected");
client.stop();
}*/
//This is your hack from couple months ago
/*int newFree = client.free();
if(newFree < 1000)
{
Serial.print("Low buffer ");
Serial.println(newFree, DEC);
} */
if (client == false) // there was a bunch of code between the following and client.stop. So I wrote this. Now it is not necessary for now
{
if(client.connect(serverName, 80))
{
// client.println("GET /data.php");
client.write("GET /data.php HTTP/1.0\r\n\r\n");
// client.write();
// client.println();
}
}
} // END OF CODE
Here is the serial print:
connecting...
connected
Client available
User Count:2
Car Type:1
Speed 1:706
Speed 2:470
Client available
User Count:2
Car Type:1
Speed 1:706
Speed 2:470
.
.
.
So, is it possible for you to compare two different codes and figure out what the problem might be? I think I go around the problem somewhere.
Edit: added last sentence, my bad.