📜 ⬆️ ⬇️

Testing of radio modems LoRa / LoRaWAN RN2483. Part 1, LoRa

One of the interesting technologies of the “Internet of Things” is the LoRa / LoRaWAN network, but they are practically not described in RuNet. It's time to fill this gap, and it is even more interesting to try “live” how it works.



What is LoRa?


This is a long range communication technology patented by Semtech and implemented in their SX1272 and SX1276 chips. LoRa is a low-level protocol over which higher-level protocols can be implemented, for example, LoRaWAN.
')
A feature of the LoRa standard is the transfer of small data packets with low power consumption. According to the manufacturer, the range in the open air can reach 10km, and the battery life can be several years. The operating frequencies depend on the country, and are 433 or 868 MHz (EU version) or 915 MHz (USA version).

How it works? Details under the cut.

The modules RN2483 were chosen for testing. They are good because they are easy to program and support different modes of operation. The RN2483 contains the SX1276 chip and a controller in a single package, controlled by UART commands, which allows you to connect it to any device (PC, Arduino, microcontroller, etc). You can buy a module without strapping, it is cheaper, but soldering was too lazy, so a set of a pair of ready-made boards was ordered on eBay.

This allows you to connect modules to your PC via USB, and to any device.

Data transfer


A simple Python program was written for transmission:
Source
import serial from time import sleep def deviceSend(device, cmd): try: print cmd device.write(cmd + "\r\n") line = device.readline() if line is not None and len(line) > 0: r = line.decode('utf-8').strip() print "> " +r return except Exception as e: pass if __name__ == "__main__": port = serial.Serial(port="COM20", baudrate=57600, timeout=5) deviceSend(port, "sys reset") sleep(2) deviceSend(port, "mac pause") deviceSend(port, "radio set freq 868000000") # Output power, -3..15 deviceSend(port, "radio set pwr -3") deviceSend(port, "radio set mod lora") # sf12, sf7 deviceSend(port, "radio set sf sf7") # Bandwidth: with 125KHz the sensitivity is better but time on air is longer. Chip is capable from 125KHz to 500KHz. deviceSend(port, "radio set bw 125") deviceSend(port, "radio tx 0123456789") sleep(0.5) line = port.readline() print line.strip() deviceSend(port, "mac resume") 


Let us analyze the main parameters in more detail.
pwr - power, can vary in the range -3..15dB
frequency - transmission frequency
mac pause - disable lorawan mode, transfer between two devices (p2p) is activated
tx - data packet
mod is a type of modulation. Available in 2 types, lora or fsk.
bw is the bandwidth of the spectrum, it can be 125, 250, 500 kHz.
sf - spread factor, affects the duration of the transfer.
This is the spectrum for sf7 and sf12 with the same amount of data.


As you can see, the data is transmitted in short blocks. The maximum packet size is no more than 255 bytes, after the transmission is completed, the modem confirms that the data has been sent.

Receiving data


For reception, you must set the same parameters as for transmission, otherwise the modems will not "hear" each other. The code is shown below, the program in the infinite loop "listens" to the data on the serial port.

Source
 import serial from time import sleep def deviceSend(device, cmd): try: print cmd device.write(cmd + "\r\n") line = device.readline() if line is not None and len(line) > 0: r = line.decode('utf-8').strip() print "> " +r return r except Exception as e: pass return "" if __name__ == "__main__": port = serial.Serial(port="COM20", baudrate=57600, timeout=5) deviceSend(port, "sys reset") sleep(2) deviceSend(port, "mac pause") deviceSend(port, "radio set freq 868000000") # Output power, -3..15dB deviceSend(port, "radio set pwr -3") deviceSend(port, "radio set mod lora") # sf12, sf7 deviceSend(port, "radio set sf sf7") # Bandwidth: with 125KHz the sensitivity is better but time on air is longer. Chip is capable from 125KHz to 500KHz. deviceSend(port, "radio set bw 125") # WDT: 5s wait for each data deviceSend(port, "radio set wdt 5000") print "Start listening" try: while True: ans = deviceSend(port, "radio rx 0") if ans == "ok": r = port.readline().strip() if r != "err" and len(r) > 0: print "> " + r # We need time to prepare RN2483 for the next receiving sleep(0.1) except KeyboardInterrupt: pass deviceSend(port, "mac resume") 


As you can see, everything is simple, and using a modem is no different from any other transmission over the serial port. The program code (with minor improvements) was launched on the Raspberry Pi, data reception can be seen on the screen.


There are a lot of different commands for setting up the RN2483, they can be found in the PDF "RR2903 LoRa Technology Module Command Reference User's Guide". For an approximate assessment of the result, you can also download the program Semtech Lora Calculator , which allows you to enter different settings (width of the spectrum, frequency, etc.) and see the result - bit rate, current consumption, battery life.

For example, the promised battery life of the SX1276 chip from a 1000 mAh battery will be about 30 days when transmitted in blocks of 8 bytes with an interval of 100 seconds and a power of 10dBm.

For practical testing of the range, one of the modems was left in the apartment by the window, the second was connected to the Raspberry Pi and brought to the street. Some sources promise a range in urban areas of about 3 km. The result, alas, is not so good: in practice, at maximum power and an antenna at 868 MHz, the signal is completely muffled after about 3 apartment buildings. Of course, in open places, the range is higher, but it is worth “turning the corner” as the signal disappears very quickly. In general, the result of 3 km in the city can probably be obtained unless you place the antenna on the TV tower, you can really count on 300m at best. But this is not so bad, given the low power of the transmitted signal.

Issue price


Information for those who want to repeat the experiments or use LoRa in their developments. The price of a set of 2x rn2483 modems ready for use on eBay is 80EUR. Separately, the module with the unsoldered SX1276 can be purchased from sellers from China for $ 12 with free shipping. The SX1276 chip without any strapping can be bought there for $ 9 (the code described in the article is only suitable for RN2483, when using the SX1276 chip, it will have to be programmed at a lower level).

findings


LoRa standard devices are a convenient and complete solution for low-speed transfer of small amounts of data over relatively large (hundreds of meters-kilometers) distances. LoRa devices are optimized for low power consumption, which allows them to be used with power from batteries or rechargeable batteries (however, the charge for this is a low data transfer rate). For example, if a farmer wants to display the temperature in greenhouses on a home display, this will be an almost ideal application for LoRa - small amounts of data, long distances, and direct visibility to objects. Modems can also be used in large rooms - hangars, factories, where it is difficult or expensive to pull the wire to the sensors, and the data volumes are small. It is possible to use at home, the high sensitivity of the modules will allow the use of even short antennas in the form of a "zigzag" on the printed circuit board. In the city, the quality of communication will strongly depend on the presence of radio visibility between antennas, the height of antenna placement, etc. Many are now strongly inspired by the capabilities of “global” LoraWAN networks, but the issue of antenna placement will be very critical for the range in such a network. However, this is true for any radio transmission systems, so the miracle did not happen here.

The next part will cover the connection of RN2483 to the LoRaWAN network.

More information can be found on the links:
- RN2483 datasheet
ww1.microchip.com/downloads/en/DeviceDoc/40001784B.pdf
- LoRa FAQ
www.link-labs.com/lora-faqs
- Semtech SX1272
www.semtech.com/wireless-rf/rf-transceivers/sx1272
- Semtech LoRa Calculator
www.semtech.com/apps/filedown/down.php?file=SX1272LoRaCalculatorSetup1%271.zip

Libraries for working with RN2483 on Raspberry Pi and Arduino can be found on github.

Source: https://habr.com/ru/post/398229/


All Articles