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

Moderator: igrr

User avatar
By altes
#27446 Hi all,

I've set up my ESP as an access point and am trying control a pwm duty cycle through GET and POST requests. I'm using the following jquery code on the html side:
Code: Select all$.post("http://192.168.4.1:80/update", {
          lc: inputRange.value,
        lb: brightnessRange.value / 100
        });


The arduino side is using a server.on to call the function that parses the incoming data

Code: Select all  server.on("/update", HTTP_POST, webUpdate);

Code: Select allvoid webUpdate() {

  output = server.arg("lc");
  setLed(server.arg("lc").toInt(), server.arg("lb").toFloat());
  Serial.println();
  Serial.print(output);
  output = server.arg("lb");
  Serial.println();
  Serial.print(output);
    server.sendHeader("Connection", "keep-alive");
  server.sendHeader("Access-Control-Allow-Origin", "*");
  server.send(200, "text/plain", "");
}


Everything works and the data is being parsed correctly however I'm noticing a delay of ~2.5 seconds between the processing of each HTTP request if I send multiple ones. I've been searching around but I can't seem to find a solution for a faster response time.

Can anyone shed some light on this?
User avatar
By martinayotte
#27504 Which version of ArduinoESP are you using ?
Because this latency issue seems to be a bug corrected more than 2 months ago.
(Look also if you have multiple ArduinoESP versions in your IDE, and delete all old ones)
User avatar
By Torah
#27509 Hi, martinayotte

I have two questions turn to you for help.
1. I cannot find the esptool in tool->programmer, although the USBtinyISP and etc. are all well. BTW, I tried in both Win 10 64bit and Win XP 32bit. And I can't see nothing reply on serial monitor. I tried both Arduino as ISP or with FTDI (esp12 standalone).
2. I tried to make esp8266 to send GET request to local server. But failed many times . The code typically likes the following. I can see that connected wifi. I think it's not a module or home network issue. I've ran some piece of code doing the same stuff but using httpd. So from your experience, can you help out of this strange problem? Merci beaucoup.

Thank you in advance. Merci beaucoup.

the changed code is here:

// Import required libraries
#include <ESP8266WiFi.h>

// WiFi parameters
const char* ssid = "TorahYongquan";
const char* password = "PlantoWang";

// Host
const char* host = "planto.oicp.net";// the local dns server is ok, and I tried 192.168.x.x, the result is same

void setup() {
// Start Serial
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {

Serial.print("Connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}

// This will send the request to the server
client.print(String("GET /add.php?temper=22") + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);

Serial.print("client.status(): ");
Serial.println(client.status());
Serial.print("client.available(): ");
Serial.println(client.available());
Serial.print("client.connected(): ");
Serial.println(client.connected());

// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r\n');
Serial.print(line);
}

Serial.println();
Serial.println("closing connection");
delay(5000);

}