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

    Failed 50% of the time to send data!? LORA

    Scheduled Pinned Locked Moved LoPy
    lopylorapython
    1 Posts 1 Posters 553 Views 1 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.
    • S Offline
      stefan85e
      last edited by stefan85e

      Im trying to learn how this works.... I dont get it still...

      It wont work, I was thinking it has to do with the recv part,
      maybe it has not the time to handle the bytes that are sent to the lopy.

      '''

      from network import LoRa
      import socket
      import time
      import pycom
      import os
      import gc

      #os.uname()
      #os.getcwd() # Check where in the filesystem you are

      pycom.heartbeat(False)
      for cycles in range(1): # stop after 1 cycles
      time.sleep(1)

      lora = LoRa(mode=LoRa.LORA,tx_power = 14, sf = 7, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)

      gc.enable()

      i = 0
      failed = 0
      counter_sent = 0
      counter_received = 0

      '''

      while True:

      #s.send("Got data from Stefan over LoRa: {}".format(i))
      s.send(bytes([
      			 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
                   33
                   #
      			 ])) # = 34 bytes             
      data = s.recv(64)
      print(data)
      counter_sent+=1
      print('Sent Data: {}'.format(counter_sent))
      if data:
          print(data)
          print('Received Data: {}'.format(data))
          counter_received+=1
          print('Received Data: {}'.format(counter_received))
          print('Successful data received: {}%'.format(counter_received/counter_sent))
          pycom.rgbled(0x007f00) # green
          print(' ')
      else:
          print(' ')
          failed +=1
          print('Got no data: {}'.format(failed))
          print('Unsuccessful data received: {}%'.format(failed/counter_sent))
          pycom.rgbled(0x7f0000)
      time.sleep(0.25)
      

      '''

      The received part:

      '''
      from network import LoRa
      import socket
      import time
      import pycom
      from machine import UART
      import gc

      lora = LoRa(mode=LoRa.LORA,tx_power = 14, sf = 7, frequency=863000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)

      Enable garbage collection

      #time.sleep(2)
      #gc.enable()
      #Counters and Declarations

      i = 0
      counter_failed = 0
      counter_sent = 0
      counter_received = 0
      UART_RX_counter = 0
      UART_TX_counter = 0
      UART_RX_Failed = 0
      UART_TX_Failed = 0
      arr_size = 0

      #While loop for UART and LoRa
      while True:
      #if uart.write('hello'):
      #UART_TX_counter=+ 1 #Successful TX Counter
      #print('Sent over UART: {}'.format(UART_TX_counter))
      #UART_RX = uart.read(5) # read up to 5 bytes
      #if UART_RX:
      #print('Received over UART: {}'.format(UART_RX))
      #UART_RX_counter =+ 1 #Successful RX Counter
      #print('Successful UART received: {}'.format(UART_RX_counter))
      #else:
      #UART_RX_Failed =+ 1 #Failed RX Counter
      #print('Did not get anything over UART: {}'.format(UART_RX_Failed))
      #else:
      #UART_TX_Failed =+ 1 #Failed TX Counter
      #print('Did not send over UART: {}'.format(UART_TX_Failed))
      '''
      i+=1
      arr_size += 1
      arr = bytearray(arr_size)

      #s.send("Got data from Jonathan over LoRa: {}".format(i))
      data = s.recv(64)
      #arr = data #Inserts Data received from LoRa
      #print('Array: {}'.format(arr))
      #print(' ')
      counter_sent+=1
      print('Success {}%'.format(counter_received/counter_sent))
      print(' ')
      print('Failed {}%'.format(counter_failed/counter_sent))
      
      if data:
          print(data)
          counter_received+=1 #Counter over Successful Received Data over LoRa
          #print('Received Data: {}'.format(counter_received))
          if s.send(data):
              print('Sent data')
          #pycom.rgbled(0x007f00) # green
          print(' ')
      else: #Unsuccessful data received over LoRA
          print(' ')
          counter_failed +=1
          #print('Got no data over LoRa: {}'.format(failed))
          #pycom.rgbled(0x7f0000)
      time.sleep(0.25)
      

      0_1523019277293_memory.PNG

      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