So i am planning on making a webserver, as i create a mental map of what im going to do im faced with a very laborious issue.
In the Ethernet Webserver example the HTML that is being returned to the one requesting it is made inline with the code.
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
this is a very laborious problem, because if my html webpage has a few hundred lines of code, the code will get very very messy.
Is there some way that i can just include a .html file and it will automagically return that instead?
Im using a Raspberry pico Rp2040 Board. Im planning on storing it in flash Actually Since the pico has a lot of flash space compared to other boards(2Mb).
I was actually thinking of doing this incase there was no other way of doing it. I would include some sort of .h file that is generated by the script.
its kind of a shame the library do not have inbuilt support for it.
I'm not an expert for the RP2040 board but if the corresponding core doesn't support a flash file system (p.e. the SPIFFS on the ESP32) the library cannot provide such a functionality. The Arduino-Pico core supports the LittleFS for such purposes but don't expect any example of a general purpose library as the Ethernet library to support stuff available on a single platform only.
BTW, how do you want to use the Ethernet library on that board? Did you attach a WizNet board to it?
Yes , a W5500 board is connected. I already have done some test and have already made a very simple webserver ( just 10 lines of html).
This seems a bit more trouble than i want to deal with. There might also be some overhead processing when fetching the html file. I guess the option for me is to go with the script route. But first i have to look into how to read url parameters, there might be weird interactions if i use one or the other