LoRaWAN connector

class whad.lorawan.connector.LoRaWAN(device: ~whad.device.WhadDevice = None, channel_plan: ~whad.lorawan.channel.ChannelPlan = <class 'whad.lorawan.channel.EU868'>)[source]

Basic LoRaWAN connector to use with a LoRa compatible hardware.

This connector provides the basic features to send and receive LoRaWAN packets with a specific channel plan.

__init__(device: ~whad.device.WhadDevice = None, channel_plan: ~whad.lorawan.channel.ChannelPlan = <class 'whad.lorawan.channel.EU868'>)[source]

Initialize this LoRaWAN connector.

Parameters:
join(app_key: bytes, app_eui: str, dev_eui: str, dev_nonce: int)[source]

Perform an OTAA join procedure

See section 6.2.1 from LoRaWAN Specifications version 1.1

Parameters:
  • app_key (bytes) – Application key

  • app_eui (str) – Application EUI

  • dev_eui (str) – Device EUI

  • dev_nonce (str) – Device nonce

on_packet(packet: PHYPayload)[source]

Callback method for incoming packet processing

Parameters:

packet (whad.scapy.layers.lorawan.PHYPayload) – Received packet

reconfigure(channel: ChannelModParams, crc: bool = True, invert_iq: bool = False)[source]

Reconfigure hardware with provided parameters.

Parameters:
  • channel (whad.lorawan.channel.ChannelModParams) – Target channel modulation parameters.

  • crc (bool, optional) – Enable CRC if set to True, disabled if set to False

  • invert_iq (bool, optional) – Invert IQ if set to True

rx1()[source]

Configure hardware to listen on RX1.

RX1 channel is chosen depending on the channel plan.

rx2()[source]

Configure hardware to listen on RX2.

RX2 channel is usually a single channel with more reliable modulation parameters used as a backup channel for downlink communication.

send(packet, timestamp: float = None)[source]

Send a LoRaWAN frame with current LoRa modulation parameters.

Parameters:
  • packet (whad.scapy.layers.lorawan.PHYPayload) – Packet to send

  • timestamp (float, optional) – If provided, will send the packet at the given timestamp

start(coding_rate: int = 45)[source]

Start the LoRaWAN adapter into receive mode by default.

stop()[source]

Stop the LoRaWAN adapter.

Configure hardware to transmit on a random uplink channel.

A random uplink channel is picked from the ones defined in the channel plan, and hardware is reconfigured to listen and send on the corresponding frequency with the associated modulation parameters.

wait_packet(timeout: float = None)[source]

Wait for a LoRaWAN packet.

If timeout is set, wait for the given time and return None if no packet has been received. If timeout is not provided, this method will block until a valid packet is received.

Parameters:

timeout (float, optional) – Timeout in seconds