Data persistance problems

I defined some variables :
Setting <- {}; Setting.TsKey <- "Unknown"; Setting.TsRefreshDelay <- 120; Setting.SiteName <- "Unknown"; Setting.SiteDescription <- "Unknown"; Setting.SiteAdress <- "Unknown"; Setting.SiteContactInfo <- "Unknown"; Setting.EmailRecipient <- "Unknown"; Setting.OtherDetails <- "";

and in the code, I have :
local table = server.load(); if (table.len() != 0) { Setting = table; } imp.wakeup(1,Main);

But whenever i’m trying to use the variable Setting.SiteName I got an error that say " ERROR: the index ‘SiteName’ does not exist"

I really dont get it

Did you add ‘SiteName’ to the table after doing a if so the table loaded in the second block of code above will not include it. Where do you do your initial (to persist the data?) I would do something like:

`local table = server.load();
if (table.len() != 0) {
    // Table loaded; assign to Setting
    Setting = table;
} else {
    // No table loaded, ie. first run, so save the defaults;

imp.wakeup(1,Main); `

FWIW, in my code I have a flag which I set to true every time I want the code to overwrite an existing persisted table, allowing me to add in new keys without error.

Ok, but why does this dont even work? :
`// Establish the device settings table with default values
clockPrefs <- {};
clockPrefs.mode <- true;
clockPrefs.bst <- false;
clockPrefs.utc <- false;
clockPrefs.offset <- 12;
clockPrefs.brightness <- 15;

// Load the settings table in from permanent storage
local settings = server.load();

// If no preferences have been saved, settings will be empty
if (settings.len() != 0) {
// Settings table is NOT empty so set the clockPrefs to the loaded table
clockPrefs = settings;

function Main(){

server.log("Brightness" + clockPrefs.brightness);



I mean, its the exact code from here :

What do you mean by ‘it doesn’t work’? You should see ‘Brightness15’ in the log. The code above doesn’t do anything else. If you’re expecting to see a different value, you won’t because you don’t ever call to write your settings to permanent storage (at least not in the code above).

Got it, need to run once…always

More specifically needs to be called any time you change data in your table.

You may want to look at this code snippet:

It’s not well documented, but here is some completely untested code from memory which might do what you want:
//Set Defaults (Note: Second parameter of read is default value if they’ve never been set)“mode”, true);“bst”, false);“utc”, false);“offset”, 12);"brightness, 15);

//Called from code not shown here
function changeBrightness(value){
Persist.write(“brightness”, value);

function Main(){
server.log(“Brightness” +“brightness”);