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

Name :Akshay Haribhau

Kothawade Roll no : 4237


ELECTIVE III :IOT LAB
ASSIGNMENT NO. 4

Problem Statement:
Upload temperature monitor data from DHT-11 sensor to Things Speak cloud server.
Hardware Requirements:
Raspberry-pi

Software Requirements:

Rasbian operating system, Python IDLE

Objectives:

To learn how to use your Raspberry Pi as a gateway device for uploading your sensor data on
ThingSpeak server.
Theory:

WHAT IS THINGSPEAK?

ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data posted
by your devices to ThingSpeak. With the ability to execute MATLAB code in ThingSpeak you
can perform online analysis and processing of the data as it comes in. ThingSpeak is often used
for prototyping and proof of concept IoT systems that require analytics.

FEATURES OF THINGSPEAK:

 Easily configure devices to send data to ThingSpeak using popular IoT protocols.
 Visualize your sensor data in real-time..
 Use the power of MATLAB to make sense of your IoT data.
 Run your IoT analytics automatically based on schedules or events.
 Prototype and build IoT systems without setting up servers or developing web software.

Design IOT App :

JSPM’s BSIOTR,Wagholi IT DEPARTMENT 1


ELECTIVE III :IOT LAB

HOW TO USE THINGSPEAK

Step 1: Signup for ThingSpeak

Go to www.thingspeak.com

Click on signup page and fill the details.

Step 2: Create a Channel for Your Data

Once you Sign in after your account activation, Create a new channel by clicking “New
Channel” button

After the “New Channel” page loads, enter the Name and Description of the data you want to
upload

You can enter the name of your data (ex: Temperature) in Field1. If you want more Fields you
can check the box next to Field option and enter the corresponding name of your data.

Click on “Save Channel” button to save all of your settings.

JSPM’s IT 2
ELECTIVE III :IOT LAB

Step 3: Get an API Key

To upload our data, we need an API key, which we will later include in a piece of python code to
upload our sensor data to Thingspeak Website.

Click on “API Keys” tab to get the key for uploading your sensor data.

(Note: The advantage of using Thingspeak compared to Xively or any other websites is that the
convenience of using Matlab Analysis and Matlab Visualizations. This is a good option
especially if you are doing some kind of research projects)

Once you have the “Write API Key”. We are almost ready to upload our data, except for the
python code.

Step 4: Modifying the Python Code

Use your Write API Key to replace the key with your API Key

Save the file to overwrite changes

Step 5: Assuming you have python 2.7 and proper python libraries.

If the code runs properly you should see “200 ok” and something like “32.6” (CPU temperature
value)

In case if there are any errors uploading the data, you will receive “connection failed” message

Step 6: Check ThingSpeak API and Confirm data transfer

Open your channel and you should see the temperature uploading into thinspeak website.

JSPM’s IT 3
ELECTIVE III :IOT LAB
You can create a python script and run it when the raspberry pi starts.

Conclusion:

We are able to use the service of ThingSpeak and perform online analysis and processing of the
data.

Program :

import httplib,urllib
import time, Adafruit_DHT
sleep=60
key='YILV344OW6XWPEHI' Copy API Key fromwebsite
while True:
h,t=Adafruit_DHT.read_retry(11,4)
print('temp',t)
params=urllib.urlencode({'field1':t,'key':key})
headers={"Content-typZZe":"application/x-www-form
urlencoded","Accept": "text/plain"}

conn=httplib.HTTPConnection("api.thingspeak.com:80")
try:
conn.request("POST", "/update",params,headers)
response=conn.getresponse()
print response.status, response.reason
data=response.read()
conn.close()
except Exception as E:
print "connection failed",E

JSPM’s IT 4

You might also like