You are on page 1of 42

Mahavir Education Trust's

Shah & Anchor Kutchhi Engineering College,


Chembur, Mumbai 400 088
UG Program in Electronics Engineering

IoT LAB
MANUAL

BY
Shriniwas Ghadyalji
BE – 2 – A
Batch Roll No. 04
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment
No.1 Aim: Data Handling and storage
Temperature, Humidity data upload on Thingspeak on Arduino IDE
Title : to store and upload the weather data using DHT11 temperature and humidity sensor on
cloud ( ThingSpeak.com) using wifi modem NodeMCU.
Hardware: NodeMCU, DHT11 Temperature and Humidity sensor, Jumper Male to female

Introduction:
This experiment is used to log weather data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor DHT11 will be used to measure temperature and humidity data using
NodeMCU on Arduino IDE.

Libraries need to be added

1.Arduino Preferences :http://arduino.esp8266.com/stable/package_esp8266com_index.json

2.dht.h in arduino liabrary

Building Circuit

Make connection as mentioned below


Sr.No. NodeMCUDHT11

1. Vin VCC

2. GND GND

3. D3 Data Out
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Circuit Layout:

Getting API Key from Thingspeak:


1. Go to https://thingspeak.com/ and create an account if you do not have one. Login to
your account.

2. Create a new channel by clicking on the button. Enter basic details of the channel. Then Scroll
down and save the channel.

3. Channel Id is the identity of your channel. Note down this. Then go to API keys copy
and paste this key to a separate notepad file will need it later.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

4. Programming:
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run
this circuit on NodeMCU.

#include <dht.h>
#define dht_apin D3 // Analog Pin sensor is connected to
#include <ESP8266WiFi.h>
dht DHT;

String apiKey = "PXD7RW20JROFFJUL"; // Enter your Write API key from


ThingSpeak const char *ssid = "wifi ssid"; // replace with your wifi ssid and wpa2 key
const char *pass = "wifi password";
const char* server = "api.thingspeak.com";
WiFiClient client;

void setup()
{ Serial.begin(115200);
delay(10);
Serial.println("Connecting to
"); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{ delay(500);
Serial.print(".")
;
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{
DHT.read11(dht_apin);
float h = DHT.humidity;
float t = DHT.temperature;
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(3000);//Wait 3 seconds before accessing sensor again.
if (isnan(h) || isnan(t))
{
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Serial.println("Failed to read from DHT sensor!");
return;
}
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, set it to 30 seconds
delay(10000);
}
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.1 Describe functional blocks of IOT.

Device: An IoT system comprises of devices that provide sensing, actuation, monitoring and control
functions.
Communication: The communication block handles the communication for the IoT system.
Services: An IoT system uses various types of IoT services such as services for device monitoring,
device control services, data publishing services and services for device directory.
Management: Management functional block provides various functions to govern the IoT system.
Security: Security functional block secures the IoT systems and by providing functions such as
authentication, authorisation, message and content integrity and data security.
Application: IoT applications provide an interface that the users can use to control and monitor
various aspects of the IoT system. Applications also allow users to view the system status and view or
analyse the processed data.

Q.2 Explain wireless sensor technology.

A Wireless Sensor Technology comprises of distributed devices with sensors which are used to monitor
the environmental and physical conditions. A WSN consist of number of end-nodes and routers and a
coordinator. End nodes have several sensors attached to them. End nodes can also act as routers. Routers
are responsible for routing the data packets from end nodes to the coordinator. The coordinator collects
the data from all the nodes. Coordinator also acts as a gateway that connects the WSN to the internet.
A Wireless Sensor Technology comprises of distributed devices with sensors which are used to monitor
the environmental and physical conditions. A WSN consist of number of end-nodes and routers and a
coordinator. End nodes have several sensors attached to them. End nodes can also act as routers. Routers
are responsible for routing the data packets from end nodes to the coordinator. The coordinator collects
the data from all the nodes. Coordinator also acts as a gateway that connects the WSN to the internet.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Experiment No.2
Aim: Data Handling and storage
Gas Level Monitoring Over Internet Using NodeMCU and & Gas Sensor on Thingspeak
on Arduino IDE
Title : To monitor pollution on thingspeak using Node MCU and MQ135sensor on cloud
( ThingSpeak.com) using wifi modem NodeMCU.
Hardware: NodeMCU, MQ135sensor, Jumper Male to female

Introduction:
This experiment is used to log pollution data on cloud. ThingSpeak.com is to be used as cloud
service provider and sensor MQ135 will be used to detect and identify different types of gasses
data .

Libraries need to be added

1.Arduino Preferences :http://arduino.esp8266.com/stable/package_esp8266com_index.json

MQ135:

The MQ-135 gas sensor senses the gases like ammonia nitrogen, oxygen, alcohols,
aromatic compounds, sulfide and smoke. The MQ-3 gas sensor has a lower conductivity to clean
the air as a gas sensing material. In the atmosphere we can find polluting gases, but the
conductivity of gas sensor increases as the concentration of polluting gas increases. MQ-135 gas
sensor can be implementation to detect the smoke, benzene, steam and other harmful gases. It
has potential to detect different harmful gases. It is with low cost and particularly suitable for Air
quality monitoring application.

The MQ135 sensor is a signal output indicator instruction. It has two outputs: analog
output and TTL output. The TTL output is low signal light which can be accessed through the IO
ports on the Microcontroller. The analog output is an concentration, i.e. increasing voltage is
directly proportional to increasing concentration. This sensor has a long life and reliable stability
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
as well
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering

Features
• High Sensitivity

• High sensitivity to Ammonia, Sulfide and Benze

• Stable and Long Life

• Detection Range: 10 – 300 ppm NH3, 10 – 1000 ppm Benzene, 10 – 300 Alcohol

• Heater Voltage: 5.0V

• Dimensions: 18mm Diameter, 17mm High excluding pins, Pins – 6mm High

• Long life and low cost

Building Circuit

Make connection as mentioned below


Sr.No. NodeMCU MQ135

1. Vin VCC

2. GND GND

3. A0 A0

Circuit Layout:
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Getting API Key from Thingspeak:


1. Go to https://thingspeak.com/ and create an account if you do not have one. Login to
your account.

2. Create a new channel by clicking on the button.Enter basic details of the channel.Than
Scroll down and save the channel.

3. Channel Id is the identity of your channel. Note down this. Than go to API keys copy
and paste this key to a separate notepad file will need it later.

4. Programming:
#include <ESP8266WiFi.h>
String apiKey = "9OIFHW3MDEDJC7ZL"; // Enter your Write API key from ThingSpeak
const char *ssid = "SK"; // replace with your wifi ssid and wpa2 key
const char *pass = "12345678";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Connecting to
"); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
}

void loop()
{
float p = analogRead(A0);
if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(p);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Polution: ");
Serial.println(p);
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(1000);
}
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.1 Compare MQTT and COAP protocol


Features CoAP MQTT

Full Form Constrained Application Message Queue Telemetry


Protocol Transport

Model used Request-Response, Publish-Subscribe


for Publish-
communicatio Subscribe
n
RESTful Yes No

Transport layer Preferably UDP, TCP can Preferably TCP, UDP


also be used. can also be used
(MQTT-S).
Header Size 4 Bytes 2 Bytes

Number of 4 16
messag
e types
used

Messaging Asynchronous & Asynchronous


Synchronous

Applicati 2 Levels 3 Levels


on
Reliabil
ity
Security IPSEC or DTLS Not defined in the standard

Intermediaries YES YES (MQTT-S)

LLN Suitability Excellent Fair


(thousand
nodes)
Application Utility Field Area Networks Extending
success enterprise
stories messaging
into IoT
applications
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.2 Explain IOT level 5 and 6

Level 5: A level – 5 IoT system has multiple end nodes and one coordinator node. The
end nodes perform sensing and/or actuation. The coordinator node collects data from the
end nodes and sends it to the cloud. Data analyzed in the cloud and the application is
cloud-based. Level – 5 IoT systems are suitable for solutions based on wireless sensor
networks, in which the data involved is big and the analysis requirements are
computationally intensive.

Level 6: A level-6 IoT system has multiple independent end nodes that perform sensing
and/or actuation and send data to the cloud. Data is stored in the cloud and the application
is cloud-based. The analytics component analyses the data and stores the results in the
cloud database. The results are visualized with the cloud-based applications. The
centralized controller is aware of the status of all the end nodes and sends control
commands to the nodes.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Experiment No.3

Aim: To control relay using Blynk App and 802.11protocol (WIFI)

Title : To control relay for electrical appliances using blynk app and wifi modem NodeMCU.

Hardware: NodeMCU, relay, relay driver, LED bank load

Introduction:
This experiment is used to control the relay through blink cloud using node mcu and wifi. In
blynk cloud we have to make one account for your cloud.

Blynk app for iOS and Android is the easiest way to build your own mobile app that work with
the hardware of your choice. No iOS or Android coding required. We also required blynk
libraries to run this experiment. Blynk Library is an extension that runs on top of your hardware
application. It handles all the connection routines and data exchange between your hardware,
Blynk Cloud, and your app project.

Libraries need to be added

1. Arduino Preferences :http://arduino.esp8266.com/stable/package_esp8266com_index.json

2. Blynk_Release_v0.5.4 arduino liabrary

Building Circuit

Make connection as mentioned below


Sr.No. NodeMCU RELAY

1. Vin VCC

2. GND GND

3. D1 Relay
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Circuit Layout:

STEP 1
Configure the Blynk app.
Download the Blynk app from playstore for Andriod devices.

STEP 2
Sign up with your email and password.

STEP 3
Creat a new project. The steps are given below:
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
STEP 4
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Add widgets to the app as required, in this experiment we are going to control one device.
So need 1 switches. Drag and drop it for your imagination.

STEP 5
Change the logic from 0-1 to 1-0 because the output of NodeMCU is active LOW. Select
digital pins D1 as output pins. change mode to switch from push.

STEP 6
Select the device you are going to communicate, which is the NodeMCU.
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
STEP 7
College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Send the authentication code to your e-mail.

STEP 8
Set up the circuit as per the schematics.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

STEP 9
Open Arduino IDE.
Configure it for NodeMCU.

STEP 10
Write the code and upload it in node mcu.
Execute it.

Programming:
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run
this circuit on NodeMCU.

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[ ] = "authtocken"; // PASTE YOUR AUTHENTICATION CODE HERE
// Your WiFi credentials.
char ssid[ ] = "ssid"; //WIFI NAME
char pass[ ] = "password"; //PASSWORD
void setup( )
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.1 List all communication protocols.

i. HTTP
ii. CoAP
iii. WebSocket
iv. MQTT
v. XMPP
vi. DDS
vii. AMQP

Q.2 List all sensor data communication protocols

A serial interfaces uses a protocol for serial communication. A microcontroller includes interfaces for
serial communication. UART and several other protocols are popularly used. Wired communication can
be:
• Serial asynchronous communication, such as, using UART communication. A RFID reader uses a
125kHz RFID UART module. A GPS device also sends serial data using UART.
• Synchronous serial-communication devices, such as sensors which can communicate serial data using
I2C or SPI interfaces in wired bus communication.
Automotive sensors communicate serial data using LIN, CAN, MOST, IEEE 1394 serial protocols.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Experiments No.4

Aim : To implement MQTT protocol


Title : To implement MQTT protocol using Raspberry Pi for local network
Hardware: Raspberry pi, Python

Introduction:
MQTT is a publish-subscribe-based messaging protocol used in the internet of Things. ...
The goal is to provide a protocol, which is bandwidth-efficient and uses little battery power.
MQTT is a messaging protocol i.e it was designed for transferring messages, and uses a publish
and subscribe model. This model makes it possible to send messages to 0,1 or multiple clients. ...
In MQTT a publisher publishes messages on a topic and a subscriber must subscribe to that topic
to view the message.

What is the difference between MQTT and HTTP?


MQTT is data centric whereas HTTP is document-centric. HTTP is request-response
protocol for client-server computing and not always optimized for mobile devices. Besides,
publish/subscribe model provides clients with independent existence from one another and
enhance the reliability of the whole system
MQTT Brokers, Publishers & Subscribers
In a nutshell, MQTT consists of publishers and subscribers, and they’re all connected
through a broker.The terminology can be confusing, but if you translate it into client-server
notation, it’s this simple:-the broker is the serverthe publishers and subscribers are the clients.
Mahavir Education
Trust's
Shah & Anchor
Kutchhi
Engineering
Procedure: College,
Chembur, Mumbai
400 088
UG Program in
Electronics
Engineering
Building a Raspberry Pi MQTT Broker
● First you need a Raspberry Pi with a recent version of Raspbian or Raspbian Lite
installed.
● GUI installation, just open Terminal and follow the instructions.
1. Install the mosquitto MQTT Broker
mosquitto is a popular MQTT broker that is well-supported on Debian-based
Linux platforms such as Raspbian. It’s easy to install using apt:-
sudo apt install mosquitto mosquitto-clients
You’ll need to enter your password the first time you run sudo.
You don’t strictly need the mosquitto-clients package for running the broker, but
installing it allows you to run the MQTT client code locally which is great for testing.
It also means you can use the Raspberry Pi as a proper MQTT client as well as
a broker. This means you could, for example, add a user interface to control other
MQTT clients around your home directly from the Raspberry Pi.
2. Enable the mosquitto broker
Enable the broker and allow it to auto-start after reboot using the following
command:-
sudo systemctl enable mosquitto
The broker should now be running. You can confirm by checking the systemd service
status:-
sudo systemctl status mosquito
This should produce an output similar to:-
(note:use CTL+C to come out from ruuning status)
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
The great thing about MQTT is that you can just make up topics to suit your needs. You
don’t need to register them anywhere. For the sake of this test, you can use a topic
called test/message.
In the existing terminal, subscribe to the test/message topic:-
mosquitto_sub –d -t test

This will send a subscription message to the MQTT broker which is currently running on
the same system. But it could be running somewhere else, as you’ll see later.
So long as the mosquitto_sub programme is running you’re listening to
the test/message topic as an MQTT client.
4. Publish to the MQTT Topic Locally
Because your current terminal is occupied listening to the topic, you’ll need to open
another terminal. You can do this using another SSH session or on the Raspbian GUI,
depending how your system is configured.
Once open, publish message to the test topic like this:-
mosquitto_pub –d -t test -m "Hello, world"

If you look back at the first terminal now you should see this:-
Hello, world

Testing from a Different Machine:


That’s all very well, but it’s not that useful. The real power of MQTT becomes
apparent when you see how easy it is to communicate between different machines.
To demonstrate how you can send and receive MQTT messages from devices
such as the ESP8266 or other rpi, which is ideal for home automation.
But first it’s useful to learn how to send and receive messages via your Raspberry
Pi broker from another computer on the network. This is the ideal test environment
because it’s real enough in that the client is a separate machine from the Raspberry Pi,
and because it’s a computer rather than an embedded system it’s convenient for testing
and debugging.
5. Select a Test Machine
There are plenty of different MQTT clients out there but use only mosquitto for
testing. It has the advantage of being able to run on pretty much everything.
6. Install the MQTT Client Package
Installing mosquitto MQTT Client on Linux
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Assuming you’re running on Linux, including a virtual Linux machine, you can install
the mosquitto client code using:-
Apt get update
sudo apt install mosquitto-clients
If your installation doesn’t yet support apt, replace it with apt-get.
Identify the Raspberry Pi on the Network
The MQTT client doesn’t need to know very much about the broker, but
it does need to know where it is on the network. The MQTT client code needs a hostname
or an IP address whenever you subscribe to or publish a message.
If your Raspberry Pi has a unique name on your network, it makes sense to use
that. Find the host name on the Pi by typing:-
hostname
If yours is left at the default it will return:-
raspberrypi
Alternatively, you can always use the Raspberry Pi’s IP address in place of the
hostname. An easy way to get this is by running:-
ifconfig | grep inet | grep cast
Subscribe to the Topic Remotely
On the test machine, there’s no need to run a server since it’s already running on
the Raspberry Pi.
You can just subscribe to the test message like this:-
mosquitto_sub -h raspberrypi -t test
If your Raspberry Pi’s hostname is different, substitute it in place
of raspberrypi in the above command. You can also use the IP address directly if you
prefer:-
mosquitto_sub -h 192.168.0.25 -t test
This will now cause the terminal to wait for messages from the broker on the
topic test/message.
Publish a Test Message Remotely
As before, you can now open another terminal window and type:-
mosquitto_pub -h raspberrypi -t test -m "Hello from remote"
or
mosquitto_pub -h raspberrypi -t test -m "Hello from remote"
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Again, substitute your hostname or IP address as appropriate.


Now you should a message see in the first terminal window:-
Hello from remote
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.1 Explain process and domain model of IoT.

The IoT-A project defines a domain model as a description of


concepts belonging to a particular area of interest. The domain
model also defines basic attributes of these concepts, such as name
and identifier. Furthermore, the domain model defines relationships
between concepts. The main purpose of a domain model is to
generate a common understanding of the target domain in question.
Such a common understanding is important, not just project-
internally, but also for the scientific discourse. Only with a common
understanding of the main concepts it becomes possible to argue
about architectural solutions and to evaluate them. The domain
model is an important part of any reference model since it includes a
definition of the main abstract concepts (abstractions), their
responsibilities, and their relationships.

Q.2 Explain IP addressing in IoT

An IP header consists of source and destination addresses, called IP address. The Internet generally uses
IPv4 addresses. IoT/M2M use IPv6 address.
IP version 4 address consists of 32 bits. However, it can be considered as four decimal numbers
separated by dots. Ranges from 0.0.0.0 to 255.255.255.255.
Devices (nodes) in IoT need large number of addresses. IP version 6 uses 128 bit address. A
hexadecimal digit represents 4-bit, 0 hex = 0000 binary to hex = 1111. Therefore, 128 bit address has 32
hexadecimal digits.
IPv6 addresses are classified into three classes. Unicast address is for a single network interface.
Anycast address means address for a group of nodes or interfaces. Multicast address means an address
used by multiple hosts, which acquires the multicast address destination by participating in the multicast
distribution protocol among network routers.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Experiment No.6
Aim: To capture image and send image through email using Raspberry Pi

Title : To capture the image from Raspberry pi camera and send image through the email using
Raspberry pi and python.

Hardware: Raspberry Pi 3 with OS installed in memory card, Raspberry pi camera.

Software: Python, Putty, VNC

Circuit Diagram – Experimental setup

Introduction:
This experiment is used to capture image from raspberry pi camera. The image is stored in Rpi
and the it is send as attachment through the email.

Raspberry Pi Camera:
This package provides a pure Python interface to the Raspberry Pi Camera module for
Python 2.7 (or above) or Python 3.2 (or above).
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Steps to execute the practical


Step 1
First, the Raspberry Pi must be connected to your desktop. Then, connect your wi-fi on
your Pi or connect your ethernet. After that, open the terminal of your Operating System using
the following code.
hostname -I
Next, open PuTTY or VNC software and paste the Host Name (or IP Address) on this
PuTTY.

After that, open the terminal box and enter your default PI name and password.
Username (pi)
Password (raspberry)
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Step 2
Next, we need to update the Raspberry Pi. So, install the latest packages. You can do that
using the following commands.
sudo apt-get update
sudo apt-get upgrade
or
sudo apt-get update && upgrade
If you want to install Python 3.0
sudo apt-get install python3
Install an SMTP service
sudo apt-get install ssmtp
Configure the SMTP
sudo nano /etc/ssmtp/ssmtp.conf

Step 3
Next, you need to enable the permissions and options like SSH and Camera. So, go to
Raspberry Pi configuration.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Step 4
Open the Python IDE 2.7 or above 3.2, create a new file and save it as camera.py. It’s
important that you do not save it as picamera.py
Write the Camera testing code as given below.
1. from picamera import PiCamera
2. from time import sleep
3. camera = PiCamera()
4. camera.start_preview()
5. sleep(05)
6. camera.stop_preview()
Save with Ctrl + S and run with F5. The camera preview should be shown for 05 seconds,
and then close.
or
Run the program.
sudo python camera.py
Note: Allowing Gmail SMTP Access for Accounts with Standard Authentication
o To allow access to Gmail’s SMTP server from your app, you can follow
these steps,
o Login to your Gmail account using your username and password.
o From the top right corner go to “My Account“.
o Under “Sign-in & security” section locate “Connected apps & sites” and click on
it.
o Locate “Allow less secure apps” setting and turn it “On“.
Code:

1. import smtplib,ssl
2. from picamera import PiCamera
3. from time import sleep
4. from email.mime.multipart import MIMEMultipart
5. from email.mime.base import MIMEBase
6. from email.mime.text import MIMEText
7. from email.utils import formatdate
8. from email import encoders
9.
10. camera = PiCamera()
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
11.
12. camera.start_preview()
13. sleep(5)
14. camera.capture('/home/pi/image.jpg') # image path set
15. sleep(5)
16. camera.stop_preview()
17. def send_an_email():
18. toaddr = 'raviraw299@gmail.com' # To id
19. me = 'raviraw299@gmail.com' # your id
20. subject = "What's News" # Subject
21.
22. msg = MIMEMultipart()
23. msg['Subject'] = subject
24. msg['From'] = me
25. msg['To'] = toaddr
26. msg.preamble = "test "
27. #msg.attach(MIMEText(text)) 28.
29. part = MIMEBase('application', "octet-stream")
30. part.set_payload(open("image.jpg", "rb").read())
31. encoders.encode_base64(part)
32. part.add_header('Content-
Disposition', 'attachment; filename="image.jpg"') # File name and format
name
33. msg.attach(part)
34.
35. try:
36. s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
37. s.ehlo()
38. s.starttls()
39. s.ehlo()
40. s.login(user = 'raviraw299@gmail.com', password = '*********') #
User id & password
41. #s.send_message(msg)
42. s.sendmail(me, toaddr, msg.as_string())
43. s.quit()
44. #except:
45. # print ("Error: unable to send email")
46. except SMTPException as error:
47. print ("Error") # Exception
48.
49. send_an_email()

Save with Ctrl + S and run with F5. When you check your mail, you will find that the image has
been received.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering

Q.1 How to acquire and store the data?


Data acquisition means acquiring the data from IOT/M2M devices. The data communicated after the
interactions with a Data acquisition system (Application). The Application interacts and communicates
with number of devices for acquiring the needed data. The devices send data on demand or at the
programmed intervals. Data of devices communicate using the network, transport and security layers.
Data Store:
Database
Relational database
Flat file
Spreadsheet
Mail server
Web server
Data Store
The acquired data stores in the databases at a server Data Storage Three Categories
1. On-line or real time or streaming data needing the processing, and only the results of processing and
analysis need storage
2. Data called once, only the results of processing at a later time and of analysis store,
3. Data needing repeated calls store for reference or audit in future.,
VMware at one node or distributed multiple nodes. A Data Store is a data repository of a set of objects
which integrate into the Store.
Data Store Features
Objects in a Data Store model using Classes which the database schemas define.
Data Store may be distributed over multiple nodes, (Apache Cassandra is example of distributed Data
Store.)
A Data Store may consist of multiple schemas or may consist of data in only one scheme. (Example of
only one scheme Data Store is relational database.)
For short reaction times, Optimised performance and high security
Data security and protection using the advanced tools, full data backups along with data recovery,
redundant data communication connections and full system power
Data Store Management
Data Store requires Data Centre management or Server management.
Spatial storage
Spatial database optimised to store, enables querying the data objects defined in a geometric space, and
which is a database for 2D and 3D objects
Topological coverage, linear networks, triangular irregular networks or other complex structures.
Mahavir Education Trust's
Shah & Anchor Kutchhi Engineering College,
Chembur, Mumbai 400 088
UG Program in Electronics Engineering
Q.2 Explain LPWAN fundamentals.
A Low Power Wide Area Network refers to a type of wireless telecommunication network designed to
allow long-range communications that communicate at a low bit rate among things (connected objects),
such as WSNs and battery operated sensors. A number of standards are included in LPWAN. Examples are
LTE Advanced for Machine Type Communications (LTE-MTC) for connected things, and LoRaWAN
specifications. The low power, low bit rate and intended use distinguish this type of network from a
wireless WAN that is designed to connect users or businesses, and carry more data, using more power. The
LPWAN data rate ranges from 0.3 kbit/s to 50 kbit/s per channel. A LPWAN may be used to create a
private wireless sensor network, but may also be a service or infrastructure offered by a third party,
allowing the owners of sensors to deploy them in the field without investing in gateway technology.

You might also like