L04 Lorawan ABP



  • Good afternoon everyone,
    i am still having problems with ABP authentication with L04 module.
    i Send a packet every 10 seconds with dr=5,
    Everything works as expected when i use 1.20.3.b4 Development stack, but with other versions such as pybytes, legacy, this code not working.

    Any ideas?
    below my code!

    many thanks,

    Alessandro

    from network import LoRa
    import socket
    import ubinascii
    import struct
    import time
    import machine

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

    dev_addr = struct.unpack(">l", ubinascii.unhexlify("260B6FA1"))[0]
    nwk_swkey = ubinascii.unhexlify("4E776147EDF91C14DD007E76D64F0D0E")
    app_swkey = ubinascii.unhexlify("655CA99B586876E156919AD7E09B87D7")

    for i in range(3, 16):
    lora.remove_channel(i)

    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)

    lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))

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

    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) # set data rate
    s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, True)

    def lora_cb(lora):
    events = lora.events()
    print(events)
    if events & LoRa.RX_PACKET_EVENT:
    print('Lora packet received')
    return
    if events & LoRa.TX_PACKET_EVENT:
    print('Lora packet sent')
    print(lora.stats())
    return
    if events & LoRa.TX_FAILED_EVENT:
    print('Lora packet sent failed')
    return

    lora.callback(trigger=(LoRa.RX_PACKET_EVENT|LoRa.TX_PACKET_EVENT|LoRa.TX_FAILED_EVENT), handler=lora_cb)

    s.setblocking(False)

    counter = 0

    while True:
    counter += 1
    if counter == 50:
    print('Sending')
    s.send("hello")
    counter = 0
    time.sleep_ms(100)


Log in to reply
 

Pycom on Twitter