Rain rate MAYBE implemented correctly

This commit is contained in:
2019-05-26 16:41:54 +02:00
parent a70ee2c162
commit 38aaa35dc8

View File

@@ -84,10 +84,6 @@ sys.path.append(_SCRIPT_PATH + "/home/pi/test/lib")
'''
_VERSION = 2.0
_NAME = u"Vantage Vue Decoding shite"
_LOG_DIR = _SCRIPT_PATH + '/log/'
_LOG_FILE_ROOT = re.sub(u'./', '', sys.argv[0])
_LOG_FILE = _LOG_DIR + _LOG_FILE_ROOT + u'.log'
_DEBUG_FILE = _LOG_DIR + _LOG_FILE_ROOT + u'.dbg'
# finite loop implementation, tout for 43200 cycles
tout = 0
@@ -113,71 +109,7 @@ influx_pwd = 'freedavis'
weather_db = 'weather_v2'
status_db = 'status'
'''
--------------------------------------------------------------------------------
Set up logging - disabled, need to enable this iin future
--------------------------------------------------------------------------------
'''
'''
--------------------------------------------------------------------------------
Setup arguments and Options - not edited, sample shite
--------------------------------------------------------------------------------
'''
desc = u'''\
DESCRIPTION:
Vantage Vue wireless data transfer decoder, V2
consult http://wp.spoton.cz/2017/11/24/davis-vantague-vue-arduino-and-a-raspberry-pi-3/
for wtf is going on
'''
epi = u'''\
ERROR CODES:
?
EXAMPLES:
?
'''
formatter = argparse.RawDescriptionHelpFormatter
arg_parser = argparse.ArgumentParser(description = desc,
formatter_class = formatter,
epilog = textwrap.dedent(epi))
arg_parser.add_argument('-d', '--details',
help = 'help',
action='store_true')
arg_parser.add_argument('-v', '--verbose',
help = 'help',
action='store_true')
arg_parser.add_argument('-p', '--section',
dest = 'section',
default = ['last', 'count', 'diff'],
choices = ['last', 'count', 'diff'],
nargs = '+',
type = str,
help = 'help')
arg_parser.add_argument('-s', '--snapusage',
help = 'help',
action='store_true')
args = arg_parser.parse_args()
if args.details:
_details = True
else:
_details = False
if args.verbose:
_more_details = True
else:
_more_details = False
if args.snapusage:
_SNAP_USAGE = True
else:
_SNAP_USAGE = False
try:
_sections = args.sections
except:
_sections = ['last', 'count', 'diff']
'''
--------------------------------------------------------------------------------
Generic, standalone functions
@@ -269,20 +201,22 @@ class davisDecoder(object):
def rainrate_decode(self, byte2, byte3):
# if byte3(b2 here) is 0xFF, or 255, there is not rain
print("b2:{} b3:{} = result:{}".format(byte2, byte3, byte2 + (byte3 >> 4 << 8)))
if byte2 == 255:
rainstate = 0
rainrate = 0
elif byte2 == 254:
rainstate = 1
rainrate = 0.1
else:
# light rain (rate in mm/h, time/clicks in seconds)
if (byte3 & 0x40) == 0:
rainstate = 1
time_between_clicks = ((byte3 & 0x30) / 16 * 250) + byte2
rainrate = 720 / (((byte3 & 0x30) / 16 * 250) + byte2)
# strong rain (rate in mm/h, time/clicks in seconds)
elif (byte3 & 0x40) == 0x40:
rainstate = 2
time_between_clicks = (((byte3 & 0x30) / 16 * 250) + byte2) / 16
rainrate = 11520 / (((byte3 & 0x30) / 16 * 250) + byte2)
rainstate = 2
if byte3 > 4:
rainrate = 720 / ((byte3 >> 4 << 8) + byte2)
else:
rainrate = 0
result = {"state": float(rainstate), "rate": float(rainrate)}
print(result)
return result
class DBwriter(object):
@@ -496,23 +430,26 @@ if '__main__':
# 0x5 -> Rain rate -> https://www.carluccio.de/
if davis_packet_id == '0x5':
rainrate_dict = davis_decoder.rainrate_decode(
davis_data['b3'],
davis_data['b4']
)
rainstate = rainrate_dict['state']
rainrate = rainrate_dict['rate']
influx_weather_write = davis_writer.construct(
influx_weather_write,
"rain",
{"value": float(rainrate_dict['state'])},
{"type": "rainstate"}
)
influx_weather_write = davis_writer.construct(
influx_weather_write,
"rain",
{"value": float(rainrate_dict['rate'])},
{"type": "rainrate"}
davis_data['b2'],
davis_data['b3']
)
if rainrate_dict:
rainstate = rainrate_dict['state']
rainrate = rainrate_dict['rate']
influx_weather_write = davis_writer.construct(
influx_weather_write,
"rain",
{"value": float(rainrate_dict['state'])},
{"type": "rainstate"}
)
influx_weather_write = davis_writer.construct(
influx_weather_write,
"rain",
{"value": float(rainrate_dict['rate'])},
{"type": "rainrate"}
)
else:
pass