Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active December 2, 2019 11:49
Show Gist options
  • Save ElectricImpSampleCode/0985f6f6de403e26e767 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/0985f6f6de403e26e767 to your computer and use it in GitHub Desktop.
Electric Imp imp API server.load() example code
// Establish the device's settings table with default values
deviceSettings <- {};
deviceSettings.mode <- true;
deviceSettings.dst <- true;
deviceSettings.utc <- false;
deviceSettings.offset <- 12;
deviceSettings.brightness <- 15;
// Load preserved settings in from permanent storage
local loadedSettings = server.load();
// If no preferences have been saved, 'loadedSettings' will be empty
if (loadedSettings.len() != 0) {
// Settings table is NOT empty so set 'deviceSettings' to the loaded table
deviceSettings = loadedSettings;
}
// Send the settings to the device
device.send("set.preferences", deviceSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment