Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By resweet
#25977 I just started playing with the Adafruit HUZZAH. I ported code that worked just fine on an Arduino Uno with a Ethernet shield. I thought With an 80 MHz CPU, this should be really fast on the HUZZAH. I saw very slow performance. I put in some print statements using the millis() millisecond timer and here is what I saw. I must be doing something incredibly dumb. I'm a rather experience programmer, but don't have a clue how this could take so long. I notice that my supplied User-Agent should probably be changed, but there are definitely performance problems before I get to that line.

I have opened a connection to my WiFi with WiFi.begin(...).
The variable client is a WebClient that I connect to my server with client.connect(...)
I am sending a POST to ReportStationInfo.php on that client. I have placed my POST data into a string named tmp.
The statements below are used to pass the data to the web. The number at the beginning of the line is the number of msecs taken to execute that line of code.


404 client.println("POST /cue/ReportStationInfo.php HTTP 1.1");
419 client.println("Host: 192.150.23.115");
445 client.println("Connection: keep-alive");
419 client.println("User-Agent: arduino-ethernet");
432 client.println("Accept: application/json");
411 client.println("Content-Type: application/x-www-form-urlencoded");
209 client.print("Content-Length: ");
420 client.println(strlen(tmp));
215 client.println();
550 client.print(tmp);
200 client.println();

You can execute a hell of a lot of statments on a 80 MHz CPU in 400 msec. The network is at least 10 MB/sec, so not much time is required to send the data. What could be going on?
User avatar
By kolban
#25990 This is a pure guess and might be completely worthless ... but it could be that each time you execute "client.println(....)" ... that causes a write of the data down the socket to the partner ... which blocks waiting for a positive acknowledgement that the data has been sent . It might be that internally, the Arduino ESP library is polling looking for a flag that says the data has been transmitted.

Realize that there is a difference between the architecture of the ESP8266 which is event driven and the logical architecture of the Arduino ESP libraries which can be "busy loop/polling".

In the native SDK of the ESP8266, when one wishes to send data, one executes a send() call passing in a buffer of data and the send call returns IMMEDIATELY ... and only some time later does the transmission actually happen and then later still there is a callback function that is invoked to indicate that the data has been sent.

In this Arduino model, when you execute a client.println() then the "logical model" is that the data is sent and we don't end THAT statement until the data has been transmitted ... and since that is not what is happening at the raw ESP SDK level ... artificial blocking has been inserted here.

You may have uncovered either a bug or a level of optimization that may be needed ... but it might be at the Arduino ESP library level as opposed to the ESP8266 itself.
User avatar
By martinayotte
#25992 Same kind of issue have been discussed more than 2 months ago ... :?
I thought it was already fixed ... (it was in write() of ClientContext.h)
Do you know which version of ArduinoIDE you are using ?
To workaround that, simply use String to concatenate all your lines, and then transmit it using only 1 client.print()
User avatar
By resweet
#26007 Well, I opened up an Intel Edison board, used the exact same code and the execution times for the statements were down in the 3 to 4 millisecond range. I'll try the HUZZAH on 1.6.5 that I loaded to make the Edison environment work. I will also try buffering the entire transaction to a single call since I've got lots of RAM left.