Event System

A vital component of MudPi is the underlying event system. This system is used to communicate new sensor readings and toggle components. We chose redis to utilize its Pub/Sub capabilities since it was able to work across multiple languages (Python, PHP, and Javascript in our case). If you don't have redis installed here is a guide to Install Redis on your Raspberry Pi

Events

MudPi will publish events when the sensors return readings or during relay state changes. Each event will return a JSON payload with an event: ExampleEvent and its data:'Hello World'. Below are the events MudPi sends out along with the channel they emit on.

Channels

A channel is a communication line that MudPi will broadcast data on. Only clients listening on a channel can receive its events and event data. Events are not rebroadcast so if a listener misses an event it's gone. At the moment the channels are predefined except for relays.

Pi Sensor Events

channel: pi-sensors

Sensor Update

Data will be an object of all your sensor readings.

{
    "event": "PiSensorUpdate",
    "data": {...}
}

Node Events

channel: sensors

Sensor Update

Data will be an object of all your sensor readings.

{
    "event": "SensorUpdate",
    "data": {...}
}

Topics

A topic is another term for channel that is used in home automation. With relays you have the ability to specify what channel the relay listens and broadcasts on through its topic option.

Relay Events

channel: Based on value set for "topic" option in relay configuration

Relay Turned On

{
    "event": "StateChanged",
    "data": 1
}

Relay Turned Off

{
    "event": "StateChanged",
    "data": 0
}

Relay Override

{
    "event": "StateOverride",
    "data": 0
}