POST to website

omri10
Posts: 2
Joined: Thu Nov 22, 2018 12:36 pm

POST to website

Postby omri10 » Thu Nov 22, 2018 2:04 pm

hi , I am using the ESP 32 to send parameters VIA POST to website , I am using this code :
  1.         timeA=millis();
  2.         USE_SERIAL.println(timeA - timeB);
  3.         strTotURL=strBaseUrl+strPage;
  4.         strTotURL.replace(" ", "");
  5.         //USE_SERIAL.println(strTotURL);
  6.         http.begin(strTotURL, ca); //HTTPS
  7.         http.addHeader("Content-Type", "application/x-www-form-urlencoded", false, true);
  8.         httpCode = http.POST(strParams);      
  9.         if(httpCode > 0)         // httpCode will be negative on error
  10.         {            
  11.             if(httpCode == HTTP_CODE_OK) // file found at server
  12.             {
  13.                 String payload = ">ADJ "+http.getString();
  14.                 USE_SERIAL.println(payload);//+payload
  15.                 timeA=millis();
  16.                 /*USE_SERIAL.print("time befor : " + timeB/1000);
  17.                 USE_SERIAL.print(" time after : " + timeA/1000);
  18.                 USE_SERIAL.println(" elapsed : " + ((timeA-timeB)/1000));*/
  19.                 USE_SERIAL.println(timeA - timeB);
  20.             }
  21.             else
  22.             {
  23.                 String payload = http.getString();
  24.                 USE_SERIAL.println(String(">fail")+payload);              
  25.             }
  26.         }
  27.         else
  28.         {
  29.            USE_SERIAL.print(String(">")+httpCode);
  30.            USE_SERIAL.println(">Acc ER1");
  31.         }
  32.  
  33.         http.end();
the problem is that the process is taking 2 sec give or take , is there any way that I can make it faster ?

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: POST to website

Postby PeterR » Sun Nov 25, 2018 10:01 pm

Get a faster uplink and/or server ;)
One problem is that HTTP negotiates a connection on each POST/GET etc.
So there is a lot of 'hello are you there', 'o yes I offer this', 'go on then here's my command' going on in each POST/GET.
Each interaction has potentionally a large latency.

MQTT and/or websockets would reduce latency significantly as these connection are established just the once rather on each transaction.
Grouping data will also improve performance. If you have 5 items to send then combine into one post.
I know - stamp coupling but the uplink won't bend to software 'rules'.

Unfortunately production quality software has to deal with potentially long response times.
The remote will not recieve data regularly and you will not always immediately recieve a 'i got it' response.

So you need to create a task which manages the uplink and allows your main task to get on with whatever.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: Bing [Bot] and 96 guests