Intermittent barometer reading from Acurite 02032C

49 views
Skip to first unread message

Brett Warden

unread,
Sep 16, 2021, 1:26:40 PM9/16/21
to weewx-user
This has been bugging me for a few years, but I just haven't been able to figure out where/how to fix it best. In the Acurite driver, there are 3 different data packets (and two variants of one of those), each updated at different intervals (18, 60, and 12*60 seconds)  Indoor air pressure is reported in R2, while outside temperature is reported in alternating R1 variants. This means that we *often* don't have a current reading for outside temperature at the same time we get a pressure reading, especially if the USB connection is being finicky, which is common with Acurite hardware.

As a result, there can be long intervals (I've seen 10+ minutes) between successful barometer calculations. When generating static webpages or otherwise working from archive data, this isn't a huge issue. When trying to do something near-real-time with loop data (for example MQTT to Home Assistant), though, this can be really annoying.

I'm not sure the best way to fix it, but one idea I've been tossing around is caching *all* the readings for a period of time (say 1-2 minutes) to ensure we have all the R1 data (including outTemp and *both* R1 variants) every time we get R2 data (pressure and inTemp). This is nice because it only affects the Acurite driver, and as a side effect, the loop data could include *everything* that was received in the last minute, not just what was in the last packet decoded, yielding a complete snapshot of reasonably current data.

Alternately, we could modify lower level weewx behavior, to include caching the temperature data used by the barometer calculation (weewx.wxformulas.sealevel_pressure_metric and weewx.wxformulas.sealevel_pressure_US). This would of course affect other drivers, but maybe some of them have the same issue.

Anyway, just looking for thoughts about this, or better ways to solve it.

Brett Warden

unread,
Sep 16, 2021, 2:08:52 PM9/16/21
to weewx-user
Maybe something like this:
--- drivers/acurite.py.orig     2021-04-02 13:15:41.000000000 -0700
+++ drivers/acurite.py  2021-09-16 10:59:45.223889264 -0700
@@ -447,6 +447,7 @@
         self.r3_max_fail = 3
         self.r1_next_read = 0
         self.r2_next_read = 0
+        self.cached = dict()
         global DEBUG_RAW
         DEBUG_RAW = int(stn_dict.get('debug_raw', 0))

@@ -481,11 +482,19 @@
                                 log.debug("R3: %s" % _fmt_bytes(row))
                 if raw1:
                     packet.update(Station.decode_R1(raw1))
+                    if 'outTemp' in packet:
+                        # Cache the current outside temp for barometer calculations
+                        self.cached['outTemp'] = packet['outTemp']
+                        self.cached['timestamp'] = time.time()
                 if raw2:
                     Station.check_pt_constants(last_raw2, raw2)
                     last_raw2 = raw2
                     packet.update(Station.decode_R2(
                             raw2, self.use_constants, self.ignore_bounds))
+
+                    # Make sure we have a recent outside temperature reading to feed the barometer calculation
+                    if 'outTemp' not in packet and 'outTemp' in self.cached and 'timestamp' in self.cached and self.cached['timestamp'] > time.time() - 60:
+                        packet['outTemp'] = self.cached['outTemp']
                 self._augment_packet(packet)
                 ntries = 0
                 yield packet

Reply all
Reply to author
Forward
0 new messages