One of the critical components in LoRa networks is the LoRaWAN gateway, which plays an important role in connecting Sensors and Nodes to servers. In this tutorial, we will build a cheap LoRaWAN Gateway with the help of Seeed Studio WM1302 LoRaWAN Gateway Module. Stay with me.
What is a LoRaWAN Gateway?
There is a lot to unpack when exploring connectivity options for the Internet of Things. One critically important element of a successful IoT network is the gateway.
Let’s start with a definition of LoRaWAN: LoRa (Long Range) is a low-power wide-area network LPWAN protocol developed by Semtech. It is one of a number of radio frequency technologies used to wirelessly connect sensors and devices for the Internet of Things (IoT) in different types of industries.
A gateway typically refers to the physical box or encasement housing the hardware and application software that performs essential tasks to connect IoT devices to the cloud. IoT devices use a gateway as a central hub to drop sensed knowledge and connect that data to external networks. A gateway is much like a Wi-Fi router. It has a LoRa concentrator, allowing it to receive RF signals sent out by LoRaWAN devices, which get converted to a signal compatible with a server, such as Wi-Fi, to send data to the cloud.
A gateway is a jumping-off point as all the devices on the network have to be able to transmit their data back to the gateway. This often means large scale LoRaWAN systems run on more than one gateway.
The maximum number of sensors or devices per gateway depends on a number of factors such as data rate and data packet size but hundreds or even low thousands per gateway is achievable.
Gateways are a crucial component to running efficient wireless networks for sensors and devices.
WM1302 LoRaWAN Gateway ModuleWM1302 module is a new generation of LoRaWAN gateway module with mini-PCIe form-factor. Based on the Semtech® SX1302 baseband LoRaWAN® chip, WM1302 unlocks the greater potential capacity of long-range wireless transmission for gateway products. It features higher sensitivity, less power consumption, and lower operating temperature than the previous SX1301 and SX1308 LoRa® chips.
WM1302 LoRaWAN gateway module has SPI and USB versions on both US915 and EU868 frequency bands, enable you to have a wide-range of LoRaWAN frequency plans options to choose including EU868, US915, AS923, AS920, AU915, KR920 and IN865.
WM1302 is designed for M2M and IoT applications and can be widely applied in LPWAN gateway supported scenarios. It would be a perfect choice for you to significantly reduce the technical difficulties and time-consumption when developing the LoRa gateway devices, including LoRaWAN gateway, miner hotspots, etc.
Hardware PreparationTo start work, we need to prepare the required hardware. In short, we want to connect WM1302 LoRaWAN Gateway Module by WM1302 Raspberry Pi Hat or Mini PCI-E to USB Adapter via USB connection to a Linux computer or an SBC (Raspberry Pi and etc).
âš The important thing you should pay attention to is that you must get the USB version when you buy WM1302 LoRaWAN Gateway Module.
âš Before connecting the interface to the computer, make sure that the antenna is connected to the WM1302 module.
âš When buying WM1302 LoRaWAN Gateway Module, pay attention to its working frequency and choose it according to your country of residence.
In this tutorial, the goal is to connect WM1302 LoRaWAN Gateway Module to PC or SBC via USB. This feature makes it possible to launch the LoRaWAN gateway even through a normal computer with Linux or even Windows operating system (via Docker).
âš I tested on a computer with Ubuntu distribution and it worked without problems.
If you are using WM1302 Raspberry Pi Hat, connect to the PC through the Type-C port.
For WM1302 LoRaWAN Gateway Module SPI version, the Semtech SX1302 and SX126x chip are conntected to Raspberry Pi via the same SPI bus with different chip select (CS) pin.
For WM1302 LoRaWAN Gateway Module USB version, the Semtech SX1302 and SX126x chip are conntected to a STM32L4 MCU, and this factory programmed MCU will work as a USB device, becoming a bridge between Raspberry Pi and SX1302/SX126x.
One of the important programs offered by Semtech for setting up the gateway is Packet Forwarder. The Packet Forwarder is the software that provides the core functionality of a LoRaWAN Gateway and defines the method of that is used to receive LR packets and transmit them to the network server. For example, the Semtech UDP Packet Forwarder is the original LoRaWAN packet forwarder, and uses the Semtech UDP protocol for transmission. Today, most gateways include a pre-compiled version of the Semtech UDP Packet Forwarder, often adapted to the specific gateway. Another popular packet forwarding protocol is MQTT which is used with the popular Chirpstack server infrastructure. This program can be run by default in Linux operating system. Of course, LoRa Basics Station can also be used.
âš If you are using a Raspberry Pi, make sure I2C and SPI are enabled before proceeding.
Enable the Raspbian I2C and SPI interfaceWM1302 module communicates with Raspberry Pi with SPI and I2C. But these two interfaces are not enabled by default in Raspbian, so developer need to enable them before using WM1302. For Raspberry Pi, enter the settings in the command line with the sudo raspi-config
command.
And follow the steps below:
1. Select Interface Options
2. Select SPI, then select Yes to enable it
3. Select I2C, then select Yes to enable it
4. Select Serial Port, then select No for "Would you like a login shell..." and select Yes for "Would you like the serial port hardware..."
5. After this, please reboot Raspberry Pi to make sure these settings work.
Resource
Get and compile LoRa SX1302 concentratorNow you need to install git
first, then download sx1302_hal
with the following commands:
sudo apt-get update
sudo apt-get install -y git
cd ~
git clone https://github.com/Lora-net/sx1302_hal
cd ~/sx1302_hal
make
Then modify reset pin
for SX1302 and SX1261 in reset_lgw.sh
script, with text editor nano
:
nano tools/reset_lgw.sh
The following code is shown at the head of text editor:
# GPIO mapping has to be adapted with HW
SX1302_RESET_PIN=23 # SX1302 reset
SX1302_POWER_EN_PIN=18 # SX1302 power enable
SX1261_RESET_PIN=22 # SX1261 reset (LBT / Spectral Scan)
AD5338R_RESET_PIN=13 # AD5338R reset (full-duplex CN490 reference design)
Use the navigation keys to move the cursor, change SX1302_RESET_PIN=23
to SX1302_RESET_PIN=17
and SX1261_RESET_PIN=22
to SX1261_RESET_PIN=5
, as following:
# GPIO mapping has to be adapted with HW
SX1302_RESET_PIN=17 # SX1302 reset
SX1302_POWER_EN_PIN=18 # SX1302 power enable
SX1261_RESET_PIN=5 # SX1261 reset (LBT / Spectral Scan)
AD5338R_RESET_PIN=13 # AD5338R reset (full-duplex CN490 reference design)
Save these changes by pressing CTRL + x
, and then y
, finally pressing Enter
to close the text editor.
in the end, copy reset_lgw.sh
to packet_forwarder
folder.
Before running lora_pkt_fwd
, you need to send LoRa packets to the LoRa TTN Server
, there is still work to be done. To achieve this target, you must add the Raspberry Pi Gateway to LoRa Server first. Take TTNv3 as an example, login TTNv3 console, click Go to gateways
and click Add gateway
, in the Add gateway
page you will find dozens of settings to fill. What you need to focus on are Gateway EUI
and Gateway Server address
and Frequency plan
, the others just leave it to the default.
Gateway EUI
: A 64 bit extended unique identifier for your gateway, we set it toAA555A0000000000
. Of course, please note that you can get the EUI by running the program in theutil_chip_id
folder.Gateway Server address
: The server addresss which gateway will connect to, copy this to clipboard, developers need to save this to the config file later.Frequency plan
: If using EU868 module, chooseEurope 863-870 MHz (SF9 for RX2)
, if using US915 module, chooseUnited States 902-928 MHz, FSB 2
After adding gateway, back to the Raspberry Pi, then edit the global_conf.json.sx1250.xxxx
config file you used just now, with text editor nano
:
# Please select one of the following comands based on your module
# for WM1302 LoRaWAN Gateway Module (SPI) - EU868
nano global_conf.json.sx1250.EU868
# for WM1302 LoRaWAN Gateway Module (USB) - EU868
nano global_conf.json.sx1250.EU868.USB
# for WM1302 LoRaWAN Gateway Module (SPI) - US915
nano global_conf.json.sx1250.US915
# for WM1302 LoRaWAN Gateway Module (USB) - US915
nano global_conf.json.sx1250.US915.USB
Basically, you only need to modify these parameters: "server_address" "serv_port_up" "serv_port_down"
, which can be found at the at the beginning of the config file. Copy Gateway Server address
to "server_address"
, change "serv_port_up"
and "serv_port_down"
to 1700
, these parameters should be edited like this:
"gateway_conf": {
"gateway_ID": "AA555A0000000000",
/* change with default server address/ports */
"server_address": "eu1.cloud.thethings.network",
"serv_port_up": 1700,
"serv_port_down": 1700,
Save these changes by pressing CTRL + x
, and then y
, finally pressing Enter
to close the text editor.
Now run lora_pkt_fwd
according to the frequency and type of your module.
# Please select one of the following comands based on your module
# for WM1302 LoRaWAN Gateway Module (SPI) - EU868
./lora_pkt_fwd -c global_conf.json.sx1250.EU868
# for WM1302 LoRaWAN Gateway Module (USB) - EU868
./lora_pkt_fwd -c global_conf.json.sx1250.EU868.USB
# for WM1302 LoRaWAN Gateway Module (SPI) - US915
./lora_pkt_fwd -c global_conf.json.sx1250.US915
# for WM1302 LoRaWAN Gateway Module (USB) - US915
./lora_pkt_fwd -c global_conf.json.sx1250.US915.USB
Because my module was USB, I ran the following command:
./lora_pkt_fwd -c global_conf.json.sx1250.EU868.USB
If everything went well, your LoRaWAN Gateway will now be connected to TTNv3.
Finally, as a suggestion, you can also use Raspberry Pi Zero to make a pocket LoRaWAN Gateway.
This tutorial was prepared with a lot of help from Meilily Li and Alison Yang.
Comments