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

    LoRa on 2 LOPYs plus serial

    Scheduled Pinned Locked Moved LoPy
    lopyserialloraloramac
    5 Posts 2 Posters 1.1k Views 2 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
      monersss
      last edited by

      Dear All,

      I need your help. I am working on connection serial -lopy-lopy-serial.
      I need to send an alert to 1 lopy via serial and than forward it to a second lopy via LoRa.
      Since I want to be sure that the whole alert has been sent it has to finish with special character \n. It works well till i am using LoRa, where what I am getting on second lopy is my alert but without \n. Could you help me to understand what i am doing wrong?
      Computer code is this one:

      import os
      import serial
      import time
      
      
      ser = serial.Serial("/COM6", 115200, timeout = 10)
      alert0 = 'message' + '\n'
      alert = alert0.encode('utf-8')
      ser.write(bytearray(alert))
              
      ser.close()
              
      time.sleep(3)
      

      First lopy:

      from machine import UART
      from network import LoRa
      import socket
      import pycom
      import time
      
      uart = UART(1, baudrate=115200, pins = ('P20', 'P21'), timeout_chars=2000)
      lora = LoRa(mode=LoRa.LORA, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      
      while True:
          data = uart.read(1000)
          print ('.')
          if (data is not None) and ('\n' in (data.decode('utf-8'))):
              print(data)
              s.send(data)
          final = s.recv(64)
          print(final)
          time.sleep_ms(1000)
      

      and second lopy, where I receive the alert via LoRa and save it on SD is here:

      from network import LoRa
      import socket
      import pycom
      import time
      
      lora = LoRa(mode=LoRa.LORA, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      
      while True:
          data1 = s.recv(64)
          if len(data1) > 0:
              s.send('data here')
              with open('/sd/lora_alert.txt','ab') as f:
                  f.write(data1)
          else:
              s.send('no alerts')
          time.sleep(2)
      

      and here i got stuck as what i get on SD is not what I have sent...

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

        @livius maybe You could help me. .please... :)

        1 Reply Last reply Reply Quote 0
        • sebS Offline
          seb
          last edited by

          Hi,

          Looking over your code I noticed you do not mount the SD card, please add this code:

          from machine import SD
          
          sd = SD()
          os.mount(sd, '/sd')
          

          I just tried this code running on two lopys with the latest firmware and everything seems to work as expected.

          M 1 Reply Last reply Reply Quote 0
          • M Offline
            monersss @seb
            last edited by

            @seb Sorry, I have missed this part of the code. Second lopy has this code in main, together with importing .py file torub LoRa , so here everythins works well, The message is stored on SD but without \n at the end....

            sebS 1 Reply Last reply Reply Quote 0
            • sebS Offline
              seb @monersss
              last edited by

              @monersss
              Can you post a sample of the file stored on the SD card? I programmed the first lopy to constantly send hello, and this was my result:

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