I'm trying to write a time in the format of "XX:XX" to the EEProm. I'm sending it over Bluetooth via a phone app, so I'm not sure how to simulate that in my code, but I've included my code at the bottom.
In the quoted section, you can see I send the data "<sundaytime=15:59>", the code splits it at the delimiter (equals sign) and then should be writing it to memory address 80 (probably 80 through 85 ?) . When I try and read it, it's coming in as "1952" and I'm wondering why that is?
How can I save the ascii values for date and time (XX:XX and XX/XX/XXXX) into EEProm and then read them? I have an Arduino Mega that I'm testing with, but would like to use an Uno for this most likely.
Input
15:59:24.281 -> New BT data: <sundaytime=15:59>
15:59:24.444 -> End char found. serialData is: sundaytime=15:59
15:59:24.444 -> Sunday time: 15:59
15:59:24.445 -> writeToEEProm, settingName: sundaytime , settingValue: 15:59
15:59:24.471 -> Data processed in processSerial, result is: 1
And when I try to read it
Output
15:59:54.461 -> data: 1952
15:59:54.494 -> 0
15:59:54.494 -> str_EEPromValueValidate.c_str()) == 0dataType == 'time'
15:59:54.560 -> data: 1952
15:59:54.560 -> 1
15:59:54.560 ->
15:59:54.560 -> 0
15:59:54.560 -> 2
15:59:54.560 -> 0
15:59:54.594 -> 0
15:59:54.594 -> 2
15:59:54.594 -> 1
15:59:54.594 -> 5
15:59:54.594 -> 1
15:59:54.594 -> 1970
Code
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <TimeLib.h>
SoftwareSerial BTSerial(12, 13); // RX , TX
// Serial In/Out Variables
String serialInString;
boolean newData = false;
String getSettingValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
} // getValue
bool processSerial (String serialInString)
{
bool returnValue = false;
if (serialInString.startsWith("automation") || serialInString == "automation\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Automation: ");
Serial.println(serialInStringValue);
writeToEEProm("automation", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("empty") || serialInString == "empty\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Empty weight: ");
Serial.println(serialInStringValue);
writeToEEProm("empty", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("full") || serialInString == "full\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Full weight: ");
Serial.println(serialInStringValue);
writeToEEProm("full", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("alldays") || serialInString == "alldays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("All Days: ");
Serial.println(serialInStringValue);
writeToEEProm("alldays", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("alldaystime") || serialInString == "alldaystime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("All days time: ");
Serial.println(serialInStringValue);
writeToEEProm("alldaystime", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("sundays") || serialInString == "sundays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Sundays: ");
Serial.println(serialInStringValue);
writeToEEProm("sundays", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("sundaytime") || serialInString == "sundaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Sunday time: ");
Serial.println(serialInStringValue);
writeToEEProm("sundaytime", serialInStringValue);
newData = false;
returnValue = true;
}
else if (serialInString.startsWith("mondays") || serialInString == "mondays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Mondays: ");
Serial.println(serialInStringValue);
writeToEEProm("mondays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("mondaytime") || serialInString == "mondaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Monday time: ");
Serial.println(serialInStringValue);
writeToEEProm("mondaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("tuesdays") || serialInString == "tuesdays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Tuesdays: ");
Serial.println(serialInStringValue);
writeToEEProm("tuesdays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("tuesdaytime") || serialInString == "tuesdaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Tuesday time: ");
Serial.println(serialInStringValue);
writeToEEProm("tuesdaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("wednesdays") || serialInString == "wednesdays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Wednesdays: ");
Serial.println(serialInStringValue);
writeToEEProm("wednesdays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("wednesdaytime") || serialInString == "wednesdaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Wednesday time: ");
Serial.println(serialInStringValue);
writeToEEProm("wednesdaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("thursdays") || serialInString == "thursdays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Thursdays: ");
Serial.println(serialInStringValue);
writeToEEProm("thursdays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("thursdaytime") || serialInString == "thursdaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Thursday time: ");
Serial.println(serialInStringValue);
writeToEEProm("thursdaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("fridays") || serialInString == "fridays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Fridays: ");
Serial.println(serialInStringValue);
writeToEEProm("fridays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("fridaytime") || serialInString == "fridaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Friday time: ");
Serial.println(serialInStringValue);
writeToEEProm("fridaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("saturdays") || serialInString == "saturdays\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Saturdays: ");
Serial.println(serialInStringValue);
writeToEEProm("saturdays", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("saturdaytime") || serialInString == "saturdaytime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("Saturday time: ");
Serial.println(serialInStringValue);
writeToEEProm("saturdaytime", serialInStringValue);
returnValue = true;
}
else if (serialInString.startsWith("chime") || serialInString == "chime\r\n")
{
String serialInStringValue = getSettingValue(serialInString, '=', 1);
Serial.print("chime: ");
Serial.println(serialInStringValue);
writeToEEProm("chime", serialInStringValue);
returnValue = true;
}
else
{
serialInString = "";
returnValue = false;
}
return returnValue;
} // processSerial
String readFromEEPROM(String settingName)
{
if (settingName == "automation")
{
int address = 20;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "empty") // this will be a float
{
int address = 30;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("float", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
return (str_EEPromValue);
}
else if (settingName == "full")
{
int address = 40;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("float", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
return (str_EEPromValue);
}
else if (settingName == "alldays")
{
int address = 50;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "alldaystime") // what data type? string with a semicolon dividing numbers?
{
int address = 60;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "sundays")
{
int address = 70;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "sundaytime")
{
int address = 80;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "mondays")
{
int address = 90;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "mondaytime")
{
int address = 100;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "tuesdays")
{
int address = 110;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "tuesdaytime")
{
int address = 120;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "wednesdays")
{
int address = 130;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "wednesdaytime")
{
int address = 140;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "thursdays")
{
int address = 150;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "thursdaytime")
{
int address = 160;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "fridays")
{
int address = 170;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "fridaytime")
{
int address = 180;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "saturdays")
{
int address = 190;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "saturdaytime")
{
int address = 200;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("time", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
else if (settingName == "chime")
{
int address = 210;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
String str_EEPromValue = "NULL";
if (validateDataType("int", str_EEPromValueValidate.c_str()) == 0)
{
return (str_EEPromValue);
}
if (EEPromValue == 1)
{
str_EEPromValue = "Enabled";
}
else if (EEPromValue == 2)
{
str_EEPromValue = "Disabled";
}
return (str_EEPromValue);
}
} // readFromEEPROM
String readFromEEPROMAll()
{
String returnValue = "";
int address = -1;
int value = -1;
int EEPromValue = -1;
address = 20;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 30;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 40;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 50;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 60;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 70;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 80;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 90;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 100;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 110;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 120;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 130;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 140;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 150;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 160;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 170;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 180;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 190;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 200;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
address = 210;
value = -1;
EEPromValue = EEPROM.get(address, value);
returnValue += String(EEPromValue) + "|";
return returnValue;
} // readFromEEPROMAll
String writeToEEProm (String settingName, String settingValue)
{
Serial.print("writeToEEProm, settingName: "); Serial.print(settingName); Serial.print(" , settingValue: "); Serial.println(settingValue);
if (settingName == "automation")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 20;
EEPROM.put(address, setting);
}
else if (settingName == "empty")
{
int address = 30;
EEPROM.put(address, settingValue);
}
else if (settingName == "full")
{
int address = 40;
EEPROM.put(address, settingValue);
}
else if (settingName == "alldays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 50;
EEPROM.put(address, setting);
}
else if (settingName == "alldaystime")
{
int address = 60;
EEPROM.put(address, settingValue);
}
else if (settingName == "sundays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 70;
EEPROM.put(address, setting);
}
else if (settingName == "sundaytime")
{
int address = 80;
EEPROM.put(address, settingValue);
}
else if (settingName == "mondays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 90;
EEPROM.put(address, setting);
}
else if (settingName == "mondaytime")
{
int address = 100;
EEPROM.put(address, settingValue);
}
else if (settingName == "tuesdays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 110;
EEPROM.put(address, setting);
}
else if (settingName == "tuesdaytime")
{
int address = 120;
EEPROM.put(address, settingValue);
}
else if (settingName == "wednesdays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 130;
EEPROM.put(address, setting);
}
else if (settingName == "wednesdaytime")
{
int address = 140;
EEPROM.put(address, settingValue);
}
else if (settingName == "thursdays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 150;
EEPROM.put(address, setting);
}
else if (settingName == "thursdaytime")
{
int address = 160;
EEPROM.put(address, settingValue);
}
else if (settingName == "fridays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 170;
EEPROM.put(address, setting);
}
else if (settingName == "fridaytime")
{
int address = 180;
EEPROM.put(address, settingValue);
}
else if (settingName == "saturdays")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 190;
EEPROM.put(address, setting);
}
else if (settingName == "saturdaytime")
{
int address = 200;
EEPROM.put(address, settingValue);
}
else if (settingName == "chime")
{
int setting = NULL;
if (settingValue == "enabled")
{
setting = 1;
}
else if (settingValue == "disabled")
{
setting = 2;
}
int address = 210;
EEPROM.put(address, setting);
}
return "1";
} // writeToEEProm
bool validateDataType(String dataType, char* data) // true is indeed 1, and false is 0.
//bool validateDataType(String dataType, String data) // true is indeed 1, and false is 0.
{
if (dataType == "string")
{
for (int i = 0; i < strlen(data); i++)
{
if (isAlpha(data[i]))
{
// continue
}
else
{
return false;
}
}
return true;
}
else if (dataType == "int")
{
for (int i = 0; i < strlen(data); i++)
{
if (isDigit(data[i]))
{
// continue
}
else
{
return false;
}
}
return true;
}
else if (dataType == "float")
{
int decimalPointCount = 0;
for (int i = 0; i < strlen(data); i++)
{
if (isDigit(data[i]))
{
// continue
}
else if (data[i] == '.')
{
decimalPointCount++;
if (decimalPointCount > 1)
{
return false;
}
}
else
{
return false;
}
}
if (decimalPointCount != 1)
{
return false;
}
else
{
return true;
}
}
else if (dataType == "time")
{
Serial.println("dataType == 'time'");
Serial.print("data: "); Serial.println(data);
int colonCount = 0;
for (int i = 0; i < strlen(data); i++)
{
if (isDigit(data[i]))
{
// continue
}
else if (data[i] == ':')
{
colonCount++;
if (colonCount > 1) // will need to make it > 2 if including seconds
{
return false;
}
}
else
{
return false;
}
}
if (colonCount != 1) // will need to make it > 2 if including seconds
{
return false;
}
else
{
return true;
}
}
} // validateDataType
void setup()
{
Serial.begin(9600);
BTSerial.begin(9600);
while (!Serial)
{
; // Wait for serial to connect
}
while (!BTSerial)
{
; // Wait for BTSerial to connect
}
delay(2000);
Serial.println("");
Serial.println(" ***** Start ***** ");
Serial.println("");
Serial.println(readFromEEPROMAll());
//Serial.println(readFromEEPROM("automation"));
//Serial.println(readFromEEPROM("alldays"));
//Serial.println(readFromEEPROM("alldaystime"));
Serial.println(readFromEEPROM("sundays"));
Serial.println(readFromEEPROM("sundaytime"));
//Serial.println(readFromEEPROM("mondays"));
//Serial.println(readFromEEPROM("mondaytime"));
Serial.println("sundaytime");
int address = 80;
int value = -1;
int EEPromValue = EEPROM.get(address, value);
String str_EEPromValueValidate = String(EEPromValue);
Serial.print("EEPromValue: "); Serial.println(EEPromValue);
Serial.print("str_EEPromValueValidate: "); Serial.println(str_EEPromValueValidate);
String str_EEPromValue = "NULL";
Serial.print("str_EEPromValueValidate.c_str()"); Serial.println(validateDataType("time", str_EEPromValueValidate.c_str()));
Serial.print("str_EEPromValueValidate.c_str()) == 0"); Serial.println(validateDataType("time", str_EEPromValueValidate.c_str()) == 0);
Serial.println("");
Serial.println(timeStatus());
time_t t = now(); // Store the current time in time
// variable t
Serial.println(t);
Serial.println(hour(t)); // Returns the hour for the given
// time t
Serial.println(minute(t)); // Returns the minute for the given
// time t
Serial.println(second(t)); // Returns the second for the given
// time t
Serial.println(day(t)); // The day for the given time t
Serial.println(weekday(t)); // Day of the week for the given
// time t
Serial.println(month(t)); // The month for the given time t
Serial.println(year(t)); // The year for the given time t
}
void loop()
{
while(BTSerial.available() > 0 && newData == false)
{
serialInString = BTSerial.readString();
Serial.print("New BT data: "); Serial.println(serialInString);
char serialInCharArr[serialInString.length() + 1];
serialInString.toCharArray(serialInCharArr, (serialInString.length() + 1));
String serialData = "";
for (int i = 0; i < serialInString.length(); i++)
{
if (serialInCharArr[i] == '<')
{
bool startCharFound = true;
serialData = "";
}
else if (serialInCharArr[i] == '>')
{
bool endCharFound = true;
Serial.print("End char found. serialData is: "); Serial.println(serialData);
bool processSerialResult = processSerial (serialData);
Serial.print("Data processed in processSerial, result is: "); Serial.println(processSerialResult);
newData = false;
}
else
{
serialData = serialData + serialInCharArr[i];
}
}
delay(15);
}
delay(5);
newData = false;
}