IoT communication with the Adafruit IO API

Switching via the Dashboard

The program code for the Huzzah board in Listing 1 and the circuit in Figure 1 already includes a convenient function for receiving messages from the dashboard. This approach makes it easy for the developer to trigger actions on the IoT device. The LED on GPIO 13 controls an event handler that receives messages from a feed. The example shows the feed titled LED.

Figure 1: IoT clients and desktop apps communicate via REST or MQTT with the Adafruit IO API.

You create the dashboard in Figure 4 via Dashboard | Actions | Create a New Dashboard. You can then click on the blue plus symbol to add a new block to this dashboard. After selecting the toggle button and linking it with the LED feed, you create the block using Create block. The dashboard also includes a line graph next to the button for the LED that shows the temperature and humidity levels.

Figure 4: The dashboard not only displays the feed data, it also controls IoT devices, specifically the LED.

Finally, when you click on the toggle button on the dashboard, the sensor board detects it and turns the LED on or off. The function led-> onMessage() in Listing 1 redirects incoming notifications to the handleMsg() function, which analyzes the content of the message and switches to the appropriate LED.

Conclusions

Open hardware platforms such as Arduino and Adafruit lower the barriers for creative IoT projects. Meanwhile, the Adafruit IO API makes it particularly easy to combine network-compatible sensors with web dashboards and control them via the Internet. Only a few lines of script integrate applications into the Linux desktop.

Dashboards don't just display the measured data, they are also perfect for controlling hardware. Application output, as well as system values such as CPU and memory usage, can trigger events on the IoT hardware. You can use this triggering feature to display a message or output a signal to another hardware component, such as a light or WiFi socket.

The Author

Marcus Nasarek is completely devoted to scripting, Ruby, and the Raspberry PI.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Digital Spirit Level

    The small MPU6050 sensor contains a gyroscope and an accelerometer, which means that you can build a digital spirit level with it.

  • Web Serial API

    Upgrade your computer with LEDs, buttons, or sensors to control a microcontroller board over USB from your web browser.

  • Adafruit PyPortal

    Unlike other displays for the Raspberry Pi, Adafruit's PyPortal touchscreen provides an autonomous environment, including a microprocessor, sound output, and a WiFi connection.

  • Xonsh

    Create lightweight Raspberry Pi scripts with Xonsh, a Python shell that lets you write scripts in Python with Bash commands mixed in.

  • Whiptail

    Whiptail interfaces add menus and information pages to your Raspberry Pi projects.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News