8 Capturing LoRa signals using an RTL SDR device
rpp0 edytuje tę stronę 2017-09-29 14:13:34 +02:00

This tutorial is intended for Software Defined Radio (SDR) beginners wishing to decode LoRa messages using gr-lora. We will be using a LoRa modem under our control in order to transmit messages, and an RTL-SDR to receive and display them back to the command line or Wireshark.

Prerequisites

Setup

As the first step we will build the GRC flow graph. Create a new flowgraph by selecting File > New > WX GUI. You can optionally set a name for the flowgraph by setting the ID field of the Options block.

Since we're using an RTL-SDR, drag the RTL-SDR Source block from the block tree panel to the grid view. Create a variable capture_freq and set it to 868e6 (868 MHz). Now configure the RTL-SDR block to use capture_freq as its Ch0 Frequency, and set the samp_rate variable to 1e6 (1 Msps). Finally, connect a WX GUI FFT Sink block to the RTL-SDR Source block for now, and set Baseband Freq to capture_freq. The flowgraph now looks like this:

RTL-SDR setup

You can verify whether the LoRa modem is working correctly by transmitting a message at 868.1 MHz. If you have an RN2483 connected via serial over USB, you can do the following:

$ python
>>> from loranode import RN2483Controller
>>> c = RN2483Controller("/dev/ttyUSB0")  # Choose the correct /dev device here
>>> c.set_sf(7)  # Set spreading factor 7
>>> c.set_cr("4/8")  # Set 4/8 coding
>>> c.send_p2p("00ff00ff")

A LoRa signal should appear centered at 868.1 MHz in the FFT plot during the transmission (see the red line in the figure below). However, depending on the quality of the RTL-SDR, antenna, and transmitter, the signal may be distorted with a frequency offset. gr-lora can automatically correct offsets of +-15 KHz, but for my RTL-SDR setup, the signal appears centered at 868.074. Hence, the offset is -26 KHz, and we ideally need to correct for at least 11 KHz. Create a variable named offset and set it to the offset that you observe for your setup (e.g. -26e3). For more expensive SDRs such as the HackRF and USRP, this step is usually not needed.

RTL-SDR setup

Configure gr-lora

It is now time to set up the receiver. Drag the LoRa Receiver block to the grid view and configure it so that it matches the transmitter's configuration:

  • Spreading factor: 7
  • Sample rate: samp_rate
  • Frequency: capture_freq
  • Channel list: [868.1e6 + offset]

The flowgraph now looks like this:

gr-lora setup

Run the flowgraph

Finally, run the flowgraph and transmit a message with the LoRa device.

>>> c.send_p2p("48656c6c6f2c2067722d6c6f726121")

The output should be printed to the terminal as shown below:

Decoded LoRa message

Here, we can observe a 3-byte header followed by the payload bytes.

Passing data to other applications

In order to process the received LoRa data further, a Message Socket Sink can be used to transmit UDP messages to localhost port 40868. To do so, drag the Message Socket Sink block to the grid view and connect the frames output of the LoRa Receiver to it. After restarting the application, we can observe the received payload in Wireshark:

LoRa message in Wireshark