Greetings;
I have an Arduino Mega 2560 R3 with a W5500 and a bunch of sensors to monitor pool/home water quality. I use ArduinoOTA to upload the sketches via ethernet (way faster than USB, BTW!).
The project has a one-page web server, where I display sensor data every 5 seconds. I write to an SD card every 15mins and send an email with that file to myself once a day...
All this works, but at least during the beta testing, I'd like to also observe the Serial monitor output. Obviously, a 50m USB wire is out of the question, so my thought was to print to a second web page instead...
After setting up my web server (reserved IP by router):
void setupEthernetServer() {
//SETUP ETHERNET WEB-SERVER
// start the Ethernet connection and the server:
//Ethernet.begin(mac, ip); //set up with fixed IP
Serial.print(F("Ethernet IP Request "));
tft.print(F("\nEthernet IP Req "));
Ethernet.init(EthernetChipSelect);
if (Ethernet.begin(mac) == 0) { // Start Ethernet with dynamic IP
Serial.println(F("---> FAILED: no DHCP"));
tft.setTextColor(RED);
tft.print(F("---> FAILED: no DHCP"));
tft.setTextColor(WHITE);
Serial.print(F("Ethernet Shield "));
tft.print(F("\nEthernet Shield "));
if (Ethernet.hardwareStatus() == EthernetNoHardware) { // Check for Ethernet hardware present
Serial.println(F("---> FAILED: no Hardware\n"));
tft.setTextColor(RED);
tft.print(F("---> FAILED: no Hardware"));
tft.setTextColor(WHITE);
} else {
Serial.println(F("---> OK"));
tft.print(F("---> OK"));
Serial.print(F("Ethernet Cable "));
tft.print(F("\nEthernet Cable "));
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(F("---> FAILED: no Cable\n")); // not connected
tft.setTextColor(RED);
tft.print(F("---> FAILED: no Cable\n"));
tft.setTextColor(WHITE);
} else {
Serial.println(F("---> OK"));
tft.print(F("---> OK\n"));
}
}
errorSetup = true;
ErrorSetup = ErrorSetupDelay;
return; // or not!
} //eof (Ethernet.begin(mac) == 0)
server.begin(); // start the server
Serial.print(F("---> OK at: ")); Serial.println(Ethernet.localIP());
tft.print(F("---> OK "));
tft.print(Ethernet.localIP());
tft.print(F("\n"));
ArduinoOTA.begin(Ethernet.localIP(), "Orientes", "I5tanbul", InternalStorage); // start the OTEthernet library with internal (flash) based storage
} //eof setupEthernetServer()
my current 5 second web update looks like this:
void listenForClient() {
client = server.available();
if (client) {
//Serial.println(F("new client"));
boolean currentLineIsBlank = true; // an http request ends with a blank line
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 == 'Z' && !programOTA && !internetOTA) internetOTA = true; // if a 'Z' was input, that means we are in OTA programming mode...
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connection: close")); // the connection will be closed after completion of the response
client.println(F("Refresh: 5")); // refresh the page automatically every 5 sec
client.println();
client.println(F(""));
client.println(F(""));
//send time stamp to web page
client.print(day()); client.print(F("-"));
client.print(monthShortStr(month())); client.print(F("-"));
client.print(year()); client.print(F(" "));
client.print(hour());
webDigits(minute());
webDigits(second());
client.print(F("
"));
client.print(F("
"));
// send House values to web page
client.print(F("Rain Water: "));
client.print(pReading[rainTank - 8], 2);
client.print(F(" m3"));
client.print(F("
"));
client.print(F("Line Pressure: "));
client.print(pReading[houseLine - 8], 2);
client.print(F(" bars"));
client.print(F("
"));
client.print(F("Recirc Pressure: "));
client.print(pReading[recircFilter - 8], 2);
client.print(F(" bars"));
client.print(F("
"));
client.print(F("
"));
// send Pool Values to Web Page
client.print(F("Pool EC: "));
client.print(ezoReading[eC], 0);
client.print(F(" uS"));
client.print(F("
"));
client.print(F("Pool Temp: "));
client.print(ezoReading[rTD], 1);
client.print(F(" degC"));
client.print(F("
"));
client.print(F("Pool pH: "));
client.print(ezoReading[pH], 2);
client.print(F(" pH"));
client.print(F("
"));
client.print(F("Pool Filter: "));
client.print(pReading[poolFilter - 8], 2);
client.print(F(" bars"));
client.print(F("
"));
client.print(F("Balance Tank: "));
client.print(pReading[houseLine - 8], 0);
client.print(F(" Percent"));
client.print(F("
"));
client.println(F(""));
break;
}
if (c == '\n') currentLineIsBlank = true; // you're starting a new line
else if (c != '\r') currentLineIsBlank = false; // you've gotten a character on the current line
} //eof if(client.available)
} //eof while
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
//Serial.println(F("client disconnected"));
} //eof if(client)
} //eof listenForClient
void webDigits(int digits) { // utility for digital clock display: prints preceding colon and leading 0
client.print(F(":"));
if (digits < 10) client.print('0');
client.print(digits);
}
The idea is to print ALL Serial.print and Serial.println statements to an ethernet serial monitor. I'm guessing that this would take a form similar to what this above 5secs page does.
But other than that, I'm completely lost:
1- how do I specify writing to a second page of 192.168.x.xxx ? 2- Does EVERY mention of "Serial.print" run through a version of the above, or can I drop some of those lines after the first call? 3- will there be a history of the Serial.prints available, or would the page start from where I point a browser to it? 4- if no to the above, I would have to write into another log file and dump this onto the web page upon browser pointer, correct? 5- How would I decide at compile time to either compile with Serial.print (lab/office setting) or Ethernet.print (remote setting)? The trigger would be PORT = ComX -> Serial.Print, PORT = ArduinoOTA(x.x.x.x) -> Ethernet.print... 6- This is slightly off topic, but still relates to Ethernet. I use Smtp2Go to send the daily email. Many on the Forum think that it is unsafe to do so, due to hackability. What else could I do? a) send the file to a server behind my firewall every day (I have an old NAS sitting there)? b) Would the Arduino Cloud be any safer and potentially help me display the information too? c) something else?
Some are very basic questions. Sorry about that. Any of the "HTML Basics" links I found on the web seem to overstretch my axons...
Cheers