Arduino Ethernet Client crashes after obtaining values from string My Ethernet server keeps crashing after pulling the RGB values from the string. It remains connected if I'm just toggling a pin, but whenever the string has the rgb values in it, the RGB values are pulled, the LED changes but then the server crashes and won't take any more requests. Do I need to restart the server after it plucks the RGB values for another read? If so, how would I go about doing this? 

Thanks, James :)

Example HTTP request that causes the crash: /?LED=B233+G011+R133&amp;t=T HTTP/1.1

    #include &lt;SPI.h&gt;
    #include &lt;Ethernet.h&gt;
    #include &lt;string.h&gt;

    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
    byte ip[] = {192, 168, 0, 102 }; 
    byte gateway[] = {192, 168, 0, 1 }; 
    byte subnet[] = {255, 255, 255, 0 }; 
    EthernetServer server(84);
    ; 

    char* redstring={0};
    String blue1;
    String green1;
    String red1;
    String testString = "0123456789";


    int blue;
    int green;
    int red;
    int been=0;
    int b=0;
    int g=0;
    int r=0;
    //////////////////////

    void setup(){

    pinMode(11, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(6, OUTPUT);

    //start Ethernet
    Ethernet.begin(mac, ip, gateway, subnet);
    server.begin();

    //enable serial data print 
    Serial.begin(9600); 
    Serial.println("SERVER RUNNING HTTP / GET"); 
    }

    void loop(){
     ////////////////////////////////////////
     EthernetClient client = server.available();
if (client) {
while (client.connected()) {
  if (client.available()) {
    char c = client.read();

    //read char by char HTTP request
    if (sizeof(redstring) &lt; 100) {

      //store characters to string 
      redstring += c; 
      //Serial.print(c);
    } 

    //if HTTP request has ended
    if (c == '\n') {

      ///////////////////////////////////////////

      Serial.println(redstring);



      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html");
      client.println();
      client.println("&lt;HTML&gt;");
      client.println("&lt;link rel=\"shortcut icon\" href=\"data:image/x-icon;,\" type=\"image/x-icon\"&gt;"); 
      client.println("&lt;HEAD&gt;");
      client.println("&lt;TITLE&gt;Arduino GET&lt;/TITLE&gt;");
      client.println("&lt;/HEAD&gt;");
      client.println("&lt;BODY&gt;");

      client.println("&lt;H1&gt;HTML GET&lt;/H1&gt;");
      //change ip back if not local
      client.println("&lt;FORM ACTION=\"http://192.168.0.102:84\" method=get &gt;");

      client.println("JQUERY: &lt;INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\"&gt;&lt;BR&gt;");

      client.println("&lt;INPUT TYPE=SUBMIT NAME=\"t\" VALUE=\"T\"&gt;");

      client.println("&lt;/FORM&gt;");

      client.println("&lt;BR&gt;");

      client.println("&lt;/BODY&gt;");
      client.println("&lt;/HTML&gt;");

      delay(1);
      //stopping client
      client.stop();
      /////////////////////
      //readString = Character.toUpperCase(readString); 
      for (int i = 1; i &lt; sizeof(redstring); i++) {
        if (strchr(redstring, 'B') &amp;&amp; &amp;&amp; redstring[i+1] &gt; -1) {
          blue=redstring[i+1, i+4];
          analogWrite(11, blue); 
          delay(1000);
                      }

        if (strchr(redstring, 'G') &amp;&amp; redstring[i+1] &gt; -1) {
          green=redstring[i+1, i+4];
          analogWrite(9, green); 
          delay(1000);
                      }


        if (strchr(redstring, 'R')&amp;&amp; redstring[i+1] &gt; -1) {
          red=redstring[i+1, i+4];
          analogWrite(7, red); 
          delay(1000);
                      }



      }






      //clearing string for next read
           redstring="";
          (redstring, "0", sizeof(redstring));
        }
      }
    }
  }
}
Using String, which uses dynamic allocation/deallocation on the heap is not advised in embedded platforms, as this can quickly lead to heap fragmentation, eventually leading to memory exhaustion, heap/stack collision...

First off, you should try to replace all String usage, everywhere in your program, with C-tyle strings, i.e. char* or char xxx[...] along with dedicated C functions to deal with them: strchr, strstr, strcpy, strcat, strtok, atoi...

Second, you can avoid using global variables and use the stack for many of them.

void loop() {
    ...
    if (client) {
        char readString[101];
        const int READ_STRING_SIZE = sizeof(readString) - 1;
        int readIndex = 0;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                if (readIndex &lt; READ_STRING_SIZE) {
                    readString[readIndex++] = c;
                }

                if (c == '\n') {
                    // Terminate the read string
                    readString[readIndex] = 0;
                    Serial.println(readString);

                    // Prepare for next reeading
                    readIndex = 0;

                    client.println("HTTP/1.1 200 OK");
                    ...
                    client.stop();

                    // convert readString to all uppercase
                    for (i = 0; i &lt; strlen(readString); i++)
                        readString[i] = toupper(readString[i]);

                    bool b = false;
                    bool r = false;
                    bool g = false;
                    int blue, red, green;

                    // Look for 'B' value
                    char* bb = strchr(readString, 'B');
                    if (bb != 0 &amp;&amp; isdigit(bb[1]) {
                        blue = atoi(&amp;bb[1]);
                        analogWrite(11, blue);
                        delay(500);
                        b = true;
                    }
                    // Same for 'G' and 'R' value
                    ...
                    if (b &amp;&amp; r &amp;&amp; g) {
                        Serial.print("CHANGING RED TO: ");
                        Serial.println(red);
                        Serial.print("CHANGING GREEN TO: ");
                        Serial.println(green);
                        Serial.print("CHANGING BLUE TO: ");
                        Serial.println(blue);
                    }
                }

                if (strstr(readString, "PIN6") != 0) {
                    digitalWrite(6, !digitalRead(6));
                    ...
                }
            }
        }
    }
}


In this sample code, we have completely removed dynamic memory allocation.