-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU_python.py
More file actions
37 lines (30 loc) · 1.13 KB
/
Copy pathCPU_python.py
File metadata and controls
37 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__author__ = 'Derandi Hermanda'
#memasukan library
import httplib, urllib
import time
sleep = 60 #waktu (detik) untuk sleep dan post ke chanel
key = 'isi API Key thingspeak'
# ini untuk meng push data ke thinkspeak channel
def thermometer():
while True:
#mengambi data temperatur CPU dalam Derajat (C)
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Get Raspberry Pi CPU temp
#mengirim data ke thingspeak
params = urllib.urlencode({'field1': temp, '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 temp
print response.status, response.reason
data = response.read()
conn.close()
except:
print "connection failed"
break
#sleep for desired amount of time
if __name__ == "__main__":
while True:
thermometer()
time.sleep(sleep)