-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathsend_tweet.py
More file actions
executable file
·31 lines (24 loc) · 897 Bytes
/
send_tweet.py
File metadata and controls
executable file
·31 lines (24 loc) · 897 Bytes
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
#!/usr/bin/env python
import time, os, urllib, urllib2
MAX_TEMP = 37.0
MIN_T_BETWEEN_WARNINGS = 60 # Minutes
BASE_URL = 'https://api.thingspeak.com/apps/thingtweet/1/statuses/update/'
KEY = '68LZC4LBMXLO6YDY'
def send_notification(temp):
status = 'Raspberry Pi getting hot. CPU temp=' + temp
data = urllib.urlencode({'api_key' : KEY, 'status': status})
response = urllib2.urlopen(url=BASE_URL, data=data)
print(response.read())
def cpu_temp():
dev = os.popen('/opt/vc/bin/vcgencmd measure_temp')
cpu_temp = dev.read()[5:-3]
return cpu_temp
while True:
temp = cpu_temp()
print("CPU Temp (C): " + str(temp))
if temp > MAX_TEMP:
print("CPU TOO HOT!")
send_notification(temp)
print("No more notifications for: " + str(MIN_T_BETWEEN_WARNINGS) + " mins")
time.sleep(MIN_T_BETWEEN_WARNINGS * 60)
time.sleep(1)