How to use the rak811.Mode.LoRaP2P function in rak811

To help you get started, we’ve selected a few rak811 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AmedeeBulle / pyrak811 / rak811 / cli.py View on Github external
def mode(ctx, mode):
    """Get/Set mode to LoRaWan or LoRaP2P."""
    lora = Rak811()
    if mode is None:
        click.echo('LoRaWan' if lora.mode == Mode.LoRaWan else 'LoRaP2P')
    else:
        mode = mode.lower()
        if mode == 'lorawan':
            lora.mode = Mode.LoRaWan
        else:
            lora.mode = Mode.LoRaP2P
        if ctx.obj['VERBOSE']:
            click.echo('Mode set to {0}.'.format(
                'LoRaWan' if mode == 'lorawan' else 'LoRaP2P'))
    lora.close()
github AmedeeBulle / pyrak811 / examples / p2p.py View on Github external
from rak811 import Mode, Rak811

# Send packet every P2P_BASE + (0..P2P_RANDOM) seconds
P2P_BASE = 30
P2P_RANDOM = 60

# Magic key to recognize our messages
P2P_MAGIC = b'\xca\xfe'

lora = Rak811()

# Most of the setup should happen only once...
print('Setup')
lora.hard_reset()
lora.mode = Mode.LoRaP2P

# RF configuration
# - Avoid LoRaWan channels (You will get quite a lot of spurious packets!)
# - Respect local regulation (frequency, power, duty cycle)
lora.rf_config = {
    'sf': 7,
    'freq': 869.800,
    'pwr': 16
}

print('Entering send/receive loop')
counter = 0
try:
    while True:
        # Calculate next message send timestamp
        next_send = time() + P2P_BASE + randint(0, P2P_RANDOM)