I'm using Energia to program TI's CC3200 MCU. Since Energia is based off the Arduino IDE, I'm hoping someone can help me here.

I'm trying to get the CC3200 to act as a Webserver which when successfully starts up serves up a page with two fields for the username and password that the user needs to fill. Now I'm able to see that the two fields are being successfully POST'd (through Serial.write but only when the code to get it into buffer is not present) but I was hoping someone can help me get this content into a character array (called buffer declared before the setup loop begins).

The code in the section //Here is where the POST data is does not seem to be working as I see garbage values in buffer and in the Serial.write. How do I get these POST values into buffer OR even better how do I split the two field values and store them into two separate character arrays?

void loop()
  // listen for incoming clients
  WiFiClient client = server.available();

  if (client) {
    //Serial.println("Client connected");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;

    while (client.connected()) {
      while(client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {

            // Here is where the POST data is.
            Serial.println("Post data: ");
            int ctr = 0;
            buffer[ctr] = client.read();
        Serial.println("Buffer: ");

        //Serial.println("Sending response");
        // send a standard http response header
        client.println("HTTP/1.0 200 OK");
        client.println("Content-Type: text/html");
        client.println("Connection: keep-alive");

        //form added to send data from browser and view received data in serial monitor
        client.println("<!DOCTYPE html>");
        client.println("<html lang=\"en\">");
        client.println(" <FORM action=\"\" method=\"POST\">");
        client.println("    <P>");
        client.println("    <LABEL for=\"username\">Username:</LABEL>");
        client.println("    <INPUT type=\"text\" name=\"uname\"><BR><BR>");
        client.println("    <LABEL for=\"password\">Password:</LABEL>");
        client.println("    <INPUT type=\"text\" name=\"pwd\"><BR><BR>");
        client.println("    <INPUT type=\"submit\" value=\"Submit\">");
        client.println("    </P>");
        client.println(" </FORM>");


        else if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
  • What sort of garbage data are you seeing?
    – Majenko
    Jun 12, 2016 at 20:20

1 Answer 1


In this loop

while(client.available()) { 
    buffer[ctr] = client.read();

you're using client.read() twice, so the buffer gets only every second character.

A solution could be:

while(client.available()) { 
    int c = client.read();
    buffer[ctr] = c;
  • Thanks! This code worked great! int ctr = 0; while(client.available()) { buffer[ctr] = client.read(); ctr++; }
    – hpb
    Jun 12, 2016 at 21:26
  • Any idea why this loop runs twice? I see two outputs of the buffer. Is it once when I enter the URL and hit Enter and the second when I hit Submit?
    – hpb
    Jun 13, 2016 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.