Controlling Servo over Wifi

Hello!

I just bought a WiFiShield for my arduino UNO. I came up with this idea to control a servo from a website but also from an app on my windows phone. From the website i can type in a value between 0-180 degree and then submit. It works fine! BUT! The app i wrote for my windows phone uses a slide that goes from 0-180. Each time the slide "slides" it sends the value to my server (arduino). The servo starts moving but after a while it stops, seems like the arduino crashes or something. I think its because of the large amount of data that is sent from my phone and somehow the arduino cant keep up.

Is there anyone that knows what the problem is?

Does the WiFiShield have any supports for UDP packets? Maybe it could be a solution for the bad response time.

Code:

#include <SPI.h>
#include <WiFi.h>
#include <Servo.h>

char ssid[] = "???";
char pass[] = "???";
int keyIndex = 0;
String buffer;
int status = WL_IDLE_STATUS;

WiFiServer serverTCP(1005);
Servo servo;

void setup()
{
//config servo
servo.attach(3);
servo.write(0);
Serial.begin(9600);
pinMode(8, OUTPUT);
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}

serverTCP.begin();
}

void loop()
{
// listen for incoming clients
WiFiClient client = serverTCP.available();
digitalWrite(8, HIGH);
if (client)
{
String buffer = "";
while (client.connected())
{
if (client.available())
{
char c = client.read();
//Serial.print(c);
buffer += c;
if(c == '\r')
{
servo.write(buffer.toInt());
buffer = "";
//client.flush(); ??????????????
}
}
}
}
}

Thanks!

There is a bug in the memory allocation routines that are used in the implementation of the String class that can cause a crash over time. Use a plain old C array of char instead - may help.

Thanks a lot! It helped! Never gonna use String again!