I know that this sounds insane, but my modified (to add some extra data 
derived from external sensors) weewx installation which has been running 
for a couple of months now crashes on startup. I stopped weewx to replace a 
(very) old Vantage Pro 2 ISS, removed the old unit, put the new unit in its 
place, reconfigured the console to communicate with the new unit, observed 
that the console was showing valid data, and restarted weewx, which is 
running on a Pi connected to the console via a MeteoPi. weewx immediately 
crashes, with the following exception tree, arising from my user code.
Traceback (most recent call last):
  File "/usr/share/weewx/weewxd", line 261, in <module>
    main()
  File "/usr/share/weewx/weewxd", line 154, in main
    engine.run()
  File "/usr/share/weewx/weewx/engine.py", line 158, in run
    self.dispatchEvent(weewx.Event(weewx.STARTUP))
  File "/usr/share/weewx/weewx/engine.py", line 224, in dispatchEvent
    callback(event)
  File "/usr/share/weewx/weewx/engine.py", line 530, in startup
    self._catchup(self.engine.console.genStartupRecords)
  File "/usr/share/weewx/weewx/engine.py", line 643, in _catchup
    origin='hardware'))
  File "/usr/share/weewx/weewx/engine.py", line 224, in dispatchEvent
    callback(event)
  File "/usr/share/weewx/user/NewTH.py", line 19, in read_file
    event.record['extraTemp1'] = event.record['inTemp']
KeyError: 'inTemp'

It looks as if the event record no longer contains an 'inTemp' item, but 
why not??!! Again, this installation has been running for months, through 
multiple apt update/upgrades and reboots. The only thing that changed was 
the Vantage ISS - I'm using the same console that I always did. Does this 
make sense to anyone? I will try reverting to a standard weewx config, but 
even if this works, it doesn't really help - I want to use and save the 
extra data!

The contents of the user code source file are
import syslog
import weewx
import time
import os

from weewx.wxengine import StdService

class ArchTHService(StdService):
    def __init__(self, engine, config_dict):
        super(ArchTHService, self).__init__(engine, config_dict)
        d = config_dict.get('ArchTHService', {})
        self.filename = d.get('filename', '/var/tmp/THNow.txt')
        self.filename2 = d.get('filename', '/var/tmp/THBNow.txt')
        syslog.syslog(syslog.LOG_INFO, "ArchTH: using %s" % self.filename)
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_file)

    def read_file(self, event):
# save the console values in 'extra' slots
        event.record['extraTemp1'] = event.record['inTemp'] ## This is 
where it fails
        event.record['extraHumid1'] = event.record['inHumidity']
        try:
            #skip it if it's stale. Console values will be used instead
            if time.time() - os.path.getmtime("/var/tmp/THNow.txt") < 600: #10 
minutes
                with open(self.filename) as f:
                    line = f.read() # contains temp & humidity, 
comma-separated
                values=line.split(',')
                syslog.syslog(syslog.LOG_DEBUG, "ArchTH: found value of %s" 
% line)
                event.record['inTemp'] = float(values[0])
                event.record['inHumidity'] = float(values[1])
                with open(self.filename2) as f:
                    line = f.read() # contains basement temp & humidity, 
comma-separated
                values=line.split(',')
                syslog.syslog(syslog.LOG_DEBUG, "ArchTH(B): found value of 
%s" % line)
                event.record['extraTemp2'] = float(values[0])
                event.record['extraHumid2'] = float(values[1])

        except Exception as e:
            syslog.syslog(syslog.LOG_ERR, "ArchTH: cannot interpret value: 
%s" % e)

class LoopTHService(StdService):
    loopcount= 0
    lastT = 0
    lastH =0

    def __init__(self, engine, config_dict):
        super(LoopTHService, self).__init__(engine, config_dict)
        d = config_dict.get('LoopTHService', {})
        self.filename = d.get('filename', '/var/tmp/THNow.txt')
        syslog.syslog(syslog.LOG_INFO, "LoopTH: using %s" % self.filename)
        self.bind(weewx.NEW_LOOP_PACKET, self.read_file)

    def read_file(self, event):
        if self.loopcount == 0:
            try:
                #skip it if it's stale. Vantage Console values will be used 
instead
                if time.time() - os.path.getmtime("/var/tmp/THNow.txt") < 
300: #5 minutes
                    with open(self.filename) as f:
                        line = f.read() # contains temp & humidity, 
comma-separated
                    values=line.split(',')
                    syslog.syslog(syslog.LOG_DEBUG, "LoopTH: found value of 
%s" % line)
                    event.packet['inTemp'] = float(values[0])
                    event.packet['inHumidity'] = float(values[1])
                    self.lastT=float(values[0])
                    self.lastH=float(values[1])
                    self.loopcount += 1
            except Exception as e:
                syslog.syslog(syslog.LOG_ERR, "LoopTH: cannot interpret 
value: %s" % e)  
        else:
            self.loopcount += 1
            if self.loopcount >= 30:
                self.loopcount = 0
            event.packet['inTemp'] = self.lastT
            event.packet['inHumidity'] = self.lastH
 


-- 
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/740ef422-1bc3-45a3-87e4-e5766d2ed213o%40googlegroups.com.

Reply via email to