sdr.py not parsing Oregon WGR800X output correctly.

77 views
Skip to first unread message

Rob Series

unread,
May 20, 2020, 9:00:38 AM5/20/20
to weewx-user
Hi,

Please could anyone help. I'm having problems using an Oregon wind speed sensor using instructions on /weewx/weewx/wiki/sdr-rpi-recipe.
This was working, but following an upgrade from an old WGR800 to the newer WGR800X it seems to have broken.
 
Output from sdr.py shows its getting the correct wind speed, but the parse is breaking. The crazy thin is it works with my older WGR800 unit where the input appears to be the same format. Is it possibly related to the \n

WEEWX SDR FILTER OUTPUT
=======================
 pi@raspberrypi:~ $ sudo PYTHONPATH=/usr/share/weewx python /usr/share/weewx/user/sdr.py --cmd="rtl_433 -M utc -F json" --debug

out:[u'{"time" : "2020-05-20 12:24:03", "brand" : "OS", "model" : "Oregon-WGR800", "id" : 100, "channel" : 0, "battery_ok" : 1, "wind_max_m_s" : 1.700, "wind_avg_m_s" : 0.600, "wind_dir_deg" : 202.500}\n']

parsed: {'battery.0:100.OSWGR800Packet': 1, 'wind_dir.0:100.OSWGR800Packet': None, 'dateTime': 1589977443, 'wind_speed.0:100.OSWGR800Packet': None, 'wind_gust.0:100.OSWGR800Packet': None, 'usUnits': 17}


weewx.conf

...
  [SDR]
    # This section is for the software-defined radio driver.
   
    # The driver to use
    driver = user.sdr
    cmd = rtl_433 -M utc -F json
    path=/usr/local/bin/
    log_unknown_sensors = True
    log_unmapped_sensors = True
   
    [[sensor_map]] 
        # Wind sensor
        windSpeed = wind_speed.0:100.OSWGR800Packet
        windGust = wind_gust.0:100.OSWGR800Packet
        windDir = wind_dir.0:100.OSWGR800Packet
        windBatteryStatus = battery.0:100.OSWGR800Packet


Other info
==========
pi@raspberrypi:~ $ sudo PYTHONPATH=/usr/share/weewx python /usr/share/weewx/user/sdr.py --version
sdr driver version 0.77

pi@raspberrypi:~ $ rtl_433 -V
rtl_433 version 20.02-55-gc1d1f9f branch master at 202005162227 inputs file rtl_tcp RTL-SDR



ALSO
====
If anyone has access to edit the sdr-rpi-recepie page, could the add appropriate 'cmd' and 'path' lines to the conf file (or should thhs have been added automativally by weewx_conf and the install script?
It took me some time to figure it out.

Many thanks for a great product.



Rob Series

unread,
May 23, 2020, 9:02:29 AM5/23/20
to weewx-user
Hi,
I have done some more research and it looks like there was a change in RTL_433 at tag 19.08 (August 2019) that changed the naming convention for a significant number of wind related fields for lots of sensors. I guess sdr.py needs to be updated to take this into account. I would offer but my main programming was over 20 years ago and have never programmed in Python so I would probably do more harm than good.


Gazza

unread,
May 23, 2020, 11:53:32 PM5/23/20
to weewx-user

As you have alredy found this is another case where rtl_433 has changed the reported info from what is expected by sdr.py V0.77.

For this station it looks like most of the strings have changed.

In the 'class OSWGR800Packet(Packet):' section of sdr.py try changing these bits,

from        IDENTIFIER = "WGR800"
to          IDENTIFIER = "Oregon-WGR800"


from        pkt['wind_gust'] = Packet.get_float(obj, 'gust')
              pkt['wind_speed'] = Packet.get_float(obj, 'average')
              pkt['wind_dir'] = Packet.get_float(obj, 'direction')


to           pkt['wind_gust'] = Packet.get_float(obj, 'wind_max_m_s')
              pkt['wind_speed'] = Packet.get_float(obj, 'wind_avg_m_s')
              pkt['wind_dir'] = Packet.get_float(obj, 'wind_dir_deg')


The battery status info has also changed from 'battery:OK' to 'battery_ok : 1' but I'm not sure what change is needed to fix that.


Gaz

Rob Series

unread,
May 24, 2020, 6:11:00 AM5/24/20
to weewx-user
Thanks. In the end I kept the sensor name the same and mimiced the code for parse_json() from another posting so its compatible with both versions of rtl_433.
NB original version of sdr.py parses battery status the wrong way round (0 is False, 1 is True). Seems to be a common problem in lots of sensors.
Here is the fixed code:

    # {"time" : "2018-08-04 15:29:27", "brand" : "OS", "model" : "PCR800", "id" : 236, "channel" : 0, "battery" : "OK", "rain_rate" : 0.000, "rain_total" : 109.594}
    # {"time" : "2020-05-23 11:18:53", "brand" : "OS", "model" : "Oregon-PCR800", "id" : 40, "channel" : 0, "battery_ok" : 1, "rain_rate_in_h" : 0.000, "rain_in" : 97.571}
    @staticmethod
    def parse_json(obj):
        pkt = dict()
        pkt['dateTime'] = Packet.parse_time(obj.get('time'))
        pkt['usUnits'] = weewx.US
        pkt['house_code'] = obj.get('id')
        pkt['channel'] = obj.get('channel')
       
        if 'battery' in obj:
            pkt['battery'] = 1 if obj.get('battery') == 'OK' else 0
        if 'battery_ok' in obj:
            pkt['battery'] = 1 if obj.get('battery_ok') == 'OK' else 0
       
        # Rain rate (inches/hour - weewx.us set above)
        if 'rain_rate' in obj:
            pkt['rain_rate'] = Packet.get_float(obj, 'rain_rate')
        if 'rain_rate_in_h' in obj:
            pkt['rain_rate'] = Packet.get_float(obj, 'rain_rate_in_h')

        # Total rainfall (inches)
        if 'rain' in obj:
            pkt['rain'] = Packet.get_float(obj, 'rain')
        if 'rain_in' in obj:
            pkt['rain'] = Packet.get_float(obj, 'rain_in')

        return OS.insert_ids(pkt, OSPCR800Packet.__name__)

Looking at the code for rtl_433 lots of other sensors are affected by the cnages in rtl_443. Is there a mechanism for asking the developers to update the official version of sdr.py?

Many thanks

Gazza

unread,
May 25, 2020, 6:09:09 AM5/25/20
to weewx-user

Hi Rob,

I don't know much about python so can you explain how the new version of the battery status works as I still have to sort that for my mates station.

        if 'battery_ok' in obj:
            pkt
['battery'] = 1 if obj.get('battery_ok') == 'OK' else 0

If the received data is "battery_ok" : 1 ( or "battery_ok" : 0 for flat battery), what is the == 'OK' doing as it will never return a result of 'OK" ??


Gaz

Rob Series

unread,
May 25, 2020, 2:30:24 PM5/25/20
to weewx-user
Hi Gazza,
The 'if' statement is on the right hand side of the '=' sign is actually a ternary operator. Read the expression as :

      if obj.get('battery_ok') == 'OK':
       pkt['battery'] = 1
        else:
              pkt['battery']=0

(In python Numeric zero, None or False all evaluate to False, anything else is true).

C++ has a similar operator ? : operator.

See https://www.python.org/dev/peps/pep-0308/ for the rational. Personally I find it very confusing to use 'if' for both forms.

Hope this helps. Good luck.

Rob
Reply all
Reply to author
Forward
0 new messages