Rain rate MAYBE implemented correctly
This commit is contained in:
@@ -84,10 +84,6 @@ sys.path.append(_SCRIPT_PATH + "/home/pi/test/lib")
|
|||||||
'''
|
'''
|
||||||
_VERSION = 2.0
|
_VERSION = 2.0
|
||||||
_NAME = u"Vantage Vue Decoding shite"
|
_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
|
# finite loop implementation, tout for 43200 cycles
|
||||||
tout = 0
|
tout = 0
|
||||||
|
|
||||||
@@ -113,71 +109,7 @@ influx_pwd = 'freedavis'
|
|||||||
weather_db = 'weather_v2'
|
weather_db = 'weather_v2'
|
||||||
status_db = 'status'
|
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
|
Generic, standalone functions
|
||||||
@@ -269,20 +201,22 @@ class davisDecoder(object):
|
|||||||
|
|
||||||
def rainrate_decode(self, byte2, byte3):
|
def rainrate_decode(self, byte2, byte3):
|
||||||
# if byte3(b2 here) is 0xFF, or 255, there is not rain
|
# 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:
|
if byte2 == 255:
|
||||||
rainstate = 0
|
rainstate = 0
|
||||||
|
rainrate = 0
|
||||||
|
elif byte2 == 254:
|
||||||
|
rainstate = 1
|
||||||
|
rainrate = 0.1
|
||||||
else:
|
else:
|
||||||
# light rain (rate in mm/h, time/clicks in seconds)
|
rainstate = 2
|
||||||
if (byte3 & 0x40) == 0:
|
if byte3 > 4:
|
||||||
rainstate = 1
|
rainrate = 720 / ((byte3 >> 4 << 8) + byte2)
|
||||||
time_between_clicks = ((byte3 & 0x30) / 16 * 250) + byte2
|
else:
|
||||||
rainrate = 720 / (((byte3 & 0x30) / 16 * 250) + byte2)
|
rainrate = 0
|
||||||
# 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)
|
|
||||||
result = {"state": float(rainstate), "rate": float(rainrate)}
|
result = {"state": float(rainstate), "rate": float(rainrate)}
|
||||||
|
print(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class DBwriter(object):
|
class DBwriter(object):
|
||||||
@@ -496,23 +430,26 @@ if '__main__':
|
|||||||
# 0x5 -> Rain rate -> https://www.carluccio.de/
|
# 0x5 -> Rain rate -> https://www.carluccio.de/
|
||||||
if davis_packet_id == '0x5':
|
if davis_packet_id == '0x5':
|
||||||
rainrate_dict = davis_decoder.rainrate_decode(
|
rainrate_dict = davis_decoder.rainrate_decode(
|
||||||
davis_data['b3'],
|
davis_data['b2'],
|
||||||
davis_data['b4']
|
davis_data['b3']
|
||||||
)
|
|
||||||
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"}
|
|
||||||
)
|
)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user