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.
#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);
}