Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

TM4C129 Ethernet client: http request loss when receiving continuous inquiries

$
0
0

Dear oh43 users,

I am facing trouble on an application providing on a webserver serving html documents and images from a SD card and running on a EK-TM4C1294XL platform.

 

Currently, I am bypassing the SD card storage and all the binary and html code are embedded in the source code.

 

The configuration is now quite simple, where the webserver is supplying an index.htm page and several jpeg images referred in this page.

 

For this this test purpose, and in order to increase the network traffic several jpeg image filenames are specified in the source code like tiger1.jpg, tiger.jpg, etc (total 10 images) therefore the webserver provide every time the same binary image stored into tiger_jpg array (defined in tiger.h).

 

Every time, the index.htm page and some of the images are loaded successfully (see screen capture in attachment). However, some images aren’t displayed and replaced by an empty box.

 

Some messages are inserted into the webserver functions in order to see the incoming HTTP requests. As you can see not all the 10 HTTP requests are displayed on the console log.

 

In addition, the wireshark capture confirms that the Firefox browser sends correctly all HTTP requests as expected (1 for index.htm and 10 for tiger*.jpg).

 

By comparing the console log and the wireshark capture, we can see that if several HTTP requests (GET /tiger*.jpg HTTP/1.1)  are consecutive in a very short time, it looks that the TM4C129 platform didn’t receive all the request and may be an overflow condition is present on the Ethernet client.

 

In attachment, you will find:

- tiger.h definition of tiger.jpg into array of hex values

- console message

- wireshark capture

- browser screen capture

 

Some assistance will be really helpful. Thanks in advance.

 

The code is the following:

#include <SPI.h>
#include <Ethernet.h>
#include "inc/hw_sysctl.h"
#include "inc/hw_ssi.h"
#include <driverlib/sysctl.h>

#include <driverlib/rom.h>
#include <driverlib/rom_map.h>

#define LWIP_DEBUG

// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   256



// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 0, 0, 10); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer

#include "tiger.h"

void setup()
{
    Serial.begin(115200);       // for debugging
   
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
}


void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
      
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                
                char c = client.read(); // read 1 byte (character) from client
                // buffer first part of HTTP request in HTTP_req array (string)
                // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
                if (req_index < (REQ_BUF_SZ - 1)) {
                    HTTP_req[req_index] = c;          // save HTTP request character
                    req_index++;
                }
                // print HTTP request character to serial monitor
                Serial.print(c);
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // open requested web page file

                    if (!strncmp(HTTP_req, "GET /tiger", 10)) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type: image/jpeg");
                        client.println();                      
                        client.write(tiger_jpg, sizeof(tiger_jpg));
                        
                   } else if (!strncmp(HTTP_req, "GET /index.htm", 14)) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type:  text/html");
                        client.println("Connection: close");
                        client.println();
                        
                        client.println("<html>");
                        client.println("<head>");
                        client.println("</head>");
                        client.println("<body>");
                        client.println("<p><img src='/tiger1.jpg'></p>");
                        client.println("<p><img src='/tiger2.jpg'></p>");
                        client.println("<p><img src='/tiger3.jpg'></p>");
                        client.println("<p><img src='/tiger4.jpg'></p>");
                        client.println("<p><img src='/tiger5.jpg'></p>");
                        client.println("<p><img src='/tiger6.jpg'></p>");
                        client.println("<p><img src='/tiger7.jpg'></p>");
                        client.println("<p><img src='/tiger8.jpg'></p>");
                        client.println("<p><img src='/tiger9.jpg'></p>");
                        client.println("<p><img src='/tiger10.jpg'></p>");
                        client.println("</body>");
                        client.println("</html>");
                   }                                                   
                   
                    // reset buffer index and all buffer elements to 0
                    req_index = 0;
                    memset(HTTP_req, 0, REQ_BUF_SZ);
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
}
}

Attached Thumbnails

  • 2014-09-03 16h00 Browser capture.png

Attached Files


Viewing all articles
Browse latest Browse all 2077

Trending Articles