Documentation

Data Storage

MudPi stores component state in Redis for backup and retrieval, using a simple key-value format.

Overview

MudPi uses Redis as its primary data store. Component state is automatically backed up to Redis, making it available for external applications, dashboards, and recovery after restarts.

State Keys

State is stored in Redis using the format {key}.state, where {key} is the component's slugged key. For example, a sensor configured with:

JSON
{
  "key": "soil_sensor_1",
  "interface": "gpio",
  "type": "soil_moisture",
  "pin": 4
}

Would have its state stored at the Redis key soil_sensor_1.state.

Retrieving State

You can retrieve state directly from Redis using the CLI or any Redis client:

Shell
redis-cli GET "soil_sensor_1.state"

Other Stored Keys

In addition to state, MudPi stores other system data in Redis:

Key Type Description
started_at String (timestamp) The timestamp when MudPi was started
state_keys List A list of all registered state keys in the system

Key Slugging

Component keys are slugged before being used as Redis keys. This means spaces are replaced with underscores and special characters are removed. Keep your component keys simple and lowercase to avoid unexpected key formatting.

Warning

Redis stores all values as strings. A boolean False value in Python is stored as the string "False" in Redis, which is truthy in most languages. Always compare against the string representation when reading boolean state from Redis directly.

Tip

Use the state_keys list to discover all available state keys: redis-cli LRANGE "state_keys" 0 -1