cat cputemp-opi5p.dat
105.6
All of my cpu temps (I have 6 total) look just like the above 
(cputemp-opi5p.dat, -op5.dat, -pi4b1.dat, -pi3b2.dat, -pi5r.dat, and 
cputemp-ser8.dat)
The 6 .dat files are refreshed (rewritten) every 5 minutes, a minute before 
weewx runs, and scp'd to the server running weewx for the extensions.py to 
read; each read()
only goes to its own file.
I've attached my *latest* extensions.py --  you'll see the 6 temperature 
readings, 2 are from orange pi's, 1 is from an SER8, and 3 are from 
raspbery pi's. 
You may see my python statements and you may find fault with them, but in 
order to get them working I have already done way more 
reading/experimenting/testing than I
wanted to in order to get them to run without crashing. So they're tested 
as - is.  What I'm still trying to figure out (hence the try: except: 
finally:) is if the read or cast fails, to catch it and
just plug in a ringer (nominal) value for that run. But something about the 
big weewx python engine doesn't like the try: added into extensions.py, it 
just give a *systemd[1]: weewx.service: Main process exited, code=exited, 
status=1/FAILURE*
in the syslogs, and I have to comment out the try: in extensions.py in 
order for it to run.
Hope this makes it clearer as to the situation.
Thanks  --
On Wednesday, April 16, 2025 at 11:20:09 PM UTC-5 Susan Mackay wrote:

> Probably not the problem (as it this relates to code above the error line) 
> but you have several places where you open a file, read every line and 
> process the data in that line but only pass back the last value read. This 
> seems to be a waste of a lot of processing
> .
> I agree with the comments above - the extraneous NULL in the file would 
> seem to be the issue. Perhaps you need to look at that and see if you can 
> fix the problem in the file. (Probably not as I'm guessing by the comments 
> that the file is written by the OS.) Try 'rstrip("\0")' after the 'read()'
> Susan
> On Thursday, 17 April 2025 at 5:07:48 am UTC+10 Karen K wrote:
>
>> messyp...@gmail.com schrieb am Mittwoch, 16. April 2025 um 06:31:01 
>> UTC+2:
>>
>> Apr 15 16:00:16 PI4B1 weewxd[268425]: weewx[268425] CRITICAL __main__:   
>>   ****  ValueError: could not convert string to float: '94.8\x00'
>>
>>
>> May be the nul character at the end of the file to read is the problem. 
>> In the error message above it is expressed as "\x00". 
>>
>

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/weewx-user/b26a8702-2b5f-4c0f-ab53-cd5f9e54a164n%40googlegroups.com.
#!/usr/bin/env python
#    Copyright (c) 2009-2015 Tom Keffer <tkef...@gmail.com>
#
#    See the file LICENSE.txt for your full rights.
#

"""User extensions module

This module is imported from the main executable, so anything put here will be
executed before anything else happens. This makes it a good place to put user
extensions.
"""

import locale
# This will use the locale specified by the environment variable 'LANG'
# Other options are possible. See:
# http://docs.python.org/2/library/locale.html#locale.setlocale
locale.setlocale(locale.LC_ALL, '')

import weewx.units
#weewx.units.obs_group_dict['waterTemp'] = 'group_temperature'
#weewx.units.obs_group_dict['LakeElev'] = 'group_altitude'
import re
import os

from weewx.engine import StdService
weewx.units.obs_group_dict['LakeElev'] = 'group_lake'
weewx.units.USUnits['group_lake'] = 'feetMSL'
weewx.units.default_unit_format_dict['feetMSL'] = '%.2f'
weewx.units.default_unit_label_dict['feetMSL'] = ' ftMSL'


class AddMyData(StdService):

	def __init__(self, engine, config_dict):
	# Initialize my superclass first:
		super(AddMyData, self).__init__(engine, config_dict)
	# Bind to any new archive record events:
		self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_packet)

	def new_archive_packet(self, event):

#	putting / declaring a variable here crashes it

	#(code that reads two measurements from a file)
		with open("/home/pi/wxdata/weewxmbdata.dat") as f:
			value1 = 600.00  #initialize anyway
			value2 = 123.45  #initialize anyway
			for line in f:
				numbers_str = line.split()
				numbers_float = [float(x) for x in numbers_str]
				value1 = numbers_float[0]
				value2 = numbers_float[1]

			event.record['LakeElev'] = value1
#			event.record['lakeWaveheight'] = value2

		with open("/home/pi/cputemp-pi4b1.dat") as f:
			value3 = 50.0
			for line in f:
				numbers_str = line.split()
				numbers_float = [float(x) for x in re.findall("\d+\.\d+", line)]
				value3 = numbers_float[0]
				value3 = (value3 * 9/5) + 32
			event.record['extraTemp3'] = value3


#
		with open("/home/pi/cputemp-pi3b2.dat") as f:
			value4 = 50.0
			for line in f:
				numbers_str = line.split()
				numbers_float = [float(x) for x in re.findall("\d+\.\d+", line)]
				value4 = numbers_float[0]
				value4 = (value4 * 9/5) + 32
			event.record['extraTemp4'] = value4


# #weewx was -occasionally- complaining about "UnboundLocalError: local variable 'value5' referenced before assignment"
#   I couldn't find a clue as to what was different about value5 from 4 or 3 ... so try changing to 5x!
		with open("/home/pi/cputemp-pi5r.dat") as f:
			value5x = 80.0   # initialize a "ringer" value, just in case
			for line in f:
				numbers_str = line.split()
				numbers_float = [float(x) for x in re.findall("\d+\.\d+", line)]
				value5x = numbers_float[0]
				value5x = (value5x * 9/5) + 32
			event.record['extraTemp5'] = value5x
#
# orangepi5B now places actual float in its .dat, necessitating cast as float
#Modify this and place in RPI3 extraTemp2
		with open('/home/pi/cputemp-opi5.dat') as f:   #sensors -f requested temps in F
			degf = 80.0	# initialize a "ringer" value, just in case
			degf = float(float(f.read()))		#this is OPI5B
			event.record['extraTemp6'] = degf

		with open('/home/pi/cputemp-opi5p.dat') as f:   #sensors -f requested temps in F
#			try:
				degf2 = 80.0 	# initialize a "ringer" value, just in case
				degf2 = float(float(f.read()))		#this is OPI5P
				print("degf2 okay")
#			except:
#				degf2 = 100.0
#				print("degf2 exception!")
#			finally:
				event.record['extraTemp7'] = degf2

		with open('/home/pi/cputemp-ser8.dat') as f:   #sensors -f requested temps in F
			degf3 = float(float(f.read()))          #this is SER8
			event.record['extraTemp8'] = degf3

Reply via email to