LoRa communication lopy - rfm9x



  • Hi,

    I'm using an "Adafruit RFM95W" (with a raspberry pi 3) and a lopy4. I want to send packets between them but it doesn't work.

    Here's the code I used on the lopy :

    from network import LoRa
    import socket
    import machine
    import time
    
    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868,frequency=868000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    
    while True:
    
         s.setblocking(True)
         s.send('Hello world !!')
         print("hello")
         time.sleep(5)
    
    

    And that's the rfm9x code :

    import board
    import busio
    import dogotalio
    import time
    import adafruit_rfm9x
    from digitalio import DigitalInOut, Direction
    
    CS = digitalio.DigitalInOut(board.D22)
    RESET = digitalio.DigitalInOut(board.D27)
    spi = busio.I2C(board.SCL,board.SDA)
    
    rfm9x = adafruit_rfm9x.RFM9X(spi,CS,RESET,868)
    while True :
        packet = rfm9x.receive()
        if packet is None :
            print("Listening again ...")
        else :
            print("Received : {0}".format(packet)) 
    

    It's really a simple hello world packet exchange in LoRa. After a random amount of time, the rfm9x finally received something which is unreadable and goes back to not receiving anything.

    I am in Europe so I'm using 868MHz on both devices and I checked the antenna connector.
    I tried to modify the parameters (spreading factor, coding rate, etc) but it doesn't change anything.

    For information, I posted a similar question but with a different technology : here

    Have anyone managed to get a lopy communicate with an rfm9x board ?



  • @Eric73 Great, thanks for your help !



  • @melkoutch Well, this is not a radio (sx127x) effect. If you look at adafruit lib (link in my previous post) it seem that this lib insert a 4 bytes header (line 649) before send a packet and line 697 you can se that you have to set with_header=False when you call rfm9x receive function to remove this 4 bytes header from your received data.

    It seem there no similar way for send function so header will be always send by rfm9x library.
    0xFF 0xFF 0x00 0x00 is broadcast header for RadioHead library, i suggest you to find and read this library specification if you plan to use it.



  • @Eric73 It worked !

    However, it works fine when sending packets from lopy to rfm9x but when lopy is waiting for packets it receives the following :

    b'\xff\xff\x00\x00ABC TEST !!!'
    

    (The packet sent was ABC TEST !!!)

    I can always erase the first bytes but I hope this is just another parameter to change, if anybody has an idea ?



  • @melkoutch I had a post similar to yours, I was able to rx data on the LoPy but it seemed to be in HEX, anyway my code might be of interest to you;

    https://forum.pycom.io/topic/4920/lopy-bytes-data-received-in-hex-convert-to-original-text

    Paul



  • Hi, i have a look at lora source code from pycom and adafruit( https://github.com/adafruit/Adafruit_CircuitPython_RFM9x/blob/master/adafruit_rfm9x.py ) , i'm don't very familiar with their coding style but in my humble opinion adafruit lib they don't do all init stuff for the lora chip (sx1276), and worst they doesn't allow fine grained frequency selection.

    In particular for your usage, they don't set a value for lora sync word, so sx1276 use it's reset value 0x12 (private lora), but it's seem that pycom init value is 0x34 (public lora aka lorawan).
    I suggest you to test on your pycom device with

    lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868,frequency=868000000,public=False)
    


  • @melkoutch I still feel uncomfortable about it, since the test failed initially, and worked later on when returning to the initial set-up. So it still has the smell of a non-initialized-variable bug somewhere.



  • @robert-hh Thanks for trying. I removed the frequency from parameters and tried to ajust te antenna but no changes.

    Just for information, I posted the same question on the adafruit forum if anyone wants to check it out. I posted example of the output I got (which is weird).



  • @melkoutch No clue why it does not work. This is similar to the simple LoPy-Lopy ping-pong example from the docs and library, which I tested now again between two LoPy4 devices, AND IT FAILS. It used to work.
    Edit 1: There is a RF transmission, but no data received.
    Edit 2: Just taking the example without setting the frequency works. The default is 868Mhz It has to be noted that when changing the parameters a HARD reset is required.
    Edit 3: Again tested, works now also with changed frequency ar 863MHz. One thing I did was to mis-align the antennas, because devices are very close on my desk. With one antenna vertical, and the other horizontal I have an rssi of about -50 dB, which is fine.


Log in to reply
 

Pycom on Twitter