Cayenne for Raspberry Pi

Sensors, Triggers, and Schedules

The ability to monitor your Rasp Pi, access its graphical desktop environment remotely, and control GPIO is great, but that's not Cayenne's most interesting functionality. After all, it's not a mere server monitoring service, but an IoT platform. The GPIO port makes it possible to connect a wide range of sensors and peripherals to the Rasp Pi: from temperature and PIR sensors to motors and actuators. And using Cayenne, you can read and process data from sensors and control the attached peripherals. Better still, the platform lets you create triggers and schedule events.

To demonstrate Cayenne's capabilities, I'll build a simple project that works with a temperature sensor connected to the Rasp Pi. For this project, you need a DS18B20 digital temperature sensor, a 4.7Kohm resistor, a breadboard, and a handful of wires. Start with wiring the sensor and the resistor as shown in Figure 7. Connect the circuit to the 3.3V, GND, and GPIO4 pins. Next, you need to load the 1-Wire and thermometer drivers using the following commands:

sudo modprobe w1-gpio
sudo modprobe w1-therm
Figure 7: Temperature sensor wiring diagram.

To make sure that everything works, switch to the /sys/bus/w1/devices/ directory and run the ls command:

cd /sys/bus/w1/devices/

You should see the temperature sensor listed as an alphanumeric sequence (e.g., 28-00000452baa5). Use the following command to check whether the sensor transmits any data:

cd 28-00000452baa5
cat w1_slave

If the sensor works properly (Figure 8), you should see output that looks something like:

8e 01 4b 46 7f ff 02 10 02 : crc=02 YES
8e 01 4b 46 7f ff 02 10 02 t=24875
Figure 8: Enabling the temperature sensor.

Cayenne is intelligent enough to detect a new data source (a temperature sensor in this case) automatically and add a widget for it. You can then adjust the widget's default settings, if needed. Now you can monitor the temperature directly from the Cayenne dashboard and view temperature data as a chart by clicking on the Details & Chart icon in the upper-right corner of the widget.

But that's not the only thing for which you can use Cayenne. The platform also makes it possible to create so-called triggers that perform certain actions when a specific event occurs. For example, you can create a trigger that sends you email or an SMS alert when the temperature level exceeds a specified threshold (Figure 9). To create a new trigger, select Trigger from the Add new drop-down list. If you have set up a separate project, you can create a trigger in the Triggers & Alerts section.

Figure 9: Cayenne makes it easy to create triggers.

Triggers in Cayenne are based on a simple if-then rule. Drag the Rasp Pi item onto the if area and select the temperature sensor from the Select Trigger drop-down list. In the then area, click on setup notification and configure notification settings. Press Save Trigger to save and enable the trigger. Next time the temperature value exceeds the specified threshold, you'll receive an alert via email or SMS (or both, depending on the notification settings).

In addition to triggers, Cayenne also supports event scheduling. For example, if you want to turn the connected LED on and off at specific times, you can add the appropriate events to the schedule. After selecting Event from the Add new drop-down list (or use the Scheduling section in a project), you can configure the event as shown in Figure 10. Of course, you can configure the schedule and recurrence the way you like it and add a notification, if needed.

Figure 10: Cayenne also makes scheduling events easy.

Final Word

Cayenne provides a perfect introduction to the IoT world. The platform is designed to work with Rasp Pi, the software is easy to deploy, and the accompanying mobile app is a boon for Android and iOS users. Building projects with Cayenne requires no particular skills, and you can use the platform free of change (at least for the time being). So what's not to like?

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Power to You

    Small-board computers (SBCs) are getting more and more powerful. The Raspberry Pi 3 (RPi3), which just came out in February of this year, is a case in point. This latest in the Rasp Pi line now has four cores running at 1200MHz with 1GB of RAM and on-board WiFi and Bluetooth. If you need even more power in a small computer, however, you are not left wanting. In this issue, we look at three SBCs with more cores, more memory, more ports, and more possibilities.

  • Building a Raspberry Pi greenhouse

    A greenhouse environment has to be just right. The temperature can't climb too high or sink too low, and the plants need water. Why not put your Raspberry Pi to work as the gardener?

  • Reporting Rasp Pi data on a Node.js web server

    Combine great hardware projects that use the Raspberry Pi GPIO pins and a Node.js web server that interacts with the underlying operating system and hardware, and you have a winning team.

  • Roasting beans in a repurposed air popper

    Transform an old air popcorn popper into a coffee bean roaster controlled by a Raspberry Pi and a slick user interface.

  • Create amazing Pi apps without writing code

    Create super easy Pi programs to turn on lights, speak to you, or control motors.