71 Iot
71 Iot
PRACTICAL RECORD
NAME : Ch.Karthik
ROLL NO :19761A1271
YEAR :2022-2023
CERTIFICATE
Certificate that this is a bonafied record of Practical work done in INTERNET
OF THINGS Laboratory by Ch.Karthik with Regd.No 19761A1271 of IV B.
Tech Course (VII Semester) in Information Technology branch during the
academic year 2022-2023
Date: TEACHER-IN-CHARGE
ii
INDEX
S.no Date Experiment Page No.
iii
EXPERIMENT-1
1.Start Raspberry Pi and try various Linux commands in command terminal
windows, cd, touch, mv, rm, man, mkdir, rmdir, tar, gzip, cat, more, less, ps,
sudo, cron, chown, chgrp, ping etc.
ls command - The ls command is used to list files or directories in Linux and
other Unix-based operating systems.
Use the ls command to display a listing of the current directory. Remember that
commands are casesensitive.
IoTLAB@labvm:~$ ls
Use the ls command with the labs argument to display the contents of the labs
folder.
IoTLAB @labvm:~$ ls labs
Use the ls command with the -l option to display a "long display" of the contents
of the current directory. IoTLAB @labvm:~$ ls –l
Use the ls command with the -r option to display the contents of the current
directory in reverse alphabetical order.
IoTLAB @labvm:~$ ls –r
Multiple options can be used at the same time. Use the ls command with both the
-l and -r options to display the contents of the current directory both in long and
reverse order.
IoTLAB @labvm:~$ ls –lr
There are many more options that can be used with the ls command. Use the man
command with the argument ls to see all of the possibilities in the manual. The man
command can be used to look up any command within the system. Use the space
bar to advance to subsequent screens. Press q to quit.
IoTLAB @labvm:~$ man ls
You can also use --help argument after most commands to see a shorter summary of
all the available command options.
IoTLAB @labvm:~$ ls –help
Use the pwd command to display the current working directory.
IoTLAB @labvm:~$ pwd
Use the cd command to change the directory to /home/ IoTLAB
/Documents.
IoTLAB @labvm:~$ cd Documents
Use the cd command with the / symbol to change directories to the root
directory. Use pwd again to see that you are now in the root directory.
IoTLAB @labvm:~/Documents$ cd /
IoTLAB @labvm:/$ pwd /
Use the .. characters to move up a single directory. Use pwd again to see you
are back in the user’s home directory.
IoTLAB @labvm:~/Documents$ cd ..
Use the move files command. a. Use the command mv to move the myfile.sh file
to the desktop.
IoTLAB @labvm:~/Documents$ mv myfile.sh /home/ IoTLAB /Desktop/
Use the copy files command. a. Use the command cp to make a copy of the
myfile_renamed.sh file.
IoTLAB @labvm:~/Documents$ cp myfile_renamed.sh
myfile_renamed_and_copied.sh
Use the sudo command to issue a single command as the root user. A new terminal
will not be created. Use the sudo apt-get update command to update to refresh the list
of available packages installed on the VM. This command will not work without
using the sudo command.
Use the remove files command. Use the rm command to remove the
myfile_renamed_and_copied.sh file. IoTLAB @labvm:~/Documents$ rm
myfile_renamed_and_copied.sh
Use the cat command to view the contents of the linux3.txt file.
IoTLAB @labvm:~$ cat linux3.txt
Use the grep command to filter the contents of the passwd file to display the line
from the passwd file containing IoTLAB. Also notice that the grep command is
case-sensitive.
IoTLAB @labvm:~$ grep IoTLAB /etc/passwd
2
EXPERIMENT-2
Run some python programs on Raspberry Pi like:
A. Read your name and print Hello message with name.
B. Read two numbers and print their sum, difference, product, and
division.
print(num1,ch,num2,": ",res)
word_count =0
char_count =0
str = input("Enter a sentence to count charaters and words")
str_split=str.split()
word_count = len(str_split)
3
EXPERIMENT-3
Run some python programs on Raspberry Pi like:
A. Area of a given shape (rectangle, triangle, and circle) reading shape
and appropriate values from standard input.
shape = input("Enter the name of the shape to calculate Area") area=0
shape=shape.lower() if
shape=="rectangle":
l=int(input("Enter the length of the rectangle"))
b=int(input("Enter the breadth of the rectangle")) area=
l*b
print("Area of the Rectangle is :", area) elif
shape== "triangle":
b=int(input("Enter the breadth of the triangle"))
h=int(input("Enter the height of the triangle"))
area=0.5*b*h
print("Area of the triagle :", area) elif
shape== "circle":
r=int(input("Enter the radius of the circle"))
pi=3.14
area=pi *r*r
print("Area of the circle",area)
else:
print("Sorry! This shape is not availabel")
B. Print a name ‘n’ times, where name and n are read from standard
input, using for and while loops.
name=input("Enter your name")
n=int(input("Enter the value for n to print your name n times")) for i
in range(1,n+1):
print(name)
for i in range(0,10):
print(time.ctime())
time.sleep(5)
4
D. Read a file line by line and print the word count of each line.
word_count =0
file1 = open("/content/sample_data/abc.txt",mode="r")
no_lines=0
len_words=0 for
line in file1:
line=line.strip("\n")
words=line.split() no_lines
+=1
len_words +=len(words)
print("No. of lines in a file", len_words)
5
. EXPERIMENT-4
4 A. Light an LED through Python program.
Aim: Study and Implement LED Lightening using Python program.
Objective: Student should get the knowledge on lightening an LED using
Python program.
Outcome: Student will develop a program to Light an LED using Python
program.
import time
def main():
pinMode(0,IN)
pinMode(1,OUT)
print("Light ON")
while True:
if(digitalRead(0)== HIGH):
digitalWrite(1,HIGH) time.sleep(1)
digitalWrite(1,LOW) time.sleep(1)
if __name__ ==
"__main__": main()
6
4 B. Get input from two switches and switch on corresponding LEDs.
Aim: Study and Implement to get input from two switches and switch on corresponding
LEDs.
Objective: Student should get the knowledge on lightening on
corresponding LED with two switches using Python program.
Outcome: Student will develop a program to Light a LEDs taking input
from two switches using Python program.
import time
def main():
pinMode(0,IN)
pinMode(1,IN)
pinMode(2,OUT)
pinMode(3,OUT)
print("Light ON")
while True:
if(digitalRead(0)== HIGH):
digitalWrite(2,HIGH) time.sleep(1)
digitalWrite(2,LOW)
elif(digitalRead(1)==HIGH):
7
digitalWrite(3,HIGH) time.sleep(1)
digitalWrite(3,LOW)
if __name__ ==
"__main__": main()
8
EXPERIMENT-5
Study and Configure Raspberry Pi.
9
3. Insert your SD card into the computer or laptop’s SD card reader
and make a note of the drive letter allocated to it, e.g. G:/
4. In SD Formatter, select the drive letter for your SD card and format it.
DRAG AND DROP NOOBS FILES
1. Once your SD card has been formatted, drag all the files in the extracted
NOOBS folder and drop them onto the SD card drive.
2. The necessary files will then be transferred to your SD card.
3. When this process has finished, safely remove the SD card and insert it into
your Raspberry Pi.
FIRST BOOT
1. Plug in your keyboard, mouse, and monitor cables.
2. Now plug the USB power cable into your Pi.
3. Your Raspberry Pi will boot, and a window will appear with a list of different
operating systems that you can install. We recommend that you use Raspbian
– tick the box next to Raspbian and click on Install.
4. Raspbian will then run through its installation process. Note that this can
take a while.
5. When the install process has completed, the Raspberry Pi configuration menu
(raspiconfig) will load. Here you are able to set the time and date for your
region, enable a Raspberry Pi camera board, or even create users. You can exit
this menu by using Tab on your keyboard to move to Finish.
10
5 B. Switch on a relay to light an LED through Python program.
import time
from
gpio
impo
rt *
def
main
():
pinMo
de(0,I
N)
pinMo
de(1,O
UT)
pinMo
de(2,O
UT)
pinMo
de(3,O
UT)
print("
Light
11
ON")
while
True:
if(digitalRead(0)== HIGH):
digitalWrite(1,HIG
H) time.sleep(1)
digitalWrite(1,LO
W)
digitalWrite(2,HIG
H) time.sleep(1)
digitalWrite(2,LO
W)
digitalWrite(3,HIG
H) time.sleep(1)
digitalWrite(3,LO
W)
if __name__
==
"__main
__":
main()
12
EXPERIMENT-6
6 A. Access an image through a Pi web cam.
13
Now change the name of webcam IOT0 to WEBCAM and Motion Detector
IOT1 to MOTIONDETECTOR
Now Click on Webcam → Config → IoT Server → Remote Server → Server
Address :- 192.168.1.1 , Username: admin, Password: admin → click on
Connect, --- Wait until it changes to refresh.
Now Click on Motion Detector → Config → IoT Server → Remote Server →
Server Address :- 192.168.1.1 , Username: admin, Password: admin → click
on Connect, --- Wait until it changes to refresh.
Now click on server → Desktop → Browser → type 192.168.1.1 →
Registration Server Login: Username: admin, Password: admin → Sign in
Now you can see the devices WEBCAM and MOTIONDETETOR Listed in
Web browser.
Now click on Conditions → ADD → Name : WEBCAM ON → IF – select
MOTIONDETECTOR → ON → TRUE
THEN SET → WEBCAM → ON → TRUE → Click on OK
Now click on Conditions → ADD → Name : WEBCAM OFF → IF – select
MOTIONDETECTOR → ON → FALSE
THEN SET → WEBCAM → ON → FALSE → Click on OK
Now click on server → Desktop → Browser → type 192.168.1.1 →
Registration Server Login: Username: admin, Password: admin → Sign in
Now Move the Mouse Pointer towards Motion Detector by pressing on ALT
key
You can observe the Webcam on and detecting the object moving towards
motion detector.
Aim: Study and Implement to Control a light source and Fan using web page.
Objective: Student should get the knowledge to Control a light source and
Fan using web page.
Outcome: Student will develop a program to Control a light source and Fan
using web page.
14
Procedure to connect FAN and LIGHT LAMP to Home gateway.
Connect LAMP and the FAN using straight through cable with Ethernet connector.
Click on Home Gateway → Config → Interface→ Wireless →copy SSID :
HomeGateway
Click on SmartPhone → Config → Interface → Wireless → Paste the SSID : change the
default to HomeGateway
Now the Smartphone is connected to Home Gateway.
Click on FAN → Config → change Gateway/DNSIPV4 – DHCP
15
7 A. Motion Detecting Sensor to open the room door and switch on the
light.
Aim: Study and Implement Motion Detecting Sensor to open the room door
and switch on the light.
Objective: Student should get the knowledge on Motion Detecting
Sensor to open the room door and switch on the light using Python
program.
Outcome: Student will develop a program using python to open the room
door and switch on the light when motion is detected in the room.
def main():
pinMode(0,IN)
pinMode(1,OUT)
pinMode(2,OUT)
print("Motion Sensing Started")
while True:
if (digitalRead(0)==HIGH):
digitalWrite(1,HIGH)
customWrite(2,HIGH)
else:
digitalWrite(1,LOW)
customWrite(2,LOW)
time.sleep(1)
if __name__ == "__main__":
main()
16
7 B. Get an Alarm and Sprinkle water if Fire is detected in the room.
Aim: Study and Implement to ring an Alarm and Sprinkle water if Fire is
detected in the room.
Objective: Student should get the knowledge on fire monitoring system and
sprinkle water if fire is detected using Python program.
Outcome: Student will develop a program using python to ring an Alarm and
Sprinkle water if Fire is detected in the room.
def main():
pinMode(0,IN)
pinMode(1,OUT) print("Fire
Alarm System") while True:
fire= digitalRead(0)
if(fire==1023):
customWrite(1,'1')
customWrite(2,"Fire Detected")
customWrite(3,HIGH)
digitalWrite(4,HIGH)
else:
customWrite(1,'0') customWrite(2,"Safe
No Fire Detected") customWrite(3,LOW)
digitalWrite(4,LOW)
print(fire)
if __name__ ==
"__main__": main()
Write a program in the Java script file by deleting the existing code and
add the new code as
function setup()
{
setDeviceProperty(getName(), ‘IR’, 900);
}
18
8 A. Set the siren and open the door if smoke is detected in the room.
19
8 B. Smart Room Temperature Monitoring System.
def main():
pinMode(0,IN)
pinMode(1, OUT)
pinMode(2,OUT)
pinMode(3,OUT)
print("SMART ROOM TEMPERATURE")
while True:
temp=digitalRead(0)
print("Temperature",temp)
if(temp>=520):
digitalWrite(1, HIGH)
digitalWrite(2,LOW)
20
customWrite(3,"AC-ON")
time.sleep(10)
else:
digitalWrite(2, HIGH)
digitalWrite(1,LOW)
customWrite(3,"HEATER-ON")
time.sleep(10)
if __name__ ==
"__main__": main()
21
ADDITIONAL EXPERIMENTS
1. Aim: Study and Implement Installing Django and creating a new Django
Project
Install Django
The commands that we will run in this tutorial will work on both Windows
Command Prompt(CMD) and Powershell. I will use Powershell but you can
CMD if that’s what you prefer.
> python -V
you should see the Python version installed, being printed like below:
PS C:\Users\Stanley> python -V
Python 3.7.4
Step 3 - Upgrade Pip
Python now comes with pip by default. But most of the time, it comes with
an old version. it is always a good practice to upgrade pip to the latest version
22
Step 4 - Create a Project Directory
let’s create a project directory. We will name it django_project since this tutorial
is just a demo but in the real world, the project directory’s name would be
forum, blog, etc.
> cd django_project
Your prompt should now show you that you’re in
the “django_project” directory like below:
PS C:\Users\Username\django_project>
To create a virtual environment, type python -m venv venv and wait for a few
seconds:
23
It will create a directory called venv in the project directory. Next,
> venv\Scripts\activate
When virtualenv is activated, you will see a (venv) at the beginning of the prompt.
(venv)> cd testsite
24
Step 9 - Run the Server
Let’s now run the development server using the manage.py runserver:
25
2. Aim: Study and Implement an intruder system that sends an alert to the
given email.
Objective: Student should get the knowledge to write a Python Program to
implement an intruder system that sends an alert to the given email. Outcome:
Student will implement an intruder system that sends an alert to the given
email.
Also import sleep , so that the button press operation will not be
instantaneous.
Initialize all parameters that are required to send email like from-mail, to-
mail, username,password, subject etc.
Next setup the pin connected to the button, here we used 25 pin for button
pressing
Call the method send email whenever GPIO input is given 25, i.e
whenever the button is pressed the input will be taken as 25 and the
sendemail() method will be called.
In sendemail() method:
the smtp server for creating email is to be provided to create a session for
client and smtp server.
then inorder to send email we require login credentials of sender email and
authentication should be given in gmail settings to accept less secure apps
.
then by using sendmail method we can send mail using python program.
after sending mail inorder to terminate the session between client and smtp
server we use quit() method.
26
when ever if any keyboardInterrupt occurs then raise an exception
to exit() the program
Source Code:
import smtplib
from_email=’<my-email>’
receipients_list=[‘<receipient-email>’]
cc_list=[]
subject=’Hello’
username=’<Gmail-username>’
password=’<Password>’
server=’smtp.gmail.com:587’
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)
Message= header+message
Server=smtplib.SMTP(smtpserver) Server.startls()
Server.login(login, password)
Problem=server.sendmail(from_addr,to_addr_list,message)
27
Server.quit()
While True:
Try:
If(GPIO.input(25)==True):
Sendemail(from_email,receipients_list,cc_list,subject,
message,username,password,server)
Sleep(.01)
28