JNTUA IoT TextDoc

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 11

DAY - 1:

0. Getting Started with RPi


Connect USB Keyboard @ RPi USB
Connect USB Mouse @ RPi USB
Connect DB15 to HDMI Connector
Connect micro USB Cable for Power

1. Configuring the Keyboard


Open Lx Terminal
(Type) sudo nano /etc/default/keyboard (enter)
In the place of gb with us
ctrl + x and then press 'y' enter
sudo reboot (enter)

2. Configuring Internet (Wi-Fi):


Open Lx Terminal
sudo nano /etc/network/interfaces (enter)

iface wlan0 inet dhcp (enter)


wpa-ssid "JNTUAWIFI" (enter)
wpa-psk "jntua@wifi" (enter)
#
ctrl +x and press y (enter)
sudo ifdown wlan0 (enter)
sudo ifup wlan0 (enter)
ping www.google.com (enter)
ctrl + c is a keyboard interrupt
sudo reboot (enter)

3. Updating your OS
Open Lx Terminal
sudo apt-get update (enter)

4.
Interfacing Generic Board with GPIO
+side to Pin2 (5V)
-side to Pin6 (GND)
Button and LED - Power Connection
5.
Creating a Python Script
Open Lx Terminal
mkdir iot (enter)
ls (enter)
cd iot (enter)
sudo nano demo.py (enter)
print 'Hello World, Im at JNTUA'
ctrl +x and press y enter

6. Execute a Python Script


sudo python demo.py (enter)

That's it.
Shutdown your Raspberry Pi
by running sudo halt (Enter).
End of Day - 1. ThanQ.
Tomorrow be here by 9.00AM.

DAY - 2:
Good Morning.
Welcome Back.
Switch on the Raspberry Pi.

Open Lx Terminal
cd iot (enter)
7. Interfacing LED at RPi
Hardware Connections:
Connect Generic Board
+ Side - Pin 2 (5V)
- Side - Pin 6 (GND)
LED connected @ GPIO2 (3) of RPi
Software Program:
sudo nano led.py (enter)
import RPi.GPIO as m
m.setmode(m.BCM)
m.setup(2,m.OUT)
m.output(2,m.HIGH)

ctrl + x and press y, and press enter


sudo python led.py (enter)
Analysis:
LED - OFF STATE - HIGH
LED - ON STATE - LOW
8. Blinking LED
Let Hardware be remain same
sudo nano ledblink.py
import RPi.GPIO as m
import time

m.setmode(m.BCM)
m.setup(2,m.OUT)
while (True):
m.output(2,m.LOW)
time.sleep(0.1)
m.output(2,m.HIGH)
time.sleep(0.1)

ctrl + x, press y and press enter


To execute,
sudo python ledblink.py (enter)
press ctrl + c - keyboard interrupt
until it comes back to pi@raspberry

9. Switching LED
Reading Data from Input Peri.

Hardware Connections
LED - GPIO2 (3) of RPi
BUTTON - GPIO3 (5) of RPi

Software Program:
sudo nano button.py (enter)
import RPi.GPIO as m
import time
m.setmode(m.BCM)
m.setup(2,m.OUT)
m.setup(3,m.IN)
sFlag=0
while (True):
if(m.input(3)==0 and sFlag==1):
sFlag=0
print ('Button Pressed')
m.output(2,m.LOW)
elif(m.input(3)==1 and sFlag==0):
m.output(2,m.HIGH)
print ('Button Released')
sFlag=1
(ctrl + x, press y and enter)
To execute,
sudo python button.py (enter)

Break for 10 Minutes.


ThanQ.
Welcome Back.

10. Interfacing Light Sensor


LDR Sensor - Light Dependent
Light Intensity is High
make LED off

Hardware Connections
Light Sensor Connections:

VCC connected to +side of GB


GND connected to -side of GB
DO connected GPIO4 (7) of RPi
AO is no connection

Software Program:
sudo nano ldr.py (enter)
import RPi.GPIO as m
m.setmode(m.BCM)
m.setup(4,m.IN)
m.setup(2,m.OUT)

while (True):
if(m.input(4)==0):
print ('HIGH Light')
m.output(2,m.HIGH)
else:
print ('Bad Light')
m.output(2,m.LOW)

ctrl +x, press y and enter


To execute,
sudo python ldr.py (enter)

11.
Create an account in
www.way2sms.com
with your mobile number

12.
Sending SMS through Python
sudo nano way2sms.py (enter)
import urllib2
t=urllib2.urlopen('http://www.orangeresearchlabs.com/aquasoul/sms/index.php?
user=7799204041&pass=xxxx&to=9396553329&msg=Test SMS')
print(t)

ctrl + x, press y and press enter


To execute
sudo python way2sms.py (enter)

13.
Interfacing Air Quality Sensor
Hardware Connections:
VCC to + side
GND to - side
DO to GPIO6 (31)
AO is No Connection

Software Program:
sudo nano mq.py
import RPi.GPIO as m
import time
m.setmode(m.BCM)
m.setup(6,m.IN)
m.setup(2,m.OUT)
while True:
if(m.input(6)==0):
print ('Air Content is High')
m.output(2,m.HIGH)
time.sleep(2)
else:
print ('Normal')
m.output(2,m.LOW)
time.sleep(2)

ctrl +x, press y and enter


To execute,
sudo python mq.py (enter)

14.
Interfacing Proximity Sensor

Hardware Connections:
5V/VCC to + side
GND to - side
Output to GPIO7 (26) of RPi

Software Program:
sudo nano ir.py (enter)
import RPi.GPIO as m
import time

m.setmode(m.BCM)
m.setup(2,m.OUT)
m.setup(7, m.IN)
while True:
if(m.input(7)==1):
print 'Obstacle Detected'
m.output(2,m.LOW)
time.sleep(2)
else:
m.output(2,m.HIGH)
ctrl +x , press y and enter
To execute,
sudo python ir.py (enter)

15.
Update the Python Package
sudo apt-get install python-dev (enter)
press y to continue (if it asks)

16. Update the Build Package


sudo apt-get install build-essential
(enter)
press y to continue (if it asks)

17. Download Package of DHT11


wget http://tinyurl.com/UILDHT11
(enter)
ls (enter)
unzip UILDHT11 (enter)
ls (enter)
cd UIL_Python_DHT (enter)
ls (enter)
sudo python setup.py install (enter)
cd .. (enter)
sudo halt (enter)

Lets go for lunch.


Come back by 2.00PM.
Welcome Back.
Very Good Afternoon.
Switch on your Raspberry Pi
Open Lx Terminal
cd iot (enter)
18.
Hardware Connections:
DHT11 - Humidity and Temp Sensor
VCC is connected to + side
GND is connected to - side
DATA is connected to GPIO7 (26)
sudo nano temp.py (enter)
import UIL_DHT as DHT
import time

while True:
t=DHT.read_retry(DHT.DHT11,7)
humi=str(t[0])
temp=str(t[1])
time.sleep(2)
print("Humidity: " + humi)
print("Temperature: " + temp)
ctrl +x, y and press enter
To execute,
sudo python temp.py (enter)
19.
log on to www.thingspeak.com
Create an account in Mathworks
Create an account in ThingSpeak
Login in to ThingSpeak
20. Uploading data to TS
sudo nano sUpload.py
import UIL_DHT as DHT
import urllib2 as URL
import time

while True:
t=DHT.read_retry(DHT.DHT11,7)
humi=str(t[0])
temp=str(t[1])
k=URL.urlopen('https:// ....... field1='+humi+'&field2='+temp)
print(k)
time.sleep(2)

ctrl +x, press y and enter


To execute,
sudo python sUpload.py (enter)

21. Reading Data from Cloud (TS)


sudo nano sRead.py (enter)
import urllib2 as URL
import time

while True:
k=URL.urlopen ('https://api.thingspeak.com/channels/142287/fields/1.json?
results=1').read()
k1=k.split('"')
print(k1[-2])
time.sleep(2)
ctrl +x, y and press enter
To execute,
sudo python sRead.py (enter)

Let's have a break for 10 min.


22.
Web Controlled LED
through Socket
sudo nano tServer.py (enter)
import socket
import RPi.GPIO as m
m.setmode(m.BCM)
m.setup(2,m.OUT)
s=socket.socket()
s.bind(('10.66.70.81',12345))
s.listen(5)

while True:
c,addr=s.accept()
print ('Got connection from ', addr)
t=c.recv(1024)
k=t.split('\n')
k1=k[0]
k1=k1.split(' ')
k1=k1[1][1:]
print(k1)
if(k1=='ledon'):
m.output(2,m.LOW)
elif(k1=='ledoff'):
m.output(2,m.HIGH)
c.send('Thank You')
ctrl +x , press y and enter

@ Client Side
Open Browser
http://ip_addr_server:port_num/ledon
http://ip_add_server:port_num/ledoff

That's it.
End of Day - 2.
ThanQ.
Be tomorrow here by 9.30AM

DAY - 3:
Welcome Back.
Very Good Morning.
Switch on the Raspberry Pi
23.
Touch Me Not.
If you try,
I'll intimate owner
Connect Raspberry Pi to
your own Mobile
Hotspot
So, thereby configure your RPi
sudo nano /etc/network/interfaces
In the place of JNTUAWIFI,
change it to your username
In the place of password,
change it to your password

ctrl + x, press y and enter


sudo ifdown wlan0 (enter)
sudo ifup wlan0 (enter)
RPi will be connected to
your Mobile Hotspot

Open Lx Terminal
cd iot (enter)
Touch Me Not - Use Case
Input: IR Proximity Sensor
Output: Intimating to the owner
Connect Generic Board to RPi
+ side to Pin 2 (VCC)
- side to Pin 6 (GND)
Proximity Sensor (3 Pin)
VCC to + side on GB
GND to - side on GB
DATA (OUT) to GPIO2 (3) of RPi
sudo nano sms.py
import urllib2 as URL

def send(o_mob,o_msg):
print 'Sending Sms'
t=URL.urlopen('http://www.orangeresearchlabs.com/aquasoul/sms/index.php?
user=7799204041&pass=XXXX&to='+str(o_mob)+'&msg='+str(o_msg))
print(t)
print('Sms Sent')
ctrl +x , press y and enter
To execute
sudo python sms.py (enter)

sudo nano touch.py


import RPi.GPIO as m
import sms
import time

m.setmode(m.BCM)
m.setup(2,m.IN)

while True:
if(m.input(2)==1):
print 'Someone is trying to touch'
sms.send('9396553329','OBJECTALERT4mRPI')
time.sleep(5)

24.
A family went to kulu-manali for a summer trip, no one is there at home. But,
Raspberry Pi dog is monitoring the house with internet connectivity. A thief
entered into the house, the RPi has to alert the owner, and cyber security cell
through e-mail along with gps coordinates.

Security Settings for a gmail account should be disabled properly.


Gmail Server will send an e-mail about this instinct.

Break for 10 mins.


Thanq.
Welcome Back.
Open Lx Terminal
wget http://www.orangeresearchlabs.com/SEND.zip (enter)
ls (enter)
unzip SEND.zip (enter)
ls (enter)
sudo nano SEND.py (enter)
change fromaddr with your e-mail id
change username with your username
change password with your password

ctrl + x, press y and enter

Find out the GPS coordinates of JNTUA, as the system is located here

Lt: 14.6496526, N
Lg: 77.6044158, E

Write down on your notes so that you can paste it when it is required

sudo nano Rdog.py (enter)


import SEND
import RPi.GPIO as m
import time

m.setmode(m.BCM)
m.setup(2,m.IN)
lt='14.6496526, N'
lg='77.6044158, E'
while True:
if(m.input(2)==0):
k='Theft Detected @ Latitude: ' + str(lt) + ', Longitude: ' + str(lg)
print(k)
SEND.send_email('madhu@orangeresearchlabs.com', str(k))
time.sleep(10)

25.
E-Mail Based Home Automation
Electrical appliances should be controlled by sending an email from your account.
For example, to make led on you have to send an email with subject 'LED ON'.

New e-mail arrived to your inbox will be unread and the status is 'UNREAD'. - This
is the logic

wget http://www.orangeresearchlabs.com/ORL.zip (enter)


ls (enter)
unzip ORL.zip (enter)
ls (enter)
sudo nano ORL.py (enter)
change the login credentials in mail.login (username and password)
ctrl +x, press y and enter

sudo nano ahome.py (enter)


import ORL
import time
import RPi.GPIO as m

m.setmode(m.BCM)
m.setup(2,m.OUT)
while True:
t=ORL.mail_check()
print(t)
time.sleep(2)
if(t[1]=='LED ON'):
print 'LED ON'
m.output(2,m.LOW)
elif(t[1]=='LED OFF'):
print 'LED OFF'
m.output(2,m.HIGH)
ctrl + x, y and press enter
To execute,
sudo python ahome.py

Switch to JNTUAWIFI
and you can have a break
Come back by 1.50PM.
Thanq.

Welcome Back.
Last Session of our Workshop
Very Good Afternoon.

26.

How multiple devices communicate over socket?

Gateway - IoT Cloud (TS) - Server


Endpoint (End Device) - DHT11
Endpoint Python Script
sudo nano cGateway.py (enter)
import UIL_DHT as DHT
import time
import socket
s=socket.socket()
s.connect(('192.168.1.1',12345))
t=DHT.read_retry(DHT.DHT11,7)
s.send(str(t))
print(s.recv(1024))
s.close()
ctrl + x, press y and enter
Gateway Python Script
sudo nano sGateway.py (enter)
import urllib2 as URL
import socket
import time

s=socket.socket()
s.bind(('localhost',12345))
s.listen(5)
while True:
c, addr = s.accept()
print 'Got connection from', addr
k=c.recv(1024) # (23.0,35.0)
k=k.split(',') # [(23.0, 35.0)]
humi=k[0][1:] # 23.0
temp=k[1][:-1] # 35.0
print(humi,temp)
kk=URL.urlopen('http://api.thingspeak.com/update.......... &field1=' +
str(humi) + '&field2=' + str(temp))
print(kk)
c.send("Thank You, I'll process your request")
ctrl + x, press y and enter

Let's have a break for 10 min.


Assemble back ASAP.
Welcome Back.

27.
MQTT Protocol
Message Queue Telemetry
Transport Leading IoT Protocol
Social Networking Gaints
like Facebook, Twitter,
Youtube are even using this
protocol
Publisher - Publishing a message
Subscriber - Subscribes to a topic
Broker - Conn. both pub and sub
Publisher - can be any device
Subscriber - can be any device
Broker - Cloud Server
Eclipse Foundation
Less Weight Protocol
Weight starts from single char to a big sentence of having 1024 char
Open Source Protocol
Open Source Broker
- iot.eclipse.org 1883

IBM's Node RED Package


javascript (.js) - Node.js
Web Server operates in port number
1880
If you have any queries,
you can mail me on
madhu@orangeresearchlabs.com Signing off.
If you have any ideas,
for validation. You can reach us
THANK YOU.

You might also like