I have this working on my Rasberry pi at
https://weather.cougar.eu.com/telemetry.html and this is how I did it
in weewx.conf
In
[Engine]
[[Services]]
set
data_services = user.cputemp.AddCpuTemp
Then add this Python program to the bin user directory where your Rasberry
Pi code is.
# Copyright (c) 2009-2020 Mike Revitt
# See the file LICENSE.txt for your rights.
"""Gets the CPU temperature on a Rasberry Pi"""
*import* weewx
*from* weewx.engine *import* StdService
*from* gpiozero *import* CPUTemperature
*class* AddCpuTemp(StdService):
*def* __init__(self, engine, config_dict):
# Initialize my superclass first:
super(AddCpuTemp, self).__init__(engine, config_dict)
# Bind to any new archive record events:
self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
*def* new_archive_record(self, event):
cpu = CPUTemperature()
*if* event.record['usUnits'] == weewx.US:
event.record['extraTemp1'] = ( cpu.temperature * 1.8 ) + 32
*else*:
event.record['extraTemp1'] = cpu.temperature
On Thursday, May 7, 2020 at 3:48:53 PM UTC+1, Luc Heijst wrote:
>
> Recently I downloaded the latest version of weewx-cmon (v 0.20) which was
> converted to use with python3.
> This version, and also elder versions of cmon.py, did not read the
> cpu-temp of my Raspberri PI systems (models 1B, 2B, 3B and 3B+).
>
> On my raspberry PI the following statement is true: *os.path.exists(tdir)*,
> still
> a cpu-temp could not be found in this section
> The *elif os.path.exists(tfile):* statement caused the bottem section to
> be skipped and that is the section that reads the RPI cpu-temp.
>
> See the modifications in yellow which fixed this problem.
>
> Luc
>
> --- snipped of cmon.py ---
> # read cpu temperature
> tdir = '/sys/class/hwmon/hwmon0/device'
> # rpi keeps cpu temperature in a different location
> tfile = '/sys/class/thermal/thermal_zone0/temp'
> *temp_found = False*
> if os.path.exists(tdir):
> 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):
> *temp_found = True*
> 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))
> ### elif os.path.exists(tfile): ### original statement
> if* not temp_found and *os.path.exists(tfile):
> 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))
>
> -----------
>
>
You can then access the Rasberry Pi CPU temperature as the variable
extraTemp1 from within your HTML files
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/368a7cda-13db-4d7c-a11a-48449d9eb48f%40googlegroups.com.