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

    Communication with other lora device doesn't work

    Scheduled Pinned Locked Moved MicroPython
    bugsloralopy4feather m0
    9 Posts 5 Posters 640 Views 4 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.
    • M Offline
      melkoutch
      last edited by

      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

      J robert-hhR 2 Replies Last reply Reply Quote 0
      • J Offline
        jcaron @melkoutch
        last edited by

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

        1 Reply Last reply Reply Quote 2
        • mfalkviddM Offline
          mfalkvidd
          last edited by mfalkvidd

          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.

          1 Reply Last reply Reply Quote 0
          • M Offline
            melkoutch
            last edited by melkoutch

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

            1 Reply Last reply Reply Quote 1
            • M Offline
              melkoutch
              last edited by

              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 ?

              J 1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron @melkoutch
                last edited by

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

                1 Reply Last reply Reply Quote 1
                • robert-hhR Offline
                  robert-hh @melkoutch
                  last edited by

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

                  M 1 Reply Last reply Reply Quote 1
                  • M Offline
                    melkoutch @robert-hh
                    last edited by

                    @robert-hh Thanks for clearing this out !

                    B 1 Reply Last reply Reply Quote 0
                    • B Offline
                      Bernd Meyer @melkoutch
                      last edited by

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

                      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