Building a LoRaWAN Nano Gateway to The Things Network

Chris just shared a new tutorial: "Building a LoRaWAN Nano Gateway to The Things Network"



In this article we’ll see how to build a Nano Gateway to The Things Network (TTN) using a Pycom device with LoRa: a LoPy4 or a FiPy.
When you build an IoT project using LoRaWAN you only want to worry about two things: your IoT devices and the I…

Read more

I’ve just been setting up the Nano gateway tutorial - looks as though it has configured/connected to TTN OK, but I’m having trouble getting an OTAA join. Have tried changing the DR to 3 as this is what gets sent from my device. Any other advice? TIA

OK I’ve got it working with ABP rather than OTAA. Does the Nano gateway software support both?

Hi Andrew,

It should be able to work with both. Have you followed the directions in our The Things Network Tutorials section? The Getting Started with The Things Network Tutorial has instructions on how to connect using OTAA with some example code. I haven’t tried connecting with ABP personally but I have taken a look over the code and there are some differences.

I’m pretty sure I’ve set up correctly. My code worked using the Sentrius gateway. So as far as I know at this stage it seems to be something in the Nano gateway code. I can connect from my Sodaq device using ABP but not OTAA. It’s giving a “join not accepted: denied” error code with ttn.showStatus().

Hi Andrew,

Full directions for setting up a nano Gateway and connecting view ABP and OTAA can be found here:
https://docs.pycom.io/tutorials-and-examples/lora/lorawan-nano-gateway

You can connect via OTAA to a nano Gateway using this code (change your eui and key as needed):

""" OTAA Node example compatible with the LoPy Nano Gateway """

​

from network import LoRa

import socket

import ubinascii

import struct

import time

​

# Initialize LoRa in LORAWAN mode.

lora = LoRa(mode=LoRa.LORAWAN)

​

# create an OTA authentication params

dev_eui = ubinascii.unhexlify('AABBCCDDEEFF7778') # these settings can be found from TTN

app_eui = ubinascii.unhexlify('70B3D57EF0003BFD') # these settings can be found from TTN

app_key = ubinascii.unhexlify('36AB7625FE77776881683B495300FFD6') # these settings can be found from TTN

​

# set the 3 default channels to the same frequency (must be before sending the OTAA join request)

lora.add_channel(0, frequency=868100000, dr_min=0, dr_max=5)

lora.add_channel(1, frequency=868100000, dr_min=0, dr_max=5)

lora.add_channel(2, frequency=868100000, dr_min=0, dr_max=5)

​

# join a network using OTAA

lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)

​

# wait until the module has joined the network

while not lora.has_joined():

time.sleep(2.5)

print('Not joined yet...')

​

# remove all the non-default channels

for i in range(3, 16):

lora.remove_channel(i)

​

# create a LoRa socket

s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

​

# set the LoRaWAN data rate

s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)

​

# make the socket non-blocking

s.setblocking(False)

​

time.sleep(5.0)

​

""" Your own code can be written below! """

​

for i in range (200):

s.send(b'PKT #' + bytes([i]))

time.sleep(4)

rx = s.recv(256)

if rx:

print(rx)

time.sleep(6)

I’ve never been able to get OTAA to work in this region. ABP works just fine though.

You’d be much better off using a full-fledged gateway, that supports all 8-channels and doesn’t miss a beat

Pycom LoPy4 is best suited as a node; the fact that it can be used as a nano-gateway was a “just for fun” experiment that we did a long while ago and shared :slight_smile:

ah I was just writing a response when these messages came through. Yes, the Sentrius gateway works well. The Nano gateway seems OK using ABP although TTN seems a bit iffy in picking up the transmissions - seems to register some but not all.

The missing transmissions are likely a miss-configuration on the node you are using. Every packet, the channel will increment. If not configured to only use 3 channels on the node as well, then 3 in 8 packets will be seen.

OK thanks - I’ve seen some code to switch off channels so I will incorporate that.

On further investigation, I’d like some advice. The code I’ve seen uses different libraries from the TTN one. My Serial output reports as follows.

Sending: mac set ch status 0 off
Sending: mac set ch status 1 off
Sending: mac set ch status 2 off
Sending: mac set ch status 3 off
Sending: mac set ch status 4 off
Sending: mac set ch status 5 off
Sending: mac set ch status 6 off
Sending: mac set ch status 7 off
Sending: mac set ch status 8 on
Sending: mac set ch drrange 8 0 3
Sending: mac set ch status 9 on
Sending: mac set ch drrange 9 0 3
Sending: mac set ch status 10 on
Sending: mac set ch drrange 10 0 3
Sending: mac set ch status 11 on
Sending: mac set ch drrange 11 0 3
Sending: mac set ch status 12 on
Sending: mac set ch drrange 12 0 3
Sending: mac set ch status 13 on
Sending: mac set ch drrange 13 0 3
Sending: mac set ch status 14 on
Sending: mac set ch drrange 14 0 3
Sending: mac set ch status 15 on
Sending: mac set ch drrange 15 0 3
Sending: mac set ch status 16 off

So I’m assuming I should send mac set ch status 8-15 (and 65) off. And then ch 0-2 on. Then
mac set ch freq 0 (also 1 and 2) 916800000.
Is this correct?

Not sure sorry - I tend to stick with full 8-channel LoRaWAN hardware to avoid all the workarounds!

Hi Chris, Bought the kit (FiPy & LoPy4) from you including the antennas - I am trying to setup a LoRaWan network for myself where i can monitor my own devices. Alternately using the LoRaWAN to the things network to get going and then develop a “gateway” (WebService) of my own. Your advice would be helpful for me to set things up quickly. Thanks Olly

Hi,

This was just a quick demo of an interesting way to use LoPy4. The guide works fine as-is, you are welcome to follow it as it’s written.

However, you will face challenges as noted here and in the guide: it’s a 3-channel gateway. AS915 is hard. Nodes need to be customised to work with a nano gateway.

If you’d like to use LoRaWAN, fully, then consider getting a LoRaWAN Gateway if there is no coverage in your area and skip tinkering with a nano-gateway.

Fyi, I’ve also added a warning to the top of this article to help clear the air on nano-gateway + TTN. Nano-gateways are a whole lot of fun and very low cost. Though there are some methods you need to follow as noted in the guide in order for everything to work.

Graham - thanks for your reply. I am going to invest in a LoRaWan gateway recommended by you.
How can I form a “node” and a subscriber community here in the RYDE area? Will it help the community and should it be something I should “secure” so it is nor misused? Any advice would be helpful.
I should be able to place the order on the weekend for the unit. I will still need help to get it up and running - any ideas - knowing how busy you guys are.
Regards
Olly

Hi Graham - any “overview” of the LoRaWAN setup you guys are fostering in Newcastle?
Thanks
Olly

@Chris, hi, i am using lopy4 as gateway and with SF7BW125 works ok, but when i try to use it with SF12BW125 i can’t receive downlinks, i have checked in the terminal the messages of the gateway and with SF7 it sends a downlink at 868.1Mhz and SF7BW125, but when i change to SF12 it sends a downlink at 869.525Mhz and SF9BW125 so i don’t know if i need to modify something in the gateway in order that it sends the downlink in 868.1Mhz and SF12BW125 when is configured with SF12 or i must modify the node?, thanks