Over a million developers have joined DZone.

Mulesoft With IoT: LEDs and a Raspberry Pi

DZone's Guide to

Mulesoft With IoT: LEDs and a Raspberry Pi

See how you can use MuleSoft's Anypoint and Runtime engines can work for your IoT apps. This simple blinky app demonstrates its capabilities while incorporating Twitter.

· IoT Zone ·
Free Resource

The Internet of Things (IoT) is the network of physical devices, vehicles, and other items embedded with electronics, software, sensors, actuators, and network connectivity which enable these objects to collect and exchange data.

The Anypoint Mule engine can be embedded directly into IoT devices, which enables data exchange for the devices by connecting to IoT cloud services and backend apps in the cloud.

The Mule Runtime engine can be used to expose APIs on any IoT device. Mule APIs can be deployed on IoT devices and turn them on and off.

In this blog, I will demonstrate how we can use a Twitter feed in Mule to send the input to a Raspberry Pi in order to light up LEDs.

Mule provides connectivity to all SaaS apps like Twitter, Facebook, Box, Google, etc.

Image titleA Mule app deployed in an MMC instance on the Raspberry Pi subscribes to a Twitter feed. For every feed, it calls a Python script and, in turn, the Raspberry Pi controls the blinking of the LEDs. 


You'll need the following on order to follow along with this tutorial:

  • Raspberry Pi

  • MMC

  • Python script (provided below)

  • Resistors

  • Power supply

  • LED bulbs

Setup Instructions

  1. You should be able to SSH into the Raspberry Pi. Ensure it is connected to Wi-fi.

  2. The GPIO pins on the Raspberry Pi are what makes it powerful. These pins are a physical interface between the Pi and the outside world. In layman's terms, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output). Of the 40 pins, 26 are GPIO pins, and the others are power or ground pins. You can program the pins to interact in amazing ways with the real world.

We are using a very basic Python script that can control GPIO commands to blink the LED bulb.

Python Script (ledBlink.py)

import RPi.GPIO as GPIO import time
print "LED off"

  1. Install an MMC instance on the Raspberry Pi. Develop a Mule app that gets a Twitter feed and can call the Python script. Call the Python script in localhost (Raspberry Pi). Deploy it on the Raspberry Pi Mule instance.

Image title

  1. The Mule app will get the feed from my Twitter account and call the Python script, which, in turn, will turn the LEDs on.

This demonstrates how a Mule instance running on a tiny Raspberry Pi controls the turning on/off of lights.

MuleSoft’s Runtime Engine can be used in various innovative ways to connect devices, data, and applications. This is a basic example of the Internet of Things with Mulesoft. If you'd like to look at the code for this tutorial, please have a look at my GitHub Repository.

iot app development ,mulesoft ,twitter ,raspberry pi 3 ,iot ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}