An important part of MudPi are sensors. Without them it can be hard to determine the status of our system and when to trigger components. MudPi supports a variety of both digital and analog sensors. The pi can only has digital GPIO support, so through attached nodes we can use analog sensors.

Sensor Fundamentals

Sensors work similar for both the pi and arduino. The main difference is there are more sensors supported on the arduino due to its analog capabilities. All sensors require three options to load: type, pin, and key. The type of sensor determines which sensor class gets instantiated by the sensor worker.

All sensor classes extend from a base sensor class are intended to be as simple as possible. The main responsibility of a sensor is to just get the data and return that to the worker. Sensors should not sleep the thread. Instead that is for workers to handle as well as storing/publishing data.

Sensor Readings

Sensors take readings during each worker loop. For each loop all the sensor data is packaged in a JSON object keyed based on the sensor key. This data then gets published over redis. Below are the two sensor events that MudPi broadcasts.

Pi Sensor Event

topic: pi-sensors

Data will be an object of all your sensor readings keyed based on the sensor key.

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

Node Sensor Event

topic: sensors

Data will be an object of all your sensor readings.

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

Stored Data

Sensor data is also stored into redis temporary memory as well. Only the last reading will be stored, all new values overwrite the previous. So it is up to you if you wish to store value longer into a more persistent database. MudPi will store sensor values in redis for you using the "key" you specified for the sensor in the mudpi.config file.

Note the "key" will be slugged (converted to lowercase and spaces replaced with underscores) to make it a valid redis key.