Pages: [1]   Go Down
Author Topic: Speed improvement and non blocking Ethernet library  (Read 1281 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I'm trying to find out how to make a better webserver from the arduino that would allow many client to connect and have no blocking process.
I would like that the any process that is run by the Arduino does not block the microcontroller more than 20ms.

I'm not a specialist of C development ... (in reality I can not program in C) but I would like to have some contact with the people involved in the Ethernet module development.

Here is my first question:

For the WebServer example currently in the example you read the request character by character. The library allows to read a buffer. By reading in a buffer rather than per character the time goes from 80ms to 5ms.




        uint8_t result[500];
 
        int available=client.available();
       
        client.read(result, available);
         
        boolean foundBlankLine=false;
        for (int i=0; i<available; i++) {
     
          if (result == 10 && currentLineIsBlank) {
            foundBlankLine=true;
          }
          if (result == 10) {
            // you're starting a new line
            currentLineIsBlank = true;
          }
          else if (result != 13) {
            // you've gotten a character on the current line
            currentLineIsBlank = false;
          }
        }

My first question is why I need to use an array of int rather than an array of char ?

In EthernetUDP we have:

int EthernetUDP::read(unsigned char* buffer, size_t len)

while in EthernetClient we have:

int EthernetClient::read(uint8_t *buf, size_t size) {

I would expect to have in both a char array.

Best regards,

Luc



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to find out how to make a better webserver from the arduino that would allow many client to connect and have no blocking process.
I would like that the any process that is run by the Arduino does not block the microcontroller more than 20ms.

I've done something similar to what you might need: https://github.com/stevemarple/WwwServer.

I wanted a data logger to have a built-in web server which would serve saved data files from the SD card. I also wanted the configuration to be stored in a config file on the SD card as for my application I couldn't expect end users to recompile/reflash the Arduino. To avoid interfering with the data logging process I had to split up serving a page into many small tasks which were processed from loop(); this also applies to reading the config file. The maximum time taken for a task is about 50ms. It's not complete but you may find it, or the ideas, helpful. At present it only handles static files, generating dynamic content is planned but I'm working on other things at present.

I don't know what ethernet hardware you are using but the Wiznet5100 supports a maximum of 4 simultaneous connections.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I would expect to have in both a char array.
A uint8_t is an unsigned 8 bit value. That is exactly the same size and bit pattern that an unsigned char is/has. So, they both store data in the exact same one. One uses a portable format (uint8_t). The other does not.

Code:
        uint8_t result[500];
On an Arduino, there goes 1/4 of your (very limited) memory.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26248
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@OP, if you don't want your code to develop italics, best use code tags when posting code.
Use the # icon on the editors toolbar.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: