A LoRa Step-by-Step, please. Pretty Please?



  • Hi all,

    I tried to get a LoRa connection between two LoPys for most of two days now, but to no avail.

    I probably read every relevant post on this forum and tried the LoRaMAC, the NanoGateway and I'm pretty sure all other examples I could find, but still no love. I even looked with a SDR-stick, if something is happening in the 868 MHz spectrum and I could actually see something every 6 seconds, as defined in the loop of the sender, but the receiver I hooked up to Pymakr doesn't receive anything.

    Would anyone, who successfully connected two LoPys via LoRa, be so kind to make a babystep-by-babystep tutorial for dummies like me? That would be awesome!

    Best regards,

    Stefan



  • @Mike-K Did you select the correct country in the firmware flasher when flashing your lopy? This will determine if you get the 868 or 915 firmware version and thus which frequencies you can use. From the docs:

    "frequency accepts values between 863000000 and 870000000 in the 868 band, or between 902000000 and 928000000 in the 915 band."



  • @Ralph Thank you about those code samples, but I'm curious about one thing: how do you know they work?

    I've added some print statements and changed the frequencies to 915000000 since I'm in the USA, but am having no luck.

    It appears that Node 1 is receiving only b''. Any ideas?



  • @Graunke

    If you're looking for the longest range you can trade off airtime/speed for by going to a higher spreading factor, the sf= parameter in the LoRa initialisation.

    The default sf=7 is the shortest airtime - good for frequent transmissions - but also the least range. You can try sf=12 which should give you longer range at the expense of longer on-air time, which - because of the duty cycle restrictions - means you'll have to wait longer between transmissions.

    I think the rule is SF=12 can be decoded down to a SNR (signal-to-noise ratio) of -20 while SF=7 will only go to -7.



  • @Graunke that could very well be, though I don't have much lora experience myself. Have fun programming!



  • @Ralph This works!

    Thank you. I can go on from there now. The other examples I used up to yesterday did not specify the frequency explicitly. Could that be the reason?

    I can go on from here now and try how much distance I can get between the two nodes.

    Cheers,

    Stefan



  • Hi @Graunke,

    The other replies should already help you a lot, but I agree that we should have some simple step-by-step examples/tutorials in the docs. A new version of the docs is almost done and it groups all available examples together. We'll also work on a bit more explanation to go with it.

    Here is the simplest lopy-to-lopy code that I have:

    Node 1:

    from network import LoRa
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, frequency=863000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    while True:
        if s.recv(64) == b'Ping':
            s.send('Pong')
        time.sleep(5)
    

    Node 2:

    from network import LoRa
    import socket
    import time
    
    lora = LoRa(mode=LoRa.LORA, frequency=863000000)
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setblocking(False)
    
    while True:
        s.send('Ping')
        time.sleep(5)
    


  • To make it easier, you should connect both lopy's on the same computer ( 2 usb cables) and use 2 instances of pymakr: one for the node and the other for the nano gateway.
    In the first instance of pymakr, you create the file nano_gateway.py from https://forum.pycom.io/topic/236/lopy-nano-gateway
    in the second instance of pymakr, you create the file node_1.py
    Add in the beginning of this code:

    import machine
    uart = machine.UART(0, 115200)
    os.dupterm(uart)

    Run the code node_1.py and the run the code nano_gateway.py



  • @Graunke

    Hi. You'll need to be more specific so that we can help you. What have you tried and what doesn't work? Can you provide a code sample?

    Here's a post that might help you: https://forum.pycom.io/topic/236/lopy-nano-gateway


Log in to reply
 

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