Here is the complete code that applies to this situation. I shortened it down so you didn't have to scroll through 1000+ lines. I tried to bold anything that was important.
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// VARIABLE DEFINITIONS //
[b]long master;
uint8_t Master = 0;[/b]
uint8_t NameC[11] /*= {4095, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}*/;
uint8_t Code[11] = {4096, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
uint8_t A_C[11] = {4096, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long timeoutTime = 2000;
String header;
void setup() {
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(".");
WiFi.config(ip, gateway, subnet);
Serial.println("Successfully Connected");
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_FS
type = "filesystem";
}
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.begin();
server.begin();
EEPROM.begin(4096);
[b]variableUpdate();[/b]
//master = 1514;
}
void loop() {
//ArduinoOTA.handle();
WiFiClient client = server.available();
if (client) { // If a new client connects,
Serial.println("Client Connected"); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
currentTime = millis();
previousTime = currentTime;
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
Serial.print("HEADER:");
Serial.println(header);
[b]getHeader();
eepromUpdate();[/b]
// Display the HTML web page
client.println("<div class='tab'><button class='tablinks active' onclick=\"openTab(event, 'Codes'); lastTab('Codes')\">Codes</button>");
client.println("<button class='tablinks' onclick=\"openTab(event, 'Fingerprints'); lastTab('Fingerprints')\">Fingerprints</button></div>");
//CODES TABLE
client.println("<div id='Codes' class='tabcontent' style='display:block'><h2>Codes</h2><table align='center';><col width='20%'><col width='25%'><col width='25%'><col width='20%'>");
client.println("<tr><th>Code ID</th><th>Name</th><th>Code</th><th>Active</th></tr>");
client.print("<tr><td>0</td><td>MASTER</th><td>");
client.print([b]master[/b]);
client.println("</td><td><input type='checkbox' checked disabled /></td></tr>");
for (int x = 1; x <= 10; x++) {
client.print("<tr><td>");
client.print(x);
client.print("</td><td>");
client.print(nameC[x]);
client.print("</td><td>");
client.print(code[x]);
client.println("</td><td>");
if (a_C[x] == 1) {
client.print("<input type='checkbox' checked onclick=\"window.location.assign('/c");
client.print(x);
client.println("/0')\"/></td></tr>");
} else {
client.print("<input type='checkbox' onclick=\"window.location.assign('/c");
client.print(x);
client.println("/1')\"/></td></tr>");
}
}
client.println("</table></div>");
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
[b]void variableUpdate()[/b] {
long four = EEPROM.read(Master);
long three = EEPROM.read(Master + 100);
long two = EEPROM.read(Master + 200);
long one = EEPROM.read(Master + 300);
master = (((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF));
}
[b]void eepromUpdate()[/b] {
//EEPROM.write(Master, master);
byte four = (master & 0xFF);
byte three = ((master >> 8) & 0xFF);
byte two = ((master >> 16) & 0xFF);
byte one = ((master >> 24) & 0xFF);
EEPROM.write(Master, four);
EEPROM.write(Master + 100, three);
EEPROM.write(Master + 200, two);
EEPROM.write(Master + 300, one);
delay(500);
EEPROM.commit();
delay(500);
}
I appreciate your willingness to help out!!
Thank you,
James