Dear Community
I am using an Arduino mkr 1010 and WIFININA to host a webserver.
Handling single http requests works fine, however when the web-client (Firefox) loads the page and requests additional ressources (css, images), the WifiServer
starts lagging after the first couple of files. Typically 1 to 5 seconds before Firefox receives the responses.
Eventually, after ~10 seconds my server serves 8 files successfully (20kB)
Receiving and handling individual requests takes approximately 40ms. But there appears to be a delay between incoming requests which I have no explanation for.
The function below is called in a tight loop()
, so there is no interence from any other part of the program.
#include <WiFiNINA.h>
[...]
void Wifi_WaitRequest(WiFiServer &Server) {
WiFiClient client = Server.available();
if (!client) return;
static char sReq[128]; // http request buffer
memset(sReq, 0, 128);
while (client.connected()) {
if (client.available()) {
if (strlen(sReq) >= 127){
Wifi_Error(WFCl, 406, http_REQLONG);
break;
}
char c = client.read();
if (c != '\n')
strncat(sReq,&c,1);
else {
// request complete
if (strstr(sReq, "GET ") != sReq) {
Wifi_Error(client,406, http_NOGETRE);
}
else {
// takes approx. 40ms
Wifi_HandleRequest(client, sReq);
}
break;
}
} // client available
} // client connected
client.stop();
}