Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

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

    Scheduled Pinned Locked Moved MicroPython
    9 Posts 6 Posters 3.3k Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      Graunke
      last edited by

      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

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sakis @Graunke
        last edited by

        @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

        1 Reply Last reply Reply Quote 0
        • O Offline
          Oneillsite
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • R Offline
            Ralph
            last edited by Ralph

            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)
            
            G M 2 Replies Last reply Reply Quote 0
            • G Offline
              Graunke @Ralph
              last edited by

              @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

              J 1 Reply Last reply Reply Quote 0
              • R Offline
                Ralph
                last edited by

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

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jmarcelino @Graunke
                  last edited by jmarcelino

                  @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.

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    Mike K @Ralph
                    last edited by

                    @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?

                    R 1 Reply Last reply Reply Quote 0
                    • R Offline
                      Ralph @Mike K
                      last edited by

                      @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."

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom