System calls
Enviroment variables - System
Environment is a collection of lightweight, non‑secret, name - value pairs that shape the runtime environment. They are ideal for fast, system level adjustments (endpoints, feature flags, polling intervals) without changing firmware. Available in the cloud and in the firmware, they allow configuration of both Device OS features and user features in a hierarchical manner from organization, the product, with optional per-device overrides.
For more information, see Environment.
getEnv - Enviroment variables - System
Get the value of an environment variable.
// EXAMPLE
String value;
if (System.getEnv("TEST_VAR", value)) {
Log.info("TEST_VAR=%s", value.c_str());
}
// EXAMPLE
bool enabled;
if (System.getEnv("ENABLE_DEBUG", enabled) && enabled) {
// Variable was set and is value and true
}
// EXAMPLE
int value;
if (System.getEnv("RETRY_PERIOD", value)) {
// Value was set, do something with it here
}
// PROTOTYPES
// Returns an empty string if the variable is not defined
static String getEnv(const char* name);
// Returns true if found, modifies value only on success
static bool getEnv(const char* name, String& value);
// Validates if the env is exactly "true" or "false" (case-sensitive, lowercase only)
// Returns true if found AND valid, modifies value only on success
static bool getEnv(const char* name, bool& value);
// Validates if the env is a valid integer (32-bit, signed, decimal only)
// Returns true if found AND valid, modifies value only on success
static bool getEnv(const char* name, int& value);
hasEnv - Enviroment variables - System
// EXAMPLE
if (System.hasEnv("RETRY_PERIOD")) {
// Do something
}
// PROTOTYPE
static bool hasEnv(const char* name);
listEnv - Enviroment variables - System
// EXAMPLE
Vector<const char*> list = System.listEnv();
for(auto it = list.begin(); it != list.end(); it++) {
const char *key = *it;
Log.info("key=%s value=%s", key, System.getEnv(key).c_str());
}
// PROTOTYPE
static Vector<const char*> listEnv();
clearEnv - Enviroment variables - System
Returns true if a system reset is needed to apply the changes. If reset is true (default), resets the device automatically.
// EXAMPLE
System.clearEnv();
// PROTOTYPE
static bool clearEnv(bool reset = true);