Communication with other lora device doesn't work



  • Hi,

    First I appologize if I'm not in the right category this is my first post.

    I actually have two questions.

    First one : I have a feather M0 lora board from Adafruit which communicate over LoRa. I also have a lopy4 and a pytrack. I tried to get both communicate (simple packages) over LoRa but it does not work. I made sure of the frequencies and I used the "raw lora" mode.
    Here is the code, maybe I made a mistake : (the first one is the pycom code and the second one is the feather code)

    from network import LoRa
    import socket
    import machine
    import time
    
    # initialise LoRa in LORA mode
    # Please pick the region that matches where you are using the device:
    # Asia = LoRa.AS923
    # Australia = LoRa.AU915
    # Europe = LoRa.EU868
    # United States = LoRa.US915
    # more params can also be given, like frequency, tx power and spreading factor
    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, frequency=870000000, tx_power=14,sf=12)
    
    # create a raw LoRa socket
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    
    while True:
        # send some data
        s.setblocking(True)
        s.send('Hello world !!')
    
        print("I sent hello !")
        print(lora.stats())
        # wait a random amount of time
        time.sleep(1)
    

    Here's the feather code :

    import board
    import busio
    import digitalio
    import time
    import adafruit_rfm9x
    
    
    
    RADIO_FREQ_MHZ   = 870
    CS    = digitalio.DigitalInOut(board.RFM9X_CS)
    RESET = digitalio.DigitalInOut(board.RFM9X_RST)
    led = digitalio.DigitalInOut(board.D13)
    led.direction = digitalio.Direction.OUTPUT
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
    rfm9x.tx_power = 23
    
    led.value = True
    time.sleep(3)
    
    while True:
        packet = rfm9x.receive()
        if packet is None:
            print('Received nothing! Listening again...')
       led.value = False
        else:
            print('Received (raw bytes): {0}'.format(packet))
            packet_text = str(packet, 'ascii')
            print('Received (ASCII): {0}'.format(packet_text))
            rssi = rfm9x.rssi
            print('Received signal strength: {0} dB'.format(rssi))
       led.value = True
           time.sleep(0.5)
           led.value = False
           time.sleep(0.5)
    

    It really should be basic but I can't manage to get those board communicate.

    My second question has nothing to do with the previous one : Is it possible to give arguments when uploading a file with micro python. I mean that when I launch my program in a python terminal I can specify command line arguments. How to do the same with micro python ? (By the way, I'm using Atom).

    Thanks



  • @melkoutch hope you still read this as this thread is quite old. I stumbled upon it having the exact same problem (LoPy4 <-> Feather M0 in raw LoRa). Adjusting the spreading factor doesn't seem to solve it for me. Would you be able to post the code fragment that you used to successfully connect the two? Thanks a lot!



  • @robert-hh Thanks for clearing this out !



  • @melkoutch said in Communication with other lora device doesn't work:

    My second question has nothing to do with the previous one : Is it possible to give arguments when uploading a file with micro python. I mean that when I launch my program in a python terminal I can specify command line arguments. How to do the same with micro python ? (By the way, I'm using Atom).

    There is not OS or shell on the Pycom devices, and not main() function. If the main entry point of your code is a function, you can supply arguments to that, when executed from the REPL command line. Basically, that's what the Python interpreter on a PC does: calling main() with the arguments derived from the command line of the OS shell.



  • @melkoutch the spreading factor determines the transmission speed, which in turn has an influence on range and resistance to interference (in theory at least).

    SF7 is the fastest, SF12 is the slowest. SF12 is so slow that it takes over a second to send a LoRaWAN frame with just a single data byte. In theory it gives a better range.



  • You were right the spreading factor was indeed the problem. However I don't really understand what it is. I just removed it from the params and it works. I saw in the documentation :

    sf sets the desired spreading factor. Accepts values between 7 and 12.

    What actually is a spreading factor ?



  • Thanks both of you ! I will make changes accordingly and see if that solves the problem !



  • In addition to what jcaron said, 23dBm is way above the maximum allowed transmit power in EU, unless your cable/antenna has a lot of attenuation.

    The crazy high output power could be the reason the devices can't communicate. You might be saturating the receiver.

    https://www.disk91.com/2017/technology/internet-of-things-technology/all-what-you-need-to-know-about-regulation-on-rf-868mhz-for-lpwan/ has a good introduction to the legal limits on the 868 ism band.



  • @melkoutch If I'm not mistaken, 870 MHz is actually (just) outside the allowed frequency band in the EU region.

    Also, it takes over a second to send a frame at SF12, and, depending on the sub-band, you are only allowed to transmit 10%, 1% or even 0.1% of the time. You are clearly exceeding duty cycle limits here.

    Not sure if that is actually related to your issue (don't know if in raw LoRa mode the stack will prevent sending outside of the configured band for instance), but in any case you are required to comply with local radio regulations. You could be interfering with other systems.



Pycom on Twitter