matthewwall / weewx-sdr

weewx driver for software-defined radio
GNU General Public License v3.0
114 stars 74 forks source link

OS THGN129 json parsing is wrong for battery status #135

Closed sbsrouteur closed 2 years ago

sbsrouteur commented 3 years ago

Hi,

It seems that with more recent versions of rtk_433 the json content for the thgn has changed.

Can you change the class to :

class OSBTHGN129Packet(Packet):
    # 2017-08-03 17:24:03     :       OS :    BTHGN129
    # House Code:      146
    # Channel:         5
    # Battery:         OK
    # Celcius:         32.00 C
    # Humidity:        50 %
    # Pressure:        959.36 mPa

    IDENTIFIER = "BTHGN129"
    PARSEINFO = {
        'House Code': ['house_code', None, lambda x: int(x)],
        'Channel': ['channel', None, lambda x: int(x)],
        'Battery': ['battery_ok', None, lambda x: 0 if x == 1 else 1],
        'Celcius': ['temperature', re.compile('([\d.-]+) C'), lambda x: float(x)],
        'Humidity': ['humidity', re.compile('([\d.]+) %'), lambda x: float(x)],
        'Pressure': ['pressure', re.compile('([\d.]+) mPa'), lambda x: float(x)]}

    @staticmethod
    def parse_text(ts, payload, lines):
        pkt = dict()
        pkt['dateTime'] = ts
        pkt['usUnits'] = weewx.METRIC
        pkt.update(Packet.parse_lines(lines, OSBTHGN129Packet.PARSEINFO))
        return OS.insert_ids(pkt, OSBTHGN129Packet.__name__)

    # {"time" : "2021-07-21 21:18:32", "model" : "Oregon-BTHGN129", "id" : 228, "channel" : 1, "battery_ok" : 1, "temperature_C" : 26.300, "humidity" : 57, "pressure_hPa" : 999.000}

    @staticmethod
    def parse_json(obj):
        pkt = dict()
        pkt['dateTime'] = Packet.parse_time(obj.get('time'))
        pkt['usUnits'] = weewx.METRIC
        pkt['house_code'] = obj.get('id')
        pkt['channel'] = obj.get('channel')
        pkt['battery'] = 0 if obj.get('battery_ok') == 1 else 1 
        pkt['temperature'] = Packet.get_float(obj, 'temperature_C')
        pkt['humidity'] = Packet.get_float(obj, 'humidity')
        pkt['pressure'] = Packet.get_float(obj, 'pressure_hPa')
        return OS.insert_ids(pkt, OSBTHGN129Packet.__name__)

Or would you rather have me clone and make a PR?

Regards,

matthewwall commented 2 years ago

fixed at commit aa327eb