Slow connection to local server but fast to remote site

Falesh

Junior Member
Jan 7, 2016
1
0
0
I'm running a local server, it was XAMPP on a PC but now it's nginx on a Rasberry Pi, which works fine when I connect to it with another PC on the network via browser. However when I connect to it using NodeMCU, a little wireless microcontroller which connects to the local network via wifi, it takes over a second to fetch a page. The twist is that when I make the NodeMCU connect to an external website it fetches the page in a normal time, 50ms on the site I tried. So it seems to be going through the router OK and the code works at fetch a page.

So:

1) The server displays pages quickly for PCs on the local network
2) I can connect the NodeMCU to an external website it responds quickly
3) The server takes over a second to display a page to the NodeMCU

I tried adding a DMZ, turning off the router Firewall and port forwarding. Nothing seemed to help. I also swapped the server from XAMPP on a PC to nginx on a Raspberry Pi but that didn't change the response time. Does anyone have any idea what might be causing this delay?

If anyone is interested this is the code for the NodeMCU, it was programmed in the Arduino IDE.

Code:
/*
 *  Simple HTTP get webclient test
 */
 
#include <ESP8266WiFi.h>
 
const char* ssid     = "virginmedia545641";
const char* password = "mypassword";
 
const char* host = "192.168.0.10";
//const char* host = "www.adafruit.com";

String url = "/electronics/test.php";
//String url = "/testwifi/index.html";
const int httpPort = 80;
String remoteData;

 
void setup() {
  Serial.begin(115200);
  delay(100);
 
  // 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());
}
 
void loop() {
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  unsigned long testStartTime = millis();
  
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  delay(1);
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    remoteData = client.readStringUntil('\r');
  }
  Serial.println(millis() - testStartTime);
  //Serial.println(remoteData);
  //delay(3000);
}