cmon - Extension / cpu_temp missing on raspberry

194 views
Skip to first unread message

Pline Pa

unread,
Mar 10, 2021, 12:12:00 PM3/10/21
to weewx...@googlegroups.com
Hello,

i have installed the cmon extension as described in
https://github.com/weewx/weewx/wiki/cmon

In the plots the cpu_temp - Graph has no values.

I use an raspberry pi 4

does someone have a tip about it?

Many thanks and greetings

plinepa


weewx.log

Dr__Bob

unread,
Mar 12, 2021, 10:41:44 PM3/12/21
to weewx-user
In the file cmon.py, there is a check on a directory (tdir) and a check on a specific file (tfile).  Apparently on some unices, the directory tdir contains a file with the cpu temp.  On raspberries, the directory exists, but doesn’t contain the temperature file.  The cpu temp is actually in the file tfile.  So basically, you have to swap the order of the check:  check first for tfile then tdir.  I’d post the necessary mod, but I don’t have access to my rpi right now.

Hope this helps and sorry for not being able to give more details!

Pline Pa

unread,
Mar 14, 2021, 4:06:37 AM3/14/21
to weewx...@googlegroups.com
Thank you for the hints!

I was able to find the cmon.py file under /usr/share/weewx/user/

I've  changed the if-condition so that tfile is now used.

Now the display of the cpu_temp works perfectly.

Many Thanks

Matthias Manhart

unread,
Nov 28, 2022, 8:26:28 AM11/28/22
to weewx-user
Thanks to the hints in this case. I run weewx on a Raspberry Pi 4 too and could not see a CPU temperature.

I modified the file cmon.py like this:

        # read cpu temperature
        tdir = '/sys/class/hwmon/hwmon0/device'
        # rpi keeps cpu temperature in a different location
        tfile = '/sys/class/thermal/thermal_zone0/temp'
        if os.path.exists(tfile):                                    # moved above 'elif os.path.exists(tdir):'
            try:
                s = self._readproc_line(tfile)
                t_C = int(s) / 1000 # degree C
                record['cpu_temp'] = t_C
            except Exception as e:
                logdbg("read failed for %s: %s" % (tfile, e))
        elif os.path.exists(tdir):                                   # moved behind 'if os.path.exists(tfile):'
            try:
                for f in os.listdir(tdir):
                    if f.endswith('_input'):
                        s = self._readproc_line(os.path.join(tdir, f))
                        if s and len(s):
                            n = f.replace('_input', '')
                            t_C = int(s) / 1000 # degree C
                            record['cpu_' + n] = t_C
            except Exception as e:
                logdbg("read failed for %s: %s" % (tdir, e))

The ' if os.path.exists(tfile): ' must be checked first. The complete block beginning with ' if os.path.exists(tfile): ' must be moved and if and elif must be changed. Now i can see the CPU temperature.

Reply all
Reply to author
Forward
0 new messages