This seems to be a topic that comes up frequently so apologies for adding to the tedium.
I am new to LoRa and TTN in general and I am looking for a little outside help to start trouble shooting.
Some Info:
I am using a LoPy 1.0r in both an Expansion Board 2 and PyTrack. All latest Firmware, LoPys are running the latest (1.12.0.b0 at time of writing)
Device added to Application on TTN
I allegedly can connect via ABP, though I am sceptical. I am just running the PyCom example found here and it does print some data out though it may likely be noise.
Europe Region (i.e. LoRa.EU868)
Device EUI, Application EUI and App Key have all been triple checked
My code is nothing fancy, just try to join and print a message on lora.has_joined() returning true.
from network import LoRa
import time
import binascii
# OTAA authentication parameters
# dev_eui = binascii.unhexlify('XXXXXXXXXXXXXXXX')
# app_eui = binascii.unhexlify('XXXXXXXXXXXXXXXX')
# app_key = binascii.unhexlify('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
# join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key, dev_eui), timeout=0)
# wait until the module has joined the network
while not lora.has_joined():
time.sleep(1)
print('Not yet joined...')
print('Joined!!')
Any suggestions for debugging would be greatly appreciated.
Sadly, in this case no previous thread has concluded with a solution that works for myself.
As far as I can tell the common reasons for not being able to connect are
Incorrect Device EUI, Application EUI or App Key
Incompatible Firmware
Not having registered the device on an Application (i.e. Dev EUI not provided to TTN)
Or the problem relates to setting the LoPy as a Nano Gateway and not a node in an application.
I have exhausted the above but to no avail. I failed to mention that my LoPys are running the latest (1.12.0.b0 at time of writing). I will edit that into my original post.
Had the same issue. And gave up, bought an IMST gateway. Now all is working well. The issue is in the gateway not the node as this works fine now.
What I experienced is that the OTAA only worked if I rebooted the LoPy gateway from the repl by uploading a new code (just make a little change in a comment line). In all other cases it was luck for it to work.
I guess Pycom should be aware of this issue by now.
Good luck!
Thanks @DeuxVis, I had accidentally left out the lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) line from the example code I will add that in to the original question.
With regard to the inclusion of the dev_eui, sadly it did not make a difference included or left out.
The original post had the EUI and Key lines commented out, this was just a typo during posting.
from network import LoRa
import time
import binascii
# OTAA authentication parameters
dev_eui = binascii.unhexlify('XXXXXXXXXXXXXXXX')
app_eui = binascii.unhexlify('XXXXXXXXXXXXXXXX')
app_key = binascii.unhexlify('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
# join a network using OTAA (Over the Air Activation)
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
# wait until the module has joined the network
while not lora.has_joined():
time.sleep(1)
print('Not yet joined...')
print('Joined!!')
If you have not already, I would run a firmware update on your device.
As part of the firmware update you should get the option to choose your LoRa region. This should mean you do not need to specify a region attribute when initialising the LoRa object, you may simply type something like lora = LoRa(mode=LoRa.LORAWAN)
At that stage, if you have double checked all relevant details, the last issue can only really be a lack of coverage.
What I would recommend, at that point, is to search and join your closest TTN Community.
Coverage is not guaranteed so it may be a case that you are out of range or just not turned on. You should be able to find the operator of your closest gateway and ask very, very nicely if you could bother them. This is my current situation.
After a little difficulty I have finally managed to get connected. It appears to be a combination of the local topography and the availability of TTN gateways in my area.
What has made is setting the data rate to 0 when trying to join. As I understand it, this is essentially setting the spreading factor to it’s farthest reach (i.e. SF 12) for the initially OTAA join request.
NB: this was not available in some earlier firmware for the LoPy. So, as always, make sure the firmware is up to date.
The time to join is a little erratic and can be anything from 20 - 120 seconds. This seems to go against the typical join time of around 5 - 10 seconds. Basically, your mileage may and probably will vary.
So, as it stands the simplest and best chance code for connecting to LoRaWAN gateways is:
from network import LoRa
import time
import binascii
# LoRa region will be set when you update the firmware
# it does not need to be explicitly stated
lora = LoRa(mode=LoRa.LORAWAN)
# OTAA authentication parameters
app_eui = binascii.unhexlify('XXXXXXXXXXXXXXXX')
app_key = binascii.unhexlify('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
# join a network using OTAA (Over the Air Activation)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0, dr=0)
# wait until the module has joined the network
while not lora.has_joined():
pass # no delays, just keeps looping until .has_joined() returns true
print('Joined!!')
Not stating the dev_eui will result in the .join() defaulting to the devices MAC, which is what the device will be registered with in a TTN application.
Beyond that, your checklist for connecting should still be: