Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def lora():
"""Instantiate Rak811 class though fixture."""
with patch('rak811.rak811.Rak811Serial', autospec=True):
rak811 = Rak811()
yield rak811
rak811.close()
def wake_up(ctx):
"""Wake up."""
lora = Rak811()
lora.wake_up()
if ctx.obj['VERBOSE']:
click.echo('Alive!')
lora.close()
\b
Without argument, returns:
frequency, sf, bw, cr, prlen, pwr
\b
Otherwhise set rf_config, Arguments are specified as KEY=VALUE pairs:
freq: frequency in MHz (860.000-929.900)
sf: strength factor (6-12)
bw: bandwidth (0:125KHz, 1:250KHz, 2:500KHz)
cr: coding rate (1:4/5, 2:4/6, 3:4/7, 4:4/8)
prlen: preamble length default (8-65535)
pwr: Tx power (5-20)
E.g.: rf-config freq=860.100 sf=7 pwr=16
"""
lora = Rak811()
config = dict(key_values)
if config == {}:
# No parameters: returns rc_config
config = lora.rf_config
if ctx.obj['VERBOSE']:
click.echo('Frequency: {}'.format(config['freq']))
click.echo('SF: {}'.format(config['sf']))
click.echo('BW: {}'.format(config['bw']))
click.echo('CR: {}'.format(config['cr']))
click.echo('PrLen: {}'.format(config['prlen']))
click.echo('Power: {}'.format(config['pwr']))
else:
click.echo('{} {} {} {} {} {}'.format(
config['freq'], config['sf'], config['bw'], config['cr'],
config['prlen'], config['pwr']
))
def join_otaa(ctx):
"""Join the configured network in OTAA mode."""
lora = Rak811()
try:
lora.join_otaa()
if ctx.obj['VERBOSE']:
click.echo('Joined in OTAA mode')
except Rak811Error as e:
print_exception(e)
lora.close()
def hard_reset(ctx):
"""Hardware reset of the module.
Hard reset should not be required in normal operation. It needs to be
issued once after host boot, or module restart.
"""
lora = Rak811()
lora.hard_reset()
if ctx.obj['VERBOSE']:
click.echo('Hard reset complete')
lora.close()
def link_cnt(ctx):
"""Get up & downlink counters."""
lora = Rak811()
(uplink, downlink) = lora.link_cnt
if ctx.obj['VERBOSE']:
click.echo('Uplink: {0} - Downlink: {1}'.format(uplink, downlink))
else:
click.echo('{} {}'.format(uplink, downlink))
lora.close()
def dr(ctx, dr):
"""Get/Set next send data rate."""
lora = Rak811()
if dr is None:
click.echo(lora.dr)
else:
try:
lora.dr = dr
if ctx.obj['VERBOSE']:
click.echo('Data rate set to {0}.'.format(dr))
except Rak811Error as e:
print_exception(e)
lora.close()
def rx_get(ctx, timeout, json):
"""Get LoraP2P message."""
lora = Rak811()
lora.rx_get(timeout)
if lora.nb_downlinks:
rx = lora.get_downlink()
rx['data'] = rx['data'].hex()
if json:
click.echo(dumps(rx, indent=4))
elif ctx.obj['VERBOSE']:
click.echo('Message received:')
if rx['rssi']:
click.echo('RSSI: {}'.format(rx['rssi']))
click.echo('SNR: {}'.format(rx['snr']))
click.echo('Data: {}'.format(rx['data']))
else:
click.echo(rx['data'])
elif ctx.obj['VERBOSE']:
click.echo('No message available.')
def clear_radio_status(ctx):
"""Clear radio statistics."""
lora = Rak811()
lora.clear_radio_status()
if ctx.obj['VERBOSE']:
click.echo('Radio statistics cleared.')
lora.close()
def version(ctx):
"""Get module version."""
lora = Rak811()
click.echo(lora.version)
lora.close()