Send variable from WWW and store after powering down Photon

I have built a temp controller and have a web page which I use to change the target temp via a callFunction(). Currently, when the photon loses power and reboots, the variable is reset to default value specified in the firmware (whatever the target temp set via the web page is lost). What is the easiest way to store this value so it is retained? Is it possible to store permanently in a file on the Photon (via a flash or otherwise)? Is it possible to store variables in the cloud somewhere which can be read by the Photon on startup?

Looking for the simplest way to accomplish this. Thanks!

Have a look for ‘retained variables’ and/or EEPROM :slight_smile:

I store these types of settings in the EEPROM and use a function call to set them from my web page.

uint8_t         sleep_dimmer_flag           = 0;

// EEPROM parameters.
enum EEPROMAddress
{
    SLEEP_DIMMER_FLAG_EEID  = 1,
};


// Spark.Function - Handle parameter settings.
// Returns: -1 = unknown command,  -2 = invalid value,  X = parameter
int Function_parameter_handler(String command)
{
    int             result  = -1;
    const char *    ptr     = command.c_str();
    
    if (strncmp(ptr, "sleep_dimmer=", 13) == 0)
    {
        uint8_t flag   = atoi(ptr+13);
        
        if (flag <= 1)
        {
            sleep_dimmer_flag   = flag;
            EEPROM.write(SLEEP_DIMMER_FLAG_EEID, sleep_dimmer_flag);
            result  = flag;
        }
        else
        {
            result  = -2;
        }
    }
    
    
    return (result);
}

void setup() 
{
    sleep_dimmer_flag   = EEPROM.read(SLEEP_DIMMER_FLAG_EEID);
}
1 Like

thanks guys, exactly what i needed.