Best way to transfer 1k-2k from APP into EEprom?

That’s why I referenced the post above. And why ScruffR said what he said. The way you are saving the string is not how to save a string in EEPROM. You need to specify the pointer to the data and the length of the data to get or put. You can’t just pass a pointer to a c-string, it doesn’t work that way.

2 Likes

@rickkas7, I actually red the referenced post before I make up the test case but I guess I didn’t fully understand it since I have not touch pointer for a long time. I am revisiting the referenced post and see if I can make more sense out of it. Could you help me out with this example code? If I am publishing a string from the IOS APP say 1"175 and getting to the subscribing handler const char *data. How I can store this in the EEprom? It seem like in the referenced post you convert the data back to String before you write to the EEprom.

If you simply want to store a single value that you are sending with a publish, then you can just copy data into sunSched, and use EEPROM.put to store it. There’s no need to convert data into a String object. Here is an example of one way to do that,

char sunSched[240];
int dayflag;

void setup() {
    Particle.subscribe("schedTest", schedHandler);
    Serial.begin(9600);
    delay(3000);
    EEPROM.get(0, sunSched);
    Serial.printlnf("sunSched (from setup) is: %s", sunSched);
    delay(3000);
}

void loop() {}

void schedHandler(const char *event, const char *data) {
    strcpy(sunSched, data); // be careful that data is not bigger than sunSched
    dayflag = atoi(data);
    switch(dayflag) {
        case 1:
            Serial.println("storing new value");
            EEPROM.put(0, sunSched);
            break;
        default:
            Serial.println("default");
            break;
    }
}

The first time you run this, the print out will be whatever happens to be in the EEPROM at the time, but it should reflect the value you send in the publish the next time you run it.

However, I suspect that you want to send more than one value at some point since you’re using a switch statement. In that case, you need to know where to store the next value. A simple way to do that would be to always send the same size data, so you can just increment the location in the eeprom where you store or read the data. We could give you more detailed advice if we knew what you actually intend to do.