Problem joining TTN in Australia with OTAA using a LoPy 4



  • Hi all,

    I am trying to use a LoPy 4 to connect to TTN using OTAA. I have done that multiple times with the LoPy, but can't manage to do it with the 4.

    I am in range of the Gateway (the LoPy can connect to TTN without any problem).

    The LoPy 4 is using the latest firmware and I am in Australia. The antenna is on the 915 port.

    Here is the sample code I am trying:

    from network import LoRa
    import binascii
    import time
    
    # Initialize LoRa in LORAWAN mode.
    lora = LoRa(mode=LoRa.LORAWAN)
    
    # credentials
    APP_EUI = 'XXXX'
    APP_KEY = 'YYYYYYY'
    
    print("Joining LoRa")
    
    # remove default channels
    for i in range(0, 72):
        lora.remove_channel(i)
    
    # adding the Australian channels
    print("add channels")
    for i in range(8, 15):
        lora.add_channel(i, frequency=915200000 + i * 200000, dr_min=0, dr_max=3)
        lora.add_channel(65, frequency=917500000, dr_min=4, dr_max=4)
    
    for i in range(0, 7):
        lora.add_channel(i, frequency=923300000 + i * 600000, dr_min=0, dr_max=3)
    
    # create an OTA authentication params
    app_eui = binascii.unhexlify(APP_EUI.replace(' ',''))
    app_key = binascii.unhexlify(APP_KEY.replace(' ',''))
    
    print("Joining")
    # join a network using OTAA if not previously done
    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():
        print("attempt...")
        time.sleep(2.5)
    

    For some reason, the last while is never reached (the "attempt" message is never printed), and I don't see any join packet in the TTN console. The code seems to be stuck in lora.join.

    Does anyone have an idea how I could solve this issue? Am I missing something?

    Thanks!

    Johan



  • @jmarcelino thanks for the clear explanation.
    It would be really useful if you could put this small section of code on the Getting Started section of Pycom's LoPy documentation for those who are connecting to TTN; the most popular LoRa network in Australia/New Zealand region. I will try and post something in The Things Network Australia Community page too.

    If you would prefer, I can raise it through GitHub, but I suspect your ability to change the Pycom documentation is much quicker!
    thanks again for your help Jose.
    Also, I really enjoyed your talk on The Things Network conference



  • @philwilkinson
    You almost always need to disable channels in US915 and AU915 because most commercial gateways only support listening on 8 channels out of the possible 72.

    In terms of TTN they have done this decision for you, see the subchannel map they propose: https://github.com/TheThingsNetwork/gateway-conf/blob/master/AU-global_conf.json

    916.8, 917.0, 917.2, 917.4, 917.6, 917.8, 918.0, 918.2

    But this is only true to TTN, other networks may use a different subset.

    We plan to document this better in the near future.



  • @jmarcelino said in Problem joining TTN in Australia with OTAA using a LoPy 4:

    You can now initialise lora with
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915)
    and it'll be set to the (also newly supported) Australian AU915 frequency map!
    (you'll still need to disable channels if you gateway only supports 8 out of the 72)
    This is also saved with lora.nvram_save() and nvram_restore()

    @jmarcelino I note your response to @jojo 's question mentioned the need to disable channels.

    "(you'll still need to disable channels if you gateway only supports 8 out of the 72)
    This is also saved with lora.nvram_save() and nvram_restore()"

    I have run the adjusted code :

    for i in range(16, 65):
    lora.remove_channel(i)
    for i in range(66, 72):
    lora.remove_channel(i)

    and the LoPy connects OK.

    Is this an issue with the gateway or are the full set of AU915 frequencies not covered by all gateways?
    The previous firmware for the LoPy ran fine with the same gateway.
    thanks in advance for any advice, Jose
    Phil



  • @jmarcelino

    Good morning!

    I can confirm it works very well! Thanks Pycom for your awesome work!

    Here is the code I use to join TTN in Australia, in case someone else face the same issue:

    from network import LoRa
    import binascii
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915, adr=False, tx_retries=0, device_class=LoRa.CLASS_A)
    # credentials
    APP_EUI = 'XXXXX'
    APP_KEY = 'YYYYYYYY'
    
    # remove some channels
    for i in range(16, 65):
        lora.remove_channel(i)
    for i in range(66, 72):
        lora.remove_channel(i)
    
    # create an OTA authentication params
    app_eui = binascii.unhexlify(APP_EUI.replace(' ',''))
    app_key = binascii.unhexlify(APP_KEY.replace(' ',''))
    
    print("Joining")
    # join a network using OTAA if not previously done
    lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
    

    Cheers,

    Johan



  • @rskoniec An announcement about it is coming momentarily



  • @jmarcelino Btw, is there a new version 1.16.0.b1? I couldn't find any info about it on forum.



  • @jojo I thought so, but I was not able to try this myself. :)



  • @jmarcelino

    Thanks for that! I'll try that first thing tomorrow morning and let you know how it goes :).



  • Hi @jojo,

    OK, I'm not sure why it's still on 868Mhz but fortunately you can use the new region setting functions!

    You can now initialise lora with

    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915)

    and it'll be set to the (also newly supported) Australian AU915 frequency map!
    (you'll still need to disable channels if you gateway only supports 8 out of the 72)

    This is also saved with lora.nvram_save() and nvram_restore()



  • @rskoniec

    That's right, I forgot to add the import time in the sample code, but that's not the issue here since the code is stuck at the join and does not reach the while loop :)

    I'll edit the code in the original post.

    Also the order of the 2 statements in the loop does not really matter.



  • @jmarcelino

    Hi Jose,

    I just did that, now the os.uname() returns:

    (sysname='LoPy4', nodename='LoPy4', release='1.16.0.b1', version='v1.8.6-849-055728a on 2018-02-13', machine='LoPy4 with ESP32', lorawan='1.0.0', sigfox='1.0.1')
    

    And lora.frequency() still returns 868000000 instead of 915000000. So I guess the region is still not right.



  • Add import time and try:

    while not lora.has_joined():
        time.sleep(2.5)
        print("attempt...")
    

    instead of:

    while not lora.has_joined():
        print("attempt...")
        time.sleep(2.5)
    

    Source: https://docs.pycom.io/chapter/firmwareapi/pycom/network/lora.html



  • @jojo
    Can you please try updating the firmware again, we had an issue with the very latest updates where the frequencies may have been set incorrectly.



  • Hi @jojo,

    Can you let me know which firmware version you're running please?

    Just send me the result of os.uname()

    Thanks.



Pycom on Twitter