Announcement

Collapse
No announcement yet.

Monitor PI CPU Temp?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Monitor PI CPU Temp?

    Is it possible with a script to monitor the Raspberry PI CPU temperature?

    Sump pump failed (no, I did not have any water sensors ) soaking the carpet. All my equipment sits in a closet off of the office. The office will be closed with a dehumidifier for 3 days. I'm told it will get up to 90 degrees and I'm concerned about the temp.

    I will have a fan blowing on all the equipment, but was hoping to get alerted on temperature.

    Thanks,

    Jim

    #2
    I use the following flow in Node-Red to measure CPU temp and then send to HS via MQTT. You could also send to HS via HTTP/JSON if you don't want to mess with MQTT.

    The underlying command is this.

    Code:
    vcgencmd measure_temp
    Code:
    [{"id":"c864c2db.1b099","type":"inject","z":"5a97fdf4.354ee4","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"x":145,"y":102,"wires":[["9383981b.15e2d8"]]},{"id":"9383981b.15e2d8","type":"exec","z":"5a97fdf4.354ee4","command":"vcgencmd","addpay":false,"append":"measure_temp","useSpawn":"","timer":"","name":"getBCMtemp","x":392.42857360839844,"y":99.49996948242188,"wires":[["ea341776.2c5f68"],[],[]]},{"id":"bd31580f.d14548","type":"debug","z":"5a97fdf4.354ee4","name":"","active":false,"console":"false","complete":"false","x":778,"y":47.571449279785156,"wires":[]},{"id":"ea341776.2c5f68","type":"function","z":"5a97fdf4.354ee4","name":"BCMtempParse","func":"var tempstring = msg.payload;\nvar parts = tempstring.split('=')\nvar tempc = parseFloat(parts[1])\n    tempf = tempc * 9/5 + 32;\n    tempf = Math.round(tempf * 10) / 10;\n    msg.payload = tempf;\nreturn msg;","outputs":1,"noerr":0,"x":597,"y":88.57144927978516,"wires":[["bd31580f.d14548","74e3446b.3ec89c"]]},{"id":"74e3446b.3ec89c","type":"mqtt out","z":"5a97fdf4.354ee4","name":"","topic":"RPI3-1/System/BCMTemp","qos":"","retain":"true","broker":"7f38787d.514728","x":826,"y":89.57144165039062,"wires":[]},{"id":"7f38787d.514728","type":"mqtt-broker","z":"","broker":"192.168.0.33","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

    Comment


      #3
      a script for cpu temp

      You can make a device and run this script, remember to change dref.
      its set up to show Celsius, save as xxx.vb

      Code:
      Imports System.IO
      
      ''ZeeTemperature.vb*-*Rob*Mason*-*10/23/2013*-*Free*to*use/modify. 
      
      Sub Main(parm As Object)
          Dim FTemp, CTemp As Double
          Dim lin As String
          Dim sr As StreamReader
          Dim dref As Integer = 5     'use*your*own*device*reference 
      
          Try
              sr = New StreamReader("/sys/class/thermal/thermal_zone0/temp")
              lin = sr.ReadLine()
      
              CTemp = CDbl(lin) / 1000.0
              FTemp = getFarenheit(CTemp)
              ''hs.WriteLog("ZeeTemperature","lin="*&*lin*&*"--*CTemp="*&*CTemp*&*"**FTemp="*&*FTemp) 
      
              ''update*device*here*-*use*CTemp*or*FTemp*as*needed 
              hs.SetDeviceValueByRef(dref, CTemp, True)
              hs.SetDeviceString(dref, "Current*Temp:*" & CTemp.ToString("0.#") & "&deg*C", True)
      
          Catch ex As Exception
              hs.WriteLog("ZeeTemperature", ex.Message)
          Finally
              If (Not sr Is Nothing) Then sr.Close()
          End Try
      End Sub
      
      Public Function getFarenheit(ByVal c As Double) As Double
          Dim d As Double
          d = c * 9 / 5 + 32
          Return d
      End Function

      Comment


        #4
        Originally posted by xreec View Post
        a script for cpu temp

        You can make a device and run this script, remember to change dref.
        its set up to show Celsius, save as xxx.vb

        Code:
        Imports System.IO
        
        ''ZeeTemperature.vb*-*Rob*Mason*-*10/23/2013*-*Free*to*use/modify.
        
        Sub Main(parm As Object)
        Dim FTemp, CTemp As Double
        Dim lin As String
        Dim sr As StreamReader
        Dim dref As Integer = 5 'use*your*own*device*reference
        
        Try
        sr = New StreamReader("/sys/class/thermal/thermal_zone0/temp")
        lin = sr.ReadLine()
        
        CTemp = CDbl(lin) / 1000.0
        FTemp = getFarenheit(CTemp)
        ''hs.WriteLog("ZeeTemperature","lin="*&*lin*&*"--*CTemp="*&*CTemp*&*"**FTemp="*&*FTemp)
        
        ''update*device*here*-*use*CTemp*or*FTemp*as*needed
        hs.SetDeviceValueByRef(dref, CTemp, True)
        hs.SetDeviceString(dref, "Current*Temp:*" & CTemp.ToString("0.#") & "&deg*C", True)
        
        Catch ex As Exception
        hs.WriteLog("ZeeTemperature", ex.Message)
        Finally
        If (Not sr Is Nothing) Then sr.Close()
        End Try
        End Sub
        
        Public Function getFarenheit(ByVal c As Double) As Double
        Dim d As Double
        d = c * 9 / 5 + 32
        Return d
        End Function
        I'm late to the party, but where do I get the dref for my particular Pi?
        Thanks!

        Comment


          #5
          So I thought all I had to do was create a virtual device, get the device ref for that and then change the script to reference that dref. So I changed the line that says

          Dim dref As Integer = 5 'use*your*own*device*reference

          to

          Dim dref As Integer = 1146 (my virtual device ref)

          and then triggered an event to run the script. However, I get the following errors in my log:

          Click image for larger version  Name:	Screenshot 2022-10-28 172633.jpg Views:	0 Size:	30.7 KB ID:	1573059

          Is there something else I need to change? Or have I not referenced the dref correctly?
          Malcolm

          Comment


            #6
            Please copy and paste your entire script here (using the code tags) so it displays correctly.
            Jon

            Comment


              #7
              Not to hijack this thread but this is something that tenholde's tenscripting can resolve quickly. It's usually a typo that isn't immediately obvious.
              "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

              Comment

              Working...
              X