Hey all. I looked around pretty extensively for a similar topic and found some, but none of them really seemed to shed some light on the situation exactly, and I know each situation can be different. So, I've decided to start one up. This is less of an issue and more of a "Can it be optimized?"
I've recently switched from having my local webserver running off of an ESP8266 to an Arduino Ethernet shield. There were a couple reasons for the change, primarily focused around ease of use and reprogramming. When switching over to ethernet, I loaded my .htm files onto an SD card and am using the built-in SD slot that comes with the shield. Everything looks to be working fine. Arduino gets the file, reads the contents, and writes the contents to the webserver.
My only issue is that the writing seems so slow. It seems as though it's writing one HTML element at a time. The HTML file itself is approximately 600-700 lines. With the before-mentioned page, it takes approximately 10 seconds for the whole thing to load up (10 seconds of one element at a time loading).
My question is, is that just something I'll have to deal with or is it something I can optimize? If I need to just deal with it, I suppose I can. The page only needs to load up once every great while, so it's not a huge deal, it just looks kinda messy on loadup. If it's something I can optimize, what can I do and where? Below is the code I am currently using. It's primarily example code with my stuff plugged in. I haven't written the GET/POST code I will require yet since I wanted to ask this first.
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
File webFile;
char c;
String readString;
int page = 4;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 178 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac,ip,gateway,subnet);
server.begin();
if (!SD.begin(4)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialised.");
if (!SD.exists("panel.htm")) {
Serial.println("Cannot find file!");
}
else {
Serial.println("Found file.");
}
}
void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("Client found");
while (client.connected()) {
if (client.available()) {
Serial.println("Client connected");
c = client.read();
if (readString.length() < 100) {
readString += c;
}
if (c == '\n') {
if (page == 4) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: html");
client.println("Connection: close");
client.println();
webFile = SD.open("panel.htm");
if (webFile) {
while(webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
delay(0);
client.stop();
}
}
}
}
}
delay(0);
}
Thanks in advance.
Edit: For reference, I'm using the sunfounder ethernet shield with the W5100 chip. Internet speeds don't seem to be the issue (~300mbps down / ~80mbps up)