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
    Posts
  • #38330

    tom
    Participant

    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 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)
    
    #38368

    Ray
    Keymaster

    Cool. Thanks for sharing.

    #38459

    tom
    Participant

    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?

    #38466

    Samer
    Keymaster

    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.

    Thanks!

    #39673

    tom
    Participant

    I’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?

    #45324

    Nithin
    Participant

    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