ABP 'working' Example



  • So after a lot of de-compiling i found the way to do ABP. Here by example code:

    lora = LoRa(mode=LoRa.LORAWAN, sf=7, tx_power=14)
    lora.BW_125KHZ
    lora.CODING_4_5
    
    # create an OTAA authentication tuple (NWSkey, AppSKey, DevAddr)
    auth = (bytes([0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX]), bytes([0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX]), 1762823379 )
    
    lora.join(activation=LoRa.ABP, auth=auth, timeout=0)
    
    while not lora.has_joined():
        print('Trying to join LoRa network')
        sleep(1)
        pass
    print('Joined LoRa Network')
        
    pycom.rgbled(GREEN)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    while True:
        print('Sending Packet')
        s.send('Hello from the LoPy')
        print('Done sending')
        sleep(2)
    

    I dont think i need to explain the 16 byte keys, but the devAddr is a decimal address for your addresses. You can use a calculator, but make sure you padd the 0's if a hex did not yield a 8 bit value.

    example : 69128CD3 = 0x69, 0x12, 0x8C, 0xD3

    0x69 = 1101001 -> 01101001 (pad 1 zero)
    0x12 = 10010 -> 00010010 (pad 3 zeros)
    0x8C = 10001100
    0xD3 = 11010011

    Combine it all:

    01101001000100101000110011010011

    convert that to decimal should result it 1762823379, this is the INT you will need to use. Using the Bytes() method will just result in a error that it cannot be converted into a INT, so this way i am bypassing this problem (assuming bug here)

    Now that said, the code will just continue looping and sending packets, but for some reason even when explicitly defining SF7 it will still be SF12 in addition it only sends out a single packet and then the radio just 'dies' and with dies i mean its no longer responding until you do a HARD reset. With a soft reset and running the code again it will just hang on lora.join


  • administrators

    Hello,

    If it doesn't transmit at all, could it be that you have something connected to the NC pins of the LoPy?

    https://docs.pycom.io/lopy/lopy/quickref.html

    We have added a set socket option API in order to select the data rate (expect it on Friday).

    Cheers,
    Daniel



  • new firmware out, now Lora does not transmit at all.

    nice try to fix this Pycom .... then again the readme didnt say this was fixed at all



  • I have the same problem.
    it only runs once...
    need to disconnect the usb cable and restart pymakr...:(



  • Why don't you just use plain 0x69128CD3 (which is equal to 1762823379) instead of all this binary gymnastics?



  • LoPy has responded on TTN forum with a confirmation on this and looking into this.

    and now we wait :)



  • I experience the same... I'm only successfully receiving the first packet.


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.