Annoying... had to delete loads of code
void setup()
{
pinMode(10, OUTPUT); // disable Ethernet chip
digitalWrite(10, HIGH);
Serial.begin(9600);
//Factory_reset ();
data1=EEPROM.read(551); //Check to see if this is the first time this program has ever run
if (data1==0) {First_run ();}
while (!Serial) { // Open serial communications and wait for port to open:
}
Serial.println();
Serial.print(F("Checking for SD card... "));
Serial.println();
if (SD.begin(4)) {
Serial.println(F("SUCCESS: Found SD card"));
Serial.println();
delay(50);
myFile = SD.open("SiteData.txt"); // Open the file for reading:
if (myFile) {
Serial.println(F("Opening SiteData.txt:"));
Serial.println(F(" "));
//### deleted all the files saving here
myFile.close(); // close the file:
} else {
Serial.println(F("Error opening SiteData.txt")); // if the file didn't open, print an error:
myFile.close();
}
}else {Serial.print(F("No SD card present, using memory stored data"));}
delay(500);
Serial.println();
Serial.println("Obtaining webpage layout details and logos..."); // Open Page1.html on SD card to get webpage layout details + logos
if (SD.exists("Page1.htm")) {Serial.println("SUCCESS: Opening Page1.htm file.");}
else {Serial.println("ERROR: Can't find Page1.htm file!");}
IPAddress ip(192, 168, 1, 75);
IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);
Ethernet.begin(mac, ip); //start the Ethernet connection and the server:
server.begin(); // start to listen for clients
}
void loop() {
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
// print HTTP request character to serial monitor
Serial.print(c);
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// open requested web page file
if (StrContains(HTTP_req, "GET / ")
|| StrContains(HTTP_req, "GET /login.htm")) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
myFile = SD.open("login.htm"); //Open first web page file and obtain the names of the logo files
}
else if (StrContains(HTTP_req, "GET /Ourlogo.jpg")) { //Display our logo
myFile = SD.open("Ourlogo.jpg");
if (myFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
else if (StrContains(HTTP_req, "GET /Sitelogo.jpg")) { //Display the site logo
myFile = SD.open("Sitelogo.jpg");
if (myFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
if (myFile) {
while(myFile.available()) {
client.write(myFile.read()); // send web page to client
}
myFile.close();
}
if (StrContains(HTTP_req, "User")) {
if (StrContains(HTTP_req, "User=Steve")) {Serial.println("Found user");}
if (StrContains(HTTP_req, "Pswrd=12345")) {Serial.println("Found password");}
if ((StrContains(HTTP_req, "User=Steve")) and (StrContains(HTTP_req, "Pswrd=12345"))){
Serial.println("Access granted");
Access=true;
}
else
{} //Redirect to another website if wrong submission after 5 attempts. Yet to be determined
}
if (Access==true) { client.println("HTTP/1.1 200 OK"); //If access is granted, then populate the screen
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
myFile = SD.open("systemstatus.htm");
if (myFile) {
while(myFile.available()) {
client.write(myFile.read()); // send web page to client
}
myFile.close();
}
Access=false;
}
req_index = 0; // reset buffer index and all buffer elements to 0
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
if (c == '\n') { // every line of text received from the client ends with \r\n
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
void Read_EEPROM () {
Serial.println(" ");
for (count=1;count<30;count++) {
data2=EEPROM.read(count+(((data1*30)-30)));
Serial.print(char(data2));
}
}