Professional Documents
Culture Documents
Assignment NO. 4: Elective Iii:Iot Lab
Assignment NO. 4: Elective Iii:Iot Lab
Problem Statement:
Upload temperature monitor data from DHT-11 sensor to Things Speak cloud server.
Hardware Requirements:
Raspberry-pi
Software Requirements:
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.
Go to www.thingspeak.com
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.
JSPM’s IT 2
ELECTIVE III :IOT LAB
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.
Use your Write API Key to replace the key with your API Key
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
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