lheijst / weewx-rtldavis

weewx driver that captures data from software-defined radio using the rtldavis software.
GNU General Public License v3.0
14 stars 5 forks source link

Not handling temperatures below zero F #11

Closed LloydR closed 2 years ago

LloydR commented 2 years ago

I am using this program in degrees F. Have a Vantage Pro 2. Once the temperature goes below 0 degrees F it turns into a large number like 4095 which throws the invalid flag. Looked at /var/log/syslog for this Dec 17 05:13:45 pi34 /weewxd: bme280: {'windSpeed': 2.2351944444444443, 'windDir': 27.92490118577075, 'outTemp': -17.77777777777778, 'txBatteryStatus': 0, 'dateTime': 1639743225, 'usUnits': 17, 'pressure': 855.3806985572605, 'inTemp': 14.241103088203818, 'inHumidity': 23.887456203505856} Dec 17 05:14:05 pi34 /weewxd: bme280: {'windSpeed': 1.7881555555555555, 'windDir': 34.68379446640316, 'outTemp': 209.72222222222223, 'txBatteryStatus': 0, 'dateTime': 1639743246, 'usUnits': 17, 'pressure': 855.3686777911596, 'inTemp': 14.251007335470058, 'inHumidity': 23.90369978568818}

LloydR commented 2 years ago

I had the same problem with my program. I had to do the following to get the proper values when temps went below 0 F xtemp = ((pac[3] << 8) + pac[4]) outTemp = int16(xtemp)/16 packetData[0] = outTemp/10.0 Python3 was not appreciative of int16(). Had to use int.from_bytes() as in if pkt[4] & 0x8:

digital temp sensor

                    # What a pain, the just shifting (as above) fails when temperature goes below 0 F
                    # So need to convert 2 bytes to a signed int for proper values when temp < 0 F
                    # int.from_bytes is a Python3 expression, would need to do struct.upack for python2
                    temp_raw = int.from_bytes([pkt[3], pkt[4]], byteorder='big', signed=True)
                    # The above temp raw (a 16 bit value) needs to be divided by 160 to get true temp
                    # The 12 bit value is already divided by 16 but the 16 bit value is not
                    temp_raw = temp_raw / 16
                    temp_f = temp_raw / 10.0