OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › Python script to log PI CPU temp to Thingspeak channel
- This topic has 5 replies, 4 voices, and was last updated 8 years ago by Nithin.
-
AuthorPosts
-
June 11, 2015 at 11:23 am #38330
tomParticipantI installed an OSPI controller in an outdoor location in an Orbit Sprinkler box (from Home Depot), and was worried about it overheating. So I wrote a script called pitime.py that logs the temperature to a channel on Thingspeak.com and posts the temperature every 60 seconds. Here is one of my channels: https://thingspeak.com/channels/41518
A copy of my code is available at https://github.com/munnecke/water
I still haven’t figured out how hot is too hot. I’ve wrapped the control box in aluminum foil, and it seems to help a bit. I suspect having the big power transformer inside the box doesn’t help.
to install your own version,
1) follow the instructions to create your own login and channel https://thingspeak.com/docs/tutorials/
2) copy the channel key into the script below
3) save the script below as ‘pitemp.py’ (or fetch the latest release from Github https://github.com/munnecke/water)
4) run the script as ‘sudo python pitemp.py’
#!/usr/bin/env python __author__ = 'munnecke' # This program logs a Raspberry Pi's CPU temperature to a Thingspeak Channel # To use, get a Thingspeak.com account, set up a channel, and capture the Channel Key at https://thingspeak.com/docs/tutorials/ # Then paste your channel ID in the code for the value of "key" below. # Then run as sudo python pitemp.py (access to the CPU temp requires sudo access) # You can see my channel at https://thingspeak.com/channels/41518 import httplib, urllib import time sleep = 60 # how many seconds to sleep between posts to the channel key = 'Put your Thingspeak Channel Key here' # Thingspeak channel to update #Report Raspberry Pi internal temperature to Thingspeak Channel def thermometer(): while True: #Calculate CPU temperature of Raspberry Pi in Degrees C temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Get Raspberry Pi CPU temp 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)
June 12, 2015 at 12:50 pm #38368
RayKeymasterCool. Thanks for sharing.
June 16, 2015 at 12:41 pm #38459
tomParticipantDo you have any idea of how hot is too hot? And if it does overheat, does it fry the whole board, or just shut down gracefully?
June 16, 2015 at 2:57 pm #38466
SamerKeymasterRaspberry Pi keeps specifications on the max operating temperture but I did look this up before and I believe the network controller is what gets the hotest on the Pi but can withstand ~60 C before having to turn off.
If it does overheat, the sensor will tell the board it’s too hot and it will just kill the power. This is in regard to the Raspberry Pi, not the OpenSprinkler Pi.
Thanks!
August 4, 2015 at 11:22 pm #39673
tomParticipantI’m pushing 65C now, and it keeps running https://thingspeak.com/channels/41518
If it does shut down due to overtemp, do you know if it will it just reboot when it cools down?
January 30, 2017 at 11:06 pm #45324
NithinParticipantI’m new to thingspeak, so I have an doubt where the python program want to run????
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › Python script to log PI CPU temp to Thingspeak channel