LoRaWan configuration



  • According to the documentation on https://docs.pycom.io/lopy/library/network.html the init() method of the LoRa class accepts a frequency parameter to select the desired ISM band. However the note on the same page says:

    "In LoRa.LORAWAN mode, only adr, public and tx_retries are used. All the otherparams will be ignored as theiy are handled by the LoRaWAN stack directly. On the other hand, these same 3 params are ignored in LoRa.LORA mode as they are only relevant for the LoRaWAN stack."

    If this is true, how does one configure the transmitter for different regions (e.g. US vs EU)? Can someone please post a working example that shows how to configure the transmitter for the 915 band? BTW, raw LoRa mode seems to work fine.



  • Note: I updated the code below because the duty_cycle parameter isn't supported.

    here is the function clean:

    def select_subband(lora, subband):
        if (type(subband) is int):
            if ((subband<1) or (subband>8)):
                raise ValueError("subband out of range (1-8)")
        else:
            raise TypeError("subband must be 1-8")
        
        for channel in range(0, 72):
            lora.remove_channel(channel)
        
        for channel in range((subband-1)*8, ((subband-1)*8)+8):
            lora.add_channel(channel, frequency=902300000+channel*200000, dr_min=0, dr_max=3)
    
    


  • Hi @pablomargareto, Let me try to answer a your questions:

    1. Yes, add_channel and remove_channel both work when joined with LoRaWAN.
    2. Yes, use this function:
    def select_subband(lora, subband):
        if (type(subband) is int):
            if ((subband<1) or (subband>8)):
                raise ValueError("subband out of range (1-8)")
        else:
            raise TypeError("subband must be 1-8")
        
        for channel in range(0, 72):
            lora.remove_channel(channel)
        
        for channel in range((subband-1)*8, ((subband-1)*8)+8):
            lora.add_channel(channel, frequency=902300000+channel*200000, dr_min=0, dr_max=3)
    
    1. Something like:
    for zzz in range(0,10000):
        s.send("a msg")
        time.sleep(30)
    

    Not sure this is what you're asking for (maybe you're looking for a timer/callback function set, etc).

    You can change the data rate (useful if you would like to use longer messages) by doing:

    s.setsockopt(socket.SOL_LORA,socket.SO_DR, 3)
    

    where s is a lora socket.

    Also, ignore the documentation about channels 1-3 being special, this is an issue for Europe, not the US. I should note that most US gateways are on subband 2 as best I can tell.

    I have found the LoPy to be very reliable generally when using these functions. I only use OTAA with TTN (I don't use ABP).

    -Chris



  • @dchappel No luck... I kind of give up using this hardware. It is really an awesome solution, but the lack of support and documentation is frustrating. Maybe in the future they have something more mature on the firmware/software side.

    Good luck and keep us posted! :)



  • @betabrain That is not enough. In the US you have 72 channels and a LoRa gateway listen to only 8 (some of them up to 64). You need to tell LoPy which sub-band to use.



  • I am also having issue (with very similar code) with only getting one message through for every 5-10 sends.

    Pablo - were you able to resolve your issue?

    Thanks...



  • Hello,

    First of all, thanks for this great product (lopy) and your hard work. Cheers up! I am convinced that you will achieve something really stable soon.

    I still have the same question than @tbradshaw , since I am working with one LoPy here in the US and I am not sure how the LoRaWan is setting up everything.

    I updated to the last firmware today and I was doing some testing with my lopy. This is my code:

    from network import LoRa
    import time
    import binascii
    import socket
    import pycom
    import struct
    
    lora = LoRa(mode=LoRa.LORAWAN)
    #lora = LoRa(mode=LoRa.LORAWAN)
    
    #Setting up channels
    for index in range(3, 72):
        lora.remove_channel(index)
    
    for index in range(0, 8):
        freq = 903900000 + index * 200000
        print('Frequency: ')
        print(freq)
        lora.add_channel(index, frequency=freq, dr_min=0, dr_max=3, duty_cycle=0)
    
    #corresponding real values
    dev_addr = struct.unpack(">l", binascii.unhexlify('00000000'))[0]
    nwk_swkey = binascii.unhexlify('00000000000000000000000000000000')
    app_swkey = binascii.unhexlify('00000000000000000000000000000000')
    
    lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
    
    #wait until the module has joined the network
    while not lora.has_joined():
        time.sleep(1.5)
        print('Not joined yet...')
    
    print('Network joined!')
    
    pycom.rgbled(0x00ff00)
    
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0)
    s.setblocking(True)
    
    while True:
        print('Sending Packet...')
        pycom.rgbled(0x00ff00)
        s.send('0')
        print('Done sending')
        time.sleep(200)
    

    My problem is that I only get one out of 7 or 8 messages, always on the same frequency: 904.6 MHz. We do not have any limit by regulation in the US concerning the duty cycle.

    So, my questions are:

    1. Do the add_channel and remove_channel functions work when sending with LoraWan?
    2. There are 72 channels in the US and the commercial gateways use to work with only 8 (one sub-band). Is there any way to tell lopy which channels to use?
    3. I would be interested in being able to send a message every 30 seconds. Is there any way to be possible with the current firmware?

    Thanks and regards,

    Pablo



  • @tbradshaw The region (and therefore ISM band) is locked in the firmware. To change it, do a firmware update. The default firmware updater will ask you which country you intend to use your LoPy in.


Log in to reply
 

Pycom on Twitter