TTN via Nano Gateway in AU915 Region fails on OTAA

  • Hey Guys, I've been working through everything I can find on the forum. Eventually ran into Leo Gaggl's blog: I haven't yet successfully connected to TTN using my Nano Gateway. The Node reports "Trying to join TTN Network!" and never proceeds past that. TTN console shows the node has never connected. If I configure a node with ABP, no problems. Connects, uplinks, downlinks, sweet. Thanks in advance for any help. Chris.

    Full code here:

    Build record for this project

    (sysname='FiPy', nodename='FiPy', release='1.18.0', version='v1.8.6-849-046b350 on 2018-06-01', machine='FiPy with ESP32', lorawan='1.0.2', sigfox='1.0.1')

    1. Download latest
    2. Extract examples\lorawan-nano-gateway
    3. Delete 4x -node- files (tried, failed)
    4. Change lorawan-nano-gateway\, lines marked # CMM
    5. Comment out # for EU868 settings
      Replace with settings for AU as annotated
    6. Uploaded. Started. TTN Console shows Gateway online.
    [     2.355] Starting LoRaWAN nano gateway with id: b'30AEA4FFFE2CF7C4'
    [     6.778] WiFi connected to: IoT
    [     6.783] Syncing time with ...
    [     6.888] RTC NTP sync complete
    [     6.908] Opening UDP socket to ( port 1700...
    [     6.920] Setting up the LoRa radio at 916.7999 Mhz using SF7BW125
    [     6.929] LoRaWAN nano gateway online
    [     6.933] You may now press ENTER to enter the REPL
    [    56.935] Pull ack
    [    66.940] Push ack
    [    81.939] Pull ack
    [   106.939] Pull ack

    (sysname='LoPy4', nodename='LoPy4', release='1.18.0', version='v1.8.6-849-046b350 on 2018-06-01', machine='LoPy4 with ESP32', lorawan='1.0.2', sigfox='1.0.1')

    1. Create lorawan-nano-node folder
    2. Create from Growing Data Foundation:
    3. Set app_eui, app_key from TTN's Application EUI, App Key
    >>> Running Z:\Content\Content2\Chris\Pycom\Pycom LoRaWAN\Code for Forum\lorawan-nano-node\
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!

    (never shows status online)

    Shared as:

  • @bed Approach confirmed for the EU868 region. Unless you limit the node to 1 channel, you will loose packets at the nanogateway. Note, that using OTAA join the network server may supply a new channel list, which will then be used by the node, even if you reduced the number of channels to 1 before the join. You have to repeat that channel delete again after joining.

  • @bed Appreciated Brian. I've had my head in the C code over the weekend looking for a LoRa.get_channel() or similar. No luck.

    I'll take your advice and carefully configure a single channel. Right now I'm working out why my GPy no longer connectes to Telstra on Cat-M1!

    Ta, Chris.

  • @prawnhead Hi - I've not used the nano gateway - just Multitech and TTN gateways.

    But, from my understanding of the hardware, the nano gateway will only listen on 1 channel (916.8MHz as you've set it up). That's all good, but you must then tell the node to ONLY use that one channel. Else it will be transmitting on other channels some of the time, which will be missed.

    So, I'm thinking that in either ABP or OTAA, that only the 1 channel should be set up in the node. All others should be removed. Also make sure that you use the correct data rate for the single channel that is left so that when you transmit it will actually use the channel. OTAA should be fine with only 1 channel setup.

    Unfortunately, with how the pycom code interacts with the LoRaWAN stack code, it's difficult to pass errors back to the caller. I would like to see a change, eventually, where an error is passed back if there are no channels setup for transmission, when you do the send. I've been caught out on that a couple of times :)


  • @robert-hh Thanks Robert, I have tried today to migrate working ABP code over to OTAA. No dice. Likewise taking working OTAA code for EU868 and migrating that to AU915.

    There is something going on with OTAA in AU915 that I don't understand. It must be something to do with AU915's use of the second sub-band that makes it unique.

    If I:

    • Use current code from Pycom's lorawan-nano-gateway example,
    • Reinstall firmware on all devices with 1.18.0 and set LoRa.Region = AU915 in firmware
    • select 916.8 MHz as the nano gateway's frequency
    • on the node, remove 72 channels and add the first three channels on the gateway's frequency

    Then I can run nodes with ABP and have full functionality. If I switch from ABP to OTAA then I have no functionality. The first packet out of the node (auth request) is never seen at the nano gateway.

    Likewise, if I:

    • Stand up a node and a nano gateway using Pycom's lorawan-nano-gateway
    • Reflash firmwares to 1.18.0 and select EU868 region
    • Leave the code on OTAA
    • Configure TTN to match

    I have full OTAA functionality. Request, confirm, acknowledge, uplink, downlink, its great. Still mystified why this doesn't work for AU915.

    Apologies if this is poor forum etiquette, but can I ask @jmarcelino or @daniel if you guys have any pointers here? Is there a working nano gateway configuration for AU915 please?

    Thanks in advance. Appreciate it! Chris.

  • @prawnhead So you gateway is listening at 916800000 Hz, and in the ABP script that is the only channel you allow. You have to do the same for OTAA, otherwise the gateway will not see the messages.

  • @robert-hh That's a negative. Not seeing uplink or downlink packets on the gateway as the OTAA node is joining. In ABP mode, gateway shows uplink and downlink packets (downlink not documented below) as they occur.

    Nano Gateway

    import machine
    import ubinascii
    WIFI_MAC = ubinascii.hexlify(machine.unique_id()).upper()
    # Set  the Gateway ID to be the first 3 bytes of MAC address + 'FFFE' + last 3 bytes of MAC address
    GATEWAY_ID = WIFI_MAC[:6] + "FFFE" + WIFI_MAC[6:12]
    SERVER = ''  # CMM
    PORT = 1700
    NTP = ""                 # CMM
    NTP_PERIOD_S = 3600
    # for AU915                     # Block added CMM
    # How did I pick these values?
    # Looking at the configurations in this file of EU868 & US916, linked below:
    # both specify LORA_FREQUENCY and LORA_GW_DR as the first uplink channel.
    # So choose the same for AU915. LORA_NODE_DR is not used by
    LORA_FREQUENCY = 916800000
    LORA_GW_DR = "SF7BW125"
    LORA_NODE_DR = 4

    ABP Mode
    Node Code

    """ ABP Node example compatible with the LoPy Nano Gateway """
    from network import LoRa
    import socket
    import binascii
    import struct
    import time
    import pycom
    print("Node1: RED")
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915)
    # create an ABP authentication params
    dev_addr = struct.unpack(">l", binascii.unhexlify('26021AFC'))[0] # these settings can be found from TTN
    nwk_swkey = binascii.unhexlify('073892B1631EAABB45BB786656BDE1AB') # these settings can be found from TTN
    app_swkey = binascii.unhexlify('A3AB8F56D96EEE0ED79A0CE982617614') # these settings can be found from TTN
    # join a network using ABP (Activation By Personalization)
    lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
    # There are 72 channels
    # To set up a new channel plan we first remove all of them
    print("Removing all channels ", end='')
    for i in range(0, 72):
        print("{}, ".format(i), end='')
    print(" OK")
    # Then we create only the channels we want.
    # It shouldn't be necessary to set up more than one channel. See:
    lora.add_channel(0, frequency=916800000, dr_min=0, dr_max=5)
    # 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
    """ Your own code can be written below! """
        uplink_bytes = struct.pack("B", 1)
        print("Sending: {}".format(uplink_bytes))
        # Pull data back, if any
        downlink_bytes = s.recv(256)
        if downlink_bytes:
            downlink_data = struct.unpack("B", downlink_bytes)
            print("\nDownlink Message: {}".format(downlink_bytes))
            if downlink_data[0] == 0:
                print("Switch LED off")
            if downlink_data[0] == 1:
                print("Switch LED on")

    Node output

    Node1: RED
    Removing all channels 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,  OK
    Sending: b'\x01'
    Sending: b'\x01'

    Simultaneous output from Gateway

    [   396.298] Pull ack
    [   406.308] Push ack
    [   419.756] Received packet: {"rxpk": [{"data": "QPwaAiYAAAACGx0+4xI=", "time": "2018-06-14T22:09:46.807312Z", "chan":0, "tmst": 380380320, "stat": 1, "modu": "LORA", "lsnr": 6.0, "rssi": -69, "rfch": 0, "codr": "4/5", "freq": 916.7999, "datr": "SF7BW125", "size": 14}]}
    [   419.777] Push ack
    [   421.301] Pull ack
    [   429.758] Received packet: {"rxpk": [{"data": "QPwaAiYAAQACa+Ynxr8=", "time": "2018-06-14T22:09:56.809361Z", "chan":0, "tmst": 390382229, "stat": 1, "modu": "LORA", "lsnr": 5.0, "rssi": -69, "rfch": 0, "codr": "4/5", "freq": 916.7999, "datr": "SF7BW125", "size": 14}]}
    [   429.779] Push ack

    OTAA Mode
    Node code

    from network import LoRa
    import time
    import binascii
    import pycom
    pycom.heartbeat(False) #needs to be disabled for LED functions to work
    pycom.rgbled(0x7f0000) #red
    #Set AppEUI and AppKey - use your values from the device settings -->
    app_eui = binascii.unhexlify('70B3D57ED000FACC')
    app_key = binascii.unhexlify('5C51D94AE11A3ED67797FF9B80D1450A')
    lora = LoRa(mode=LoRa.LORAWAN, public=1, adr=0, tx_retries=0)
    # Remove default channels
    for index in range(0, 72):
    # Set  AU ISM 915 channel plan for TTN Australia
    for index in range(8, 15):
        lora.add_channel(index, frequency=915200000+index*200000, dr_min=0, dr_max=3)
    lora.add_channel(65, frequency=917500000,  dr_min=4,  dr_max=4)
    for index in range(0, 7):
        lora.add_channel(index, frequency=923300000+index*600000, dr_min=0, dr_max=3)
    # Join TTN Network via OTAA
    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():
        pycom.rgbled(0x7f7f00) #yellow
        print('Trying to join TTN Network!')
        pycom.rgbled(0x007f00) #green
    print('Network joined!')

    Node output

    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!
    Trying to join TTN Network!

    Simultaneous Output from Gateway

    [     2.344] Starting LoRaWAN nano gateway with id: b'30AEA4FFFE2CF7C4'
    [     6.717] WiFi connected to: IoT
    [     6.722] Syncing time with ...
    [     7.077] RTC NTP sync complete
    [     7.246] Opening UDP socket to ( port 1700...
    [     7.258] Setting up the LoRa radio at 916.7999 Mhz using SF7BW125
    [     7.267] LoRaWAN nano gateway online
    [     7.272] You may now press ENTER to enter the REPL
    [     7.278] Push ack
    [    32.277] Pull ack
    [    57.280] Pull ack
    [    67.306] Push ack
    [    82.273] Pull ack

  • @prawnhead Did you ever see messages from you node being received by the gateway. The gateway will print a message then.
    For OTAA, you should at least see the joine request message, for ABP you should see data messages after joining.

Log in to reply

Pycom on Twitter