Go Down

Topic: Inconsistant WiFi page fetch time from local server (Read 87 times) previous topic - next topic

Falesh

I have got my NodeMCU working well now connecting to my local server. The one thing I still need to work out is the inconsistency of the time it takes to fetch a page from the server. Mostly it takes 5ms but sometimes it spikes up to anything between  50ms or 150ms and very occasionally 3600ms.

I put a load over various sized capacitors on the power line so that shouldn't be causing the issue. Is there a way to add a timeout to client.connect() so if it takes longer then 20ms it stops and retries the connection? For my application to work I need it to consistently take less then 90ms per request.

Code: [Select]
#include <ESP8266WiFi.h>
 
char ssid[] = "virginmedia54841";
char pass[] = "ljksdfli30";

const char* host = "192.168.0.27";
IPAddress server(192,168,0,27);

WiFiClient client;

void setup() {
  Serial.begin(115200);
  delay(100);
 
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, pass); 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  } 
  Serial.println("Connected to wifi");
}
 
void loop() {
  unsigned long testStartTime = millis();

  if (client.connect(server, 80)) {
    client.print(String("GET ") + "/index.php HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: ArduinoWiFi/1.1" +
               "Connection: close\r\n\r\n");
    client.println();
  } else {
    Serial.println("connection failed");
  }

  Serial.println(millis() - testStartTime);
  client.stop();
  delay(100);
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy