Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consumption time of an API (600ms) #207

Open
gimenezfrg opened this issue Nov 17, 2020 · 30 comments
Open

consumption time of an API (600ms) #207

gimenezfrg opened this issue Nov 17, 2020 · 30 comments

Comments

@gimenezfrg
Copy link

gimenezfrg commented Nov 17, 2020

I'm sending data to an API, in consumption via GET the average time is 500ms (so in the example below I'm sending data via GET), via POST for almost 1s.

Could you reduce this time? In a test by POSTMAN for example the API responds in a maximum of 38ms.

String content = "{\"UserName\": \"" + wsUserName + "\", \"BancoDados\": " + wsBancoDados + ", \"Botao\": \"" + buttonCode + "\", \"Ligado\": " + buttonStatus + "}";
    client.println("GET " + wsMetodo + " HTTP/1.1");
    client.println("Host: " + wsServidorIp + ":" + wsServidorPort);
    client.println("Content-Length: " + String(content.length()));
    client.println("Content-Type: application/json");
    client.println(content);
    client.println();    
    client.println("Connection: close");
09:59:05.006 > Conectado ao servidor.
09:59:05.006 > Send B02...
09:59:06.515 > Send OK
@JAndrassy
Copy link

I answered you yesterday. Did you delete and repost it again without any change?
your request is wrong. lookup HTTP protocol. what is a header line, what is a request body, how they are separated by an empty line.

@gimenezfrg
Copy link
Author

Hi, sorry, I didn't delete the previous one, keep it up, I just opened a new one because I thought it would be better.
I have no problem consuming the API, it works, the data arrives, the problem is that it takes almost 1s the whole operation, I changed the code and it continues the same thing, see:

String content = "{\"UserName\": \"" + wsUserName + "\", \"BancoDados\": " + wsBancoDados + ", \"Botao\": \"" + buttonCode + "\", \"Ligado\": " + buttonStatus + "}";
    client.println("POST " + wsMetodo + " HTTP/1.1");
    client.println("Host: " + wsServidorIp + ":" + wsServidorPort);
    client.println("Content-Length: " + String(content.length() + 2));
    client.println("Content-Type: application/json"); 
    client.println("Connection: close");   
    client.println(); 
    client.println(content); 
12:51:08.894 > B04 APERTADO
12:51:08.929 > Evento B04...
12:51:08.929 > [WiFiEsp] Connecting to 10.1.1.122
12:51:08.961 > Conectado ao servidor.
12:51:08.988 > Send B04...
12:51:09.755 > Envio finalizado.

@JAndrassy
Copy link

what bad rate do you use to communicate with the AT firmware?
what code prints that output?

@gimenezfrg
Copy link
Author

void setup()
{  
  Serial.begin(9600);
   //-- Inicializa a serial para conexão com ESP.
  Serial3.begin(115200);
  //-- Inicializa modulo ESP.
  WiFi.init(&Serial3);
...

while (status != WL_CONNECTED) 
  {   
    Serial.print("Tentando conectar ao WPA SSID: ");
    Serial.println(ssid);
    
    status = WiFi.begin(ssid, pass);
  }

...

void ButtonWsSend(String buttonCode, String buttonStatus)
{
  if (client.connect(wsServidorIp.c_str(), wsServidorPort)) 
  {
    Serial.println("Conectado ao servidor.");
    Serial.println("Send "+ buttonCode +"...");

    //--.    

    String content = "{\"UserName\": \"" + wsUserName + "\", \"BancoDados\": " + wsBancoDados + ", \"Botao\": \"" + buttonCode + "\", \"Ligado\": " + buttonStatus + "}";
    client.println("POST" + wsMetodo + " HTTP/1.1");
    client.println("Host: " + wsServidorIp + ":" + wsServidorPort);
    client.println("Content-Length: " + String(content.length() + 2));
    client.println("Content-Type: application/json"); 
    client.println("Connection: keep-alive");   
    client.println(); 
    client.println(content); 
    
    //--.

    client.flush();
    client.stop();

    Serial.println("Envio finalizado.");
  }
}

@JAndrassy
Copy link

you could try my WiFiEspAT library. maybe it is faster. sure is, it can run at higher baud rate on hardware Serial

https://github.com/jandrassy/WiFiEspAT#Why-a-new-wifiesp-library

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 20, 2020

Good afternoon, do you think it might be related to the Firmware I'm using?

I'm using an Arduino Mega RoboDyn board (AT MEGA 2560 + ESP 8266).
This was the AT Firmware I used on ESP:

image

@JAndrassy
Copy link

SDK 1.5 is ancient.
but the speed is a problem of WiFiEsp library. my WiFiEspAT library is faster

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 21, 2020

I'm trying for your library but I can't communicate with ESP, see:
image

image

Before I updated the Firmware to version 2.2.1:
image

What will be the problem?

@JAndrassy
Copy link

my library requires at least AT 1.7 (from SDK 3)
https://www.espressif.com/en/support/download/at?keys=&field_type_tid%5B%5D=14

@gimenezfrg
Copy link
Author

Same thing :(

image

image

image

@JAndrassy
Copy link

JAndrassy commented Nov 22, 2020

the board's setup should be right if it worked with previous library.
turn on debug logging https://github.com/jandrassy/WiFiEspAT#logging

EDIT: does the AT firmware respond to commands from Serial Monitor when you connect the esp8266 directly over USB?

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 22, 2020

It is not responding to AT commands.

With ESP connected directly to USB and with DIP7 on it just shows this:
image

With the DIP7 turned off, this information is passed on and on:
image

*** The information is only readable at 74880 speed

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 22, 2020

I put this firmware:

image

With this configuration:
image

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 22, 2020

The closest I got to running the AT commands was by following this tutorial "https://www.instructables.com/Program-Any-ESP8266-Boardmodule-With-AT-Commands-F" and leaving the configuration almost the same:
image

Connecting to ESP 74880 I receive these messages:
image

After changing to 115200 I get a Ready, sending the AT command I get ERROR
image

*** The problem seems to be with the version of this ESP, something is not hitting, this board is an ESP8266EX

@JAndrassy
Copy link

JAndrassy commented Nov 22, 2020

see https://github.com/jandrassy/WiFiEspAT#at-17-1

and to send AT commands from Serial Monitor set the line ending setting to Both

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 22, 2020

With firmware version 2.2.1:
image

The AT command worked:
image

I will try to use your library now ...

@gimenezfrg
Copy link
Author

Did not work :(

image

@JAndrassy
Copy link

JAndrassy commented Nov 22, 2020

again. AT 1.7 is with SDK 3.
test with CheckFirmware example

AT 2.1 is with RTOS SDK IDF framework

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 22, 2020

Is it for me to test with Firmware 1.7? I already tested with 1.7 and 1.7.4, it does not work the AT command, the only one that seems to work is this one, 2.2.1

I didn't understand what I have to test now, could you give more details?

@gimenezfrg
Copy link
Author

I think I understand, is it for me to follow the recommendations below?
How do I do this "--flash_size 1MB 0x0" in "ESP8266 DOWNLOAD TOOL"?

image

@gimenezfrg
Copy link
Author

It worked, I put Firmware 1.7.4 following its settings and it worked, the weather improved well, something around 200ms for POST and 100ms for GET.

The only problem is that after consuming the API 4 times, on Thursday, as a disconnected server, can you tell me why?

image

@gimenezfrg
Copy link
Author

I commented client.stop() and stopped disconnecting after 5 times, I don't know if it's right, but it worked.

@JAndrassy
Copy link

you flashed the 1 MB version? the esp8266 on Mega+WiFi has a 4 MB flash memory, but the firmware only needs two so Espressif builds the published version for 2 MB flash and a stripped down version for 1 MB flash

@gimenezfrg
Copy link
Author

I used firmware 1.7.4 and followed the parameters indicated in mark 2 of the image, should I use the parameters of mark 1?

image

@JAndrassy
Copy link

JAndrassy commented Nov 23, 2020

yes 1, the second is for 1 MB esp-01 modules.
but it is not important if you don't need the removed features

@gimenezfrg
Copy link
Author

How can I be sure that mine is not ESP-01? It has these markings:
ESP8266EX
412019
UB00PPAW77

@JAndrassy
Copy link

4 MB clues: 1) Robotdyn Mega+WiFi board spec 2) Flash Download Tool detection

@gimenezfrg
Copy link
Author

Okay, last question, is there a significant difference whether or not to use client.stop()?

Without it working well, can I keep it that way?
I also left Connection: keep-alive, it got faster.

Thank you very much for all the support.

@JAndrassy
Copy link

JAndrassy commented Nov 23, 2020

Okay, last question, is there a significant difference whether or not to use client.stop()?

Without it working well, can I keep it that way?
I also left Connection: keep-alive, it got faster.

Thank you very much for all the support.

the AT firmware is limited to 5 concurrent 'links' (TCP clients and UDP listeners). it is harder to manage if some connections are left open.

and is it faster?

@gimenezfrg
Copy link
Author

gimenezfrg commented Nov 23, 2020

Just for you to understand, my solution has 16 connected buttons and are pressed by users at random. When a button is pressed, I consume a web service to record the moment that was pressed, the registration is done in a database.

As it can happen that more than one user presses the same time, the sending must be as fast as possible.

Anyway, without using client.stop() and with "Connection: keep-alive" it fine, somewhere around 80ms, and it doesn't stop after 5 uploads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants