There
is a new jargon in the IT world called IoT - Internet of things. This is not
new to IT industry but it is not that common. This blog is not to cover about
IoT or any other technologies in details. Rather, I have tried to provide
technical information on how to collaborate different technologies and create
an end to end basic IoT application.
Technologies
1.
MS Azure Cloud Service
2.
Python
Hardware
1.
Raspberry Pi 2
2.
GIPO Bread Board to create circuit
3.
1K Ohm 1/4 W 0.25W Resistor
4.
Two LEDs - Red and Green
5.
One Wire
6.
RPi GPIO T-Cobbler
7.
8" 40 Pin Ribbon Cable for
Raspberry Pi 2
MS
Azure Cloud Service
We
would be creating a very basic Cloud service to activate a circuit. You can
also create the service locally and test it, but objective here is to call Web
API service from Cloud and enable the circuit. Also, the purpose of creating a
web service and hosting it at some other server is to create a service or the
source of data which can be called from any platform or hardware.
Create
a simple Web API service method which will return the value as true
when the system service is called from any client application.
IoTMessageController
exposes a simple get method which returns bool value.
Once
this Web API is created, you can host it to the MS Azure Cloud. We'll be
creating a Python program to call the Web API Service later in this blog.
Circuit
Design
You
can see the T-Cobbler is numbered with some codes. It is very important to
understand the codes and do not disorders with wrong connection as it might
burn the circuit due to wrong connection with the power pins.
Let
us assemble the circuit as per below -
- Attach T-Cobbler to GIPO bread board. Make sure pins are properly fitted into the board
- Fix the 8" 40 pin Ribbon Cable to T-Cobbler
- G23 ( with anode of Resistor)->28 (with cathode of Resistor)
- G18 ( with anode of Resistor)->26 (with cathode of Resistor)
- Connect Black Wire from GND -> -ve section hole. As shown in the figure
- Now we are having two LEDs.
- Connect Green -> anode of LED at 26 hole -> cathod to -ve section hole
- Connect Red -> cathode of LED at 28 hole -> cathode to -ve section hole
Connecting to Raspberry Pi2
Connect
another section of Ribbon Cable to the Raspberry Pi 2 pins, as shown in the
above figure.
Python
Code
The
purpose of writing a code in python is to call service and trigger GIPO circuit
board. Python is easily available in all the platforms. Since we are using
Raspberry Pi Mother board and we have the operating system which is Linux
based, therefore, it become obvious choice to use Python. You can use other
languages as well like C++ to call to the service and read board.
#!/usr/bin/env python2 import urllib2 import urllib import time import RPi.GPIO as GPIO DEBUG = True GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GREEN_LED = 18 RED_LED = 23 GPIO.setup(GREEN_LED, GPIO.OUT) GPIO.setup(RED_LED, GPIO.OUT) if DEBUG: print('Calling Azure Web API') url='http://366bfa6fd6bd44d4846a1a3d44abe2b7.cloudapp.net/api/IoTMeassage' data = urllib2.urlopen(url) info = data.read() if (info == 'true'): GPIO.output(GREEN_LED, True) GPIO.output(RED_LED, False) else: GPIO.output(RED_LED, True) GPIO.output(GREEN_LED, False) time.sleep(20) GPIO.cleanup()
Execute
python program to enable the circuit
Open
the terminal in the Raspberry Pi OS and execute the program by the commands
mentioned in the screen.
When
the service is called, the value is checked for true. In case the value matches
with the condition the Green LED will trigger otherwise Red LED will trigger. I
have added the timer sleep setting as 20 sec which will make the light glow for
20 seconds before cleaning the GPIO circuit board. You can extend your circuit
to do 'N' number of stuff or you can connect it to any other available circuit
boards available in the market to communicate with the application on the
cloud.
Summary
You
have read above about how basic program can be used to trigger GIPO bread
board. Now, you can create your own applications, programs and design circuits
to innovate your ideas. IoT is the next big thing if we understand the power of
collaboration. You can use IoT for automation or get the information from the
circuit/device and load it to your cloud system for the analysis. There is no
limit to the imagination with IoT.