Environment Variables
Environment variables allow you to configure device-specific settings without changing your code. Each device can have different values for the same variables, making it easy to customize behavior across your fleet.
Defining Environment Variables
To add environment variables to your app, define a JSON Schema in your release configuration. This is done by setting envSchema and optionally envUiSchema when publishing your app.
envSchema
The envSchema defines what environment variables your app accepts using JSON Schema:
{
"type": "object",
"required": ["pinNumber"],
"properties": {
"pinNumber": {
"title": "Pin number",
"type": "string"
}
}
}
envUiSchema
The envUiSchema customizes how the form is rendered using React JSON Schema Form UI Schema:
{
"pinNumber": {
"ui:placeholder": "Enter GPIO pin number"
}
}
Setting Values
When adding a new device to your app, the environment variables form appears during device setup. Users can configure values specific to each device before flashing.
Accessing Environment Variables in Code
Environment variables are available through the standard WASI environment interface:
#include <stdlib.h>
int main() {
char* pin_number = getenv("pinNumber");
if (pin_number) {
int pin = atoi(pin_number);
// Use the pin value
}
return 0;
}