OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Python script to log PI CPU temp to Thingspeak channel

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #38330


    I 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 that logs the temperature to a channel on and posts the temperature every 60 seconds. Here is one of my channels:

    A copy of my code is available at

    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

    2) copy the channel key into the script below

    3) save the script below as ‘’ (or fetch the latest release from Github

    4) run the script as ‘sudo python’

    #!/usr/bin/env python
    __author__ = 'munnecke'
    # This program logs a Raspberry Pi's CPU temperature to a Thingspeak Channel
    # To use, get a account, set up a channel, and capture the Channel Key at 
    # Then paste your channel ID in the code for the value of "key" below.
    # Then run as sudo python (access to the CPU temp requires sudo access)
    # You can see my channel at
    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("")
                conn.request("POST", "/update", params, headers)
                response = conn.getresponse()
                print temp
                print response.status, response.reason
                data =
                print "connection failed"
    #sleep for desired amount of time
    if __name__ == "__main__":
            while True:


    Cool. Thanks for sharing.



    Do 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?



    Raspberry 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.




    I’m pushing 65C now, and it keeps running

    If it does shut down due to overtemp, do you know if it will it just reboot when it cools down?



    I’m new to thingspeak, so I have an doubt where the python program want to run????

Viewing 6 posts - 1 through 6 (of 6 total)
  • 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