Hi,
I got this code I have been working on, it runs pretty well in my opinion.
But I need to make my void webBrowser(){} faster…
The webbrowser snippet function code:
void webBrowser(){
// listen for incoming clients
EthernetClient WEBclient = WEBServer.available();
if (WEBclient) {
Serial.println("new WEBClient");
/*
Serial.println(F("new WEBclient"));
lcd.clear();
lcd.setCursor(0,0);
lcd.println(F("new WEBclient")); */
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (WEBclient.connected()) {
if (WEBclient.available()) {
char c = WEBclient.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
WEBclient.println(F("HTTP/1.1 200 OK"));
WEBclient.println(F("Content-Type: text/html"));
WEBclient.println(F("Connection: close")); // the connection will be closed after completion of the response
// WEBclient.println(F("Refresh: 20")); // refresh the page automatically every 5 sec
WEBclient.println();
WEBclient.println(F("<!DOCTYPE HTML>"));
//<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js'></script>
WEBclient.println(F("<html><head><title>DATALOGGER</title></head><body bgcolor='2a2a2c'; style='color:red'>"));
WEBclient.println(F("<table width='100%'; border='1'><tr><th colspan='10'><h2>DATA LOGGER</h2></th></tr><tr><th><h5>YEAR</th><th>MONTH</th><th>DATE</th><th>TIME24</th><th>MINUTES</th><th>SENSORNUM</th><th>SENSORTYPE</th><th>TEMPERATURE</th><th>HUMIDITY</th><th>X_SENSORVALUE</th></h5></tr>"));
logFile = SD.open("log.csv");
if (logFile) {
// read from the file until there's nothing else in it:
while (logFile.available()) {
String req = logFile.readStringUntil('*');
for(int i = 1; i=11; i++) {
//String input[i] = logFile.readStringUntil(',');
//client.println(input[i]);
for(int y = 1; y=11; y++) {
WEBclient.println(F("<td>"));
String input[i] = logFile.readStringUntil(',');
WEBclient.println(input[i]);
WEBclient.println(F("</td>"));
}
}
/*
String input1 = logFile.readStringUntil(',');
String input2 = logFile.readStringUntil(',');
String input3 = logFile.readStringUntil(',');
String input4 = logFile.readStringUntil(',');
String input5 = logFile.readStringUntil(',');
String input6 = logFile.readStringUntil(',');
String input7 = logFile.readStringUntil(',');
String input8 = logFile.readStringUntil(',');
String input9 = logFile.readStringUntil(',');
String input10 = logFile.readStringUntil(',');
String input11 = logFile.readStringUntil(',');
WEBclient.println(F("<tr><td>"));
WEBclient.println(input1);
WEBclient.println(F("</td><td>"));
WEBclient.println(input2);
WEBclient.println(F("</td><td>"));
WEBclient.println(input3);
// client.println(F("</td><td>"));
// client.println(input4);
WEBclient.println(F("</td><td>"));
WEBclient.println(input5);
WEBclient.println(F("</td><td>"));
WEBclient.println(input6);
WEBclient.println(F("</td><td>"));
WEBclient.println(input7);
WEBclient.println(F("</td><td>"));
WEBclient.println(input8);
WEBclient.println(F("</td><td>"));
WEBclient.println(input9);
WEBclient.println(F("</td><td>"));
WEBclient.println(input10);
WEBclient.println(F("</td><td>"));
WEBclient.println(input11);
WEBclient.println(F("</td></tr>"));
*/ }
// close the file:
logFile.close();
} else {
// if the file didn't open, print an error:
Serial.println(F("error opening readFile log.csv"));
}
WEBclient.println(F("</table></body></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;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
WEBclient.stop();
Serial.println(F("WEBclient disconnected"));
lcd.clear();
lcd.setCursor(3,0);
lcd.println(F("WEBclient"));
lcd.setCursor(0,1);
lcd.println(F("disconnected"));
input1 = "";
input2 = "";
input3 = "";
input4 = "";
input5 = "";
input6 = "";
input7 = "";
input8 = "";
input9 = "";
input10 = "";
input11 = "";
}
}
How can I make the for loops correctly, I have been working on this part but it doenst seem to work:
I cannot find any good information how to do a table for loop in this way?
Do you know where to start…
while (logFile.available()) {
String req = logFile.readStringUntil('*');
for(int i = 1; i=11; i++) {
//String input[i] = logFile.readStringUntil(',');
//client.println(input[i]);
for(int y = 1; y=11; y++) {
WEBclient.println(F("<td>"));
String input[i] = logFile.readStringUntil(',');
WEBclient.println(input[i]);
WEBclient.println(F("</td>"));
}
}