Documentation

Worker Configuration

Configure workers that handle sensor readings, control inputs, and display operations on multiple threads.

Overview

MudPi has multiple operations it can perform — from toggling relays, to taking sensor readings, to listening for input. These operations are all controlled through workers that run on multiple threads for better performance. You can read more about workers in the Core Concepts — Workers documentation.

To add a worker, place a worker configuration object in the workers array. The minimum required option is type. Add sensors, controls, i2c, or displays based on your worker type:

JSON
{
  "workers": [{
    "type": "sensor",
    "sleep_duration": 30,
    "topic": "sensors",
    "sensors": [
      { "..." : "..." }
    ]
  }]
}

Splitting Workers

If you wish to split components across multiple workers, define another worker configuration with different settings. This lets you poll components at different intervals or emit data on different topics:

JSON
{
  "workers": [
    {
      "type": "sensor",
      "sleep_duration": 30,
      "topic": "sensors",
      "sensors": [{ "..." : "..." }]
    },
    {
      "type": "sensor",
      "sleep_duration": 10,
      "topic": "sensors",
      "sensors": [{ "..." : "..." }]
    }
  ]
}

Tip

You can store everything on one worker or spread across multiple workers — the choice is up to you. Multiple workers let you fine-tune polling intervals per component group.

Settings

Option Type Required Description
`type` String Yes Type of worker. Options: `sensor`, `control`, `i2c`, `display`
`sleep_duration` Integer No Seconds to pause between reading cycles. Minimum is 2 seconds to prevent crashing.
`topic` String No Redis channel name to emit sensor reading data through.

Type-Dependent Settings

Each worker type has its own set of configuration options:

Option Type Required Worker Type Description
`sensors` Array No Sensor Array of sensor configs. See [sensors](/docs/configuration-sensors) configuration.
`controls` Array No Control Array of control configs. See [controls](/docs/configuration-controls) configuration.
`displays` Array No Display Array of display configs. See [displays](/docs/configuration-displays) configuration.