How to write and read date time to/from EEProm?

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;

}

Could the problem be that Strings (capital S) are objects of the String library rather than normal variables and hence that you cannot use put() and get() to save and load them

Have you considered using C style strings, ie arrays of chars instead of Strings ?

Which Arduino board are you using , as there may be other solutions ?

Hi, I'm using an Arduino Mega for testing, but would like to use the Uno as a final product.

As for Strings, I had posted some code a week ago and a forum member advised me to use EEProm.put and get, so I've been doing that and it has been fine for integers and ascii. If you are suggesting I should use .c_str(), I will try that and report back.

Doing that means converting back and forth between Strings and strings. What I was suggesting was using strings throughout and not using Strings at all, hence no need for conversion either way

1 Like

It does not help that you are attempting to write a String to EEPROM, then reading back an integer.

1 Like

I think that's the crux of my problem. Do you have any suggestions to approach storing non integers into EEProm?

1 Like

You can store an load variables of any type using put() and get(). What is the problem ?

1 Like

Probably my inexperience with hardware level programming.

I'll read up on that when I get back home, I was hoping to get some guidance from someone more experienced than myself, as to how they'd approach it.

1 Like

I wasn't sure how to approach this (and learn at the same time) so I did it with the code block at the bottom and this snippet from it appears to be the winner.

Can a c_str act like "var" in other languages, where it's type agnostic?

EEPROM.put(addressT, s_settingValue.c_str());
c_eepromGet[10];
EEPROM.get(addressT, c_eepromGet);
Serial.print("c_eepromGet: "); Serial.println(c_eepromGet);

21:56:16.630 -> s_eepromGet: == 0 *** Start Test *** 15:30s_eepromGet: i_

21:56:16.695 -> i_eepromGet: 1530

21:56:16.729 -> f_eepromGet: 0.00

21:56:16.761 -> c_eepromGet: �:30

21:56:16.761 ->

21:56:16.761 -> s_eepromGet: �����������������������������������������������

21:56:16.826 -> i_eepromGet: 13617

21:56:16.859 -> f_eepromGet: 0.00

21:56:16.859 -> c_eepromGet: 15:30

21:56:16.892 ->

21:56:16.892 -> *** End Test ***

    Serial.print(""); Serial.println(" *** Start Test *** "); Serial.print("");

    int addressT = 80;
    String s_settingValue = "15:30"; 
    int i_settingValue = 1530;
    char c_settingValue[10] = "15:30";

    String s_eepromGet = "";
    int i_eepromGet = -1;
    float f_eepromGet = 0.00f;
    char c_eepromGet[10];

    // String put
    EEPROM.put(addressT, s_settingValue.c_str());

        s_eepromGet = "";
        EEPROM.get(addressT, s_eepromGet);
        Serial.print("s_eepromGet: "); Serial.println(s_eepromGet);

        i_eepromGet = -1;
        EEPROM.get(addressT, i_eepromGet);
        Serial.print("i_eepromGet: "); Serial.println(i_eepromGet);

        f_eepromGet = 0.00f;
        EEPROM.get(addressT, f_eepromGet);
        Serial.print("f_eepromGet: "); Serial.println(f_eepromGet);

        c_eepromGet[10];
        EEPROM.get(addressT, c_eepromGet);
        Serial.print("c_eepromGet: "); Serial.println(c_eepromGet);

        Serial.println("");


    // cString put
    EEPROM.put(addressT, s_settingValue.c_str());

        s_eepromGet = "";
        EEPROM.get(addressT, s_eepromGet);
        Serial.print("s_eepromGet: "); Serial.println(s_eepromGet);

        i_eepromGet = -1;
        EEPROM.get(addressT, i_eepromGet);
        Serial.print("i_eepromGet: "); Serial.println(i_eepromGet);

        f_eepromGet = 0.00f;
        EEPROM.get(addressT, f_eepromGet);
        Serial.print("f_eepromGet: "); Serial.println(f_eepromGet);

        c_eepromGet[10];
        EEPROM.get(addressT, c_eepromGet);
        Serial.print("c_eepromGet: "); Serial.println(c_eepromGet);
        
        Serial.println("");


    // int put    
    EEPROM.put(addressT, i_settingValue);

        s_eepromGet = "";
        EEPROM.get(addressT, s_eepromGet);
        Serial.print("s_eepromGet: "); Serial.println(s_eepromGet);

        i_eepromGet = -1;
        EEPROM.get(addressT, i_eepromGet);
        Serial.print("i_eepromGet: "); Serial.println(i_eepromGet);

        f_eepromGet = 0.00f;
        EEPROM.get(addressT, f_eepromGet);
        Serial.print("f_eepromGet: "); Serial.println(f_eepromGet);

        c_eepromGet[10];
        EEPROM.get(addressT, c_eepromGet);
        Serial.print("c_eepromGet: "); Serial.println(c_eepromGet);

        Serial.println("");


    // char[] put    
    EEPROM.put(addressT, c_settingValue);

        s_eepromGet = "";
        EEPROM.get(addressT, s_eepromGet);
        Serial.print("s_eepromGet: "); Serial.println(s_eepromGet);

        i_eepromGet = -1;
        EEPROM.get(addressT, i_eepromGet);
        Serial.print("i_eepromGet: "); Serial.println(i_eepromGet);

        f_eepromGet = 0.00f;
        EEPROM.get(addressT, f_eepromGet);
        Serial.print("f_eepromGet: "); Serial.println(f_eepromGet);

        c_eepromGet[10];
        EEPROM.get(addressT, c_eepromGet);
        Serial.print("c_eepromGet: "); Serial.println(c_eepromGet);

        Serial.println("");

Never mind, that doesn't work when I try it outside of the test code.

If anyone could give an example of how I can read and write to the EEPROM without having to worry about variable types, I'd really appreciate it.

1 Like

Simplest way I can think of is to store the string in a struct, then the get() and put() functions have a fixed size to work with.

#include <EEPROM.h>

void setup() {
  Serial.begin(9600);
  Serial.print("");
  Serial.println(" *** Start Test *** ");

  int addressT = 80;
  String s_settingValue = "15:30";
  
  struct {
    char text[10];
  } dataPut, dataGet;

  strlcpy(dataPut.text, s_settingValue.c_str(), sizeof(dataPut.text));
  EEPROM.put(addressT, dataPut);

  EEPROM.get(addressT, dataGet);
  Serial.print("eepromGet: "); Serial.println(dataGet.text);
}

void loop() {
}

What you are trying to do is really simple

#include <EEPROM.h>

char valueToEEPROM[20] = "15:30";
char valueFromEEPROM[20];

void setup()
{
    Serial.begin(115200);
    Serial.print("writing ");
    Serial.println(valueToEEPROM);
    EEPROM.put(0, valueToEEPROM);
    EEPROM.get(0, valueFromEEPROM);
    Serial.print("read ");
    Serial.println(valueFromEEPROM);
}

void loop()
{
}

1 Like

See the two replies above.

As you only seem to need to store the time in format "HH:mm", you need a character array of 6 bytes (5 plus 1) to retrieve the time. After that, you can convert it to a String if needed.

I appreciate everyone's replies and I'm sure it is simple, however it hasn't been going simple for me, for whatever reason. It's almost 2am, so maybe that's part of the issue.
I kept getting compiler errors with .put and .get and so I switched over to .write and .read.

I wanted to create a function that is flexible, so I don't have to know the size or data type to write to the EEPROM. This way I can use it to write ints, floats, strings, timedate, etc.

I don't know if the code below is going to cut it, as I've only tested it with the time format of "xx:xx" or "x:xx", however if you all give it the thumbs down, I will try to implement your most recent suggestions when I wake up tomorrow.

String eepromReadAll(int eeAddress)
{
    int eeAddressIndexer = eeAddress;
    String returnValue;
    char c;
    
    do 
    {
        c = EEPROM.read(eeAddressIndexer);
        if (c != '\0')
        {
            Serial.print("eepromReadAll: "); Serial.println(c);
            returnValue += c;
        }
        eeAddressIndexer = (eeAddressIndexer + 1);
    } while (c != '\0');

    return returnValue;
}


void eepromWriteAll(int eeAddress, String eeValue)
{
    char c_eeValue[eeValue.length()];
    eeValue.toCharArray(c_eeValue, (eeValue.length() + 1));
    Serial.print("c_eeValue: "); Serial.println(c_eeValue);
    int indexer = 0;
    for (int i = 0; i < strlen(c_eeValue); i++)
    {
        Serial.println(c_eeValue[i]);
        EEPROM.write((eeAddress + i), c_eeValue[i]);
        indexer = (eeAddress + i);
    }

    EEPROM.write((indexer + 1), '\0');
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.