LoPy4 not working in Class C

  • Greetings,
    I have a problem that seems to have more than a few posts on this forum . I have the LoPy4 working bi-directionally in Class A with a MultiTech Conduit AP gateway. I've been datalogging several sensors to a database and generating graphs and reports. It all works great.
    This week I started working on an I2C switch box so I can start working on the control programming. This is where it all came crashing down, I can not get Class C to work and can't just wait for the RX1 window after transmitting to the gateway to interact with the switch box. After digging through posts on this topic I have my first question formed, how do I get RX2 to work if I can't set the data rate the same on the LoPy4 and the gateway? The gateway will only accept DR8-DR13 and the LoPy4 only accepts between DR0-DR4(???).
    I'm in the US so using US915, working only on my local network and have Sub-Band 1 set to 1.

    Thanks ahead for any help

    from network import LoRa
    from machine import I2C, RTC
    import socket
    import binascii
    import time
    import config
    rtc = RTC()
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915, device_class=LoRa.CLASS_C, public=False)
    for index in range(0, 72):
    lora.add_channel(index=0, frequency=902300000, dr_min=0, dr_max=3)
    lora.add_channel(index=1, frequency=902500000, dr_min=0, dr_max=3)
    lora.add_channel(index=2, frequency=902700000, dr_min=0, dr_max=3)
    lora.add_channel(index=3, frequency=902900000, dr_min=0, dr_max=3)
    lora.add_channel(index=4, frequency=903100000, dr_min=0, dr_max=3)
    lora.add_channel(index=5, frequency=903300000, dr_min=0, dr_max=3)
    lora.add_channel(index=6, frequency=903500000, dr_min=0, dr_max=3)
    lora.add_channel(index=7, frequency=903700000, dr_min=0, dr_max=3)
    lora.add_channel(index=8, frequency=903000000, dr_min=4, dr_max=4)
    lora.add_channel(index=9, frequency=923300000, dr_min=0, dr_max=3)
    dev_eui = binascii.unhexlify(config.DEV_EUI.replace(' ',''))
    app_eui = binascii.unhexlify(config.APP_EUI.replace(' ',''))
    app_key = binascii.unhexlify(config.APP_KEY.replace(' ',''))
    print("Joining LoRa...")
    lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0)
    join_retry = 0
    while not lora.has_joined():
        print('Not joined yet... ', rtc.now())
        if join_retry > 100:
            raise Exception("Couldn join LoRa!")
    print("Connected to LoRa")
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)
    s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, False)
    while True:
        #except OSError as e:
        rx,port  = s.recvfrom(3)
        if rx:
            print("Got a packet",rx,port)
            s.send("Got It")

  • @Jamie In US915, RX2 uses a fixed channel and DR, which is by default downlink channel 0 (923.3 MHz) at DR8 (SF12BW500). This can be changed by the network through relevant MAC commands.

    You shouldn't have to specify anything on the LoPy. You only pick uplink channels, but class C downlinks automatically use either the default or whatever the network says.

    What LNS are you using? What are the settings of your LNS and gateway?

    Note that you must explicitly configure your LNS to let it know the device is class C, the device does not say anything about it to the network. If you don't, the network will continue to consider it's a class A device and send downlinks in the usual RX1 and RX2 windows.

  • Hi,

    If it can help you, I'm using LOPY and LOPY4 in CLASS C, with this code:

    lora = LoRa(mode=LoRa.LORAWAN,region=LoRa.US915, tx_retries=3, device_class=LoRa.CLASS_C)

    lora.add_channel(0, frequency=902300000, dr_min=0, dr_max=3)
    lora.add_channel(1, frequency=902500000, dr_min=0, dr_max=3)
    lora.add_channel(2, frequency=902700000, dr_min=0, dr_max=3)
    lora.add_channel(3, frequency=902900000, dr_min=0, dr_max=3)
    lora.add_channel(4, frequency=903100000, dr_min=0, dr_max=3)
    lora.add_channel(5, frequency=903300000, dr_min=0, dr_max=3)
    lora.add_channel(6, frequency=903500000, dr_min=0, dr_max=3)
    lora.add_channel(7, frequency=903700000, dr_min=0, dr_max=3)
    lora.add_channel(64, frequency=903000000, dr_min=4, dr_max=4

  • Global Moderator

    From what I've seen, is that the downlink channels should be automatically linked to the uplink channels you define here, linking DR0 to DR8 and so on between uplink and downlink. After the uplink, the node will automatically configure the channel and datarates for the downlink, this should also happen in CLASS_C. I have checked the code, and the device does actually switch to CLASS_C upon request, opening the window after RX2 with the DR and channel settings as we expect.

Log in to reply

Pycom on Twitter