[weewx-user] Re: sdr.py not parsing Oregon WGR800X output correctly.

2020-05-25 Thread 'Rob Series' via 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


On Monday, 25 May 2020 11:09:09 UTC+1, Gazza wrote:
>
>
> 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
>

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/662e5e8a-7cbb-4cac-af52-405abae5f1a4%40googlegroups.com.


[weewx-user] Re: sdr.py not parsing Oregon WGR800X output correctly.

2020-05-25 Thread Gazza

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

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/e8aabc20-d62b-44ab-934f-7187f5383c27%40googlegroups.com.


[weewx-user] Re: sdr.py not parsing Oregon WGR800X output correctly.

2020-05-24 Thread 'Rob Series' via 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

On Sunday, 24 May 2020 04:53:32 UTC+1, Gazza wrote:
>
>
> 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,
>
> fromIDENTIFIER = "WGR800"
> to  IDENTIFIER = "Oregon-WGR800"
>
>
> frompkt['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
>

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/47aabe74-f73f-4a08-b4f6-38c1e0eeb9cc%40googlegroups.com.


[weewx-user] Re: sdr.py not parsing Oregon WGR800X output correctly.

2020-05-23 Thread Gazza

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,

fromIDENTIFIER = "WGR800"
to  IDENTIFIER = "Oregon-WGR800"


frompkt['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

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/45760cec-2038-4b2d-8ba7-8fff073d94be%40googlegroups.com.


[weewx-user] Re: sdr.py not parsing Oregon WGR800X output correctly.

2020-05-23 Thread 'Rob Series' via 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.

https://github.com/merbanan/rtl_433/commit/6d21cad0f158fbc6064d66ddd1abf96d6ba4867b#diff-06935eba6ba3c8d3e4b0d4d59d294ac8

see also:

https://github.com/merbanan/rtl_433/blob/6d75c7db86793072f854a33efa0a88a83e06e796/src/devices/oregon_scientific.c#L637-L654

On Wednesday, 20 May 2020 14:00:38 UTC+1, Rob Series wrote:
>
> 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.
>
>
>
>

-- 
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 weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/f314cf81-9a25-404f-9b49-e17a50535a4d%40googlegroups.com.