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

    Lopy LoRa socket timeout

    Scheduled Pinned Locked Moved LoPy
    lopylopy lorawansockettimeout
    3 Posts 2 Posters 1.3k 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.
    • A Offline
      AHellLycan
      last edited by

      Hi, I’m noob with python and lora, I want to open a socket wait for a message, if there is no message then do something else, my code so far is:

        from network import LoRa
       import socket
       import machine
       import time
       import binascii
       import network
      
       n = 0
      try:
           the_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      except:
          exit('Error creating socket.')
      the_sock.settimeout(5)
      while True:
           try:
                 n+=1
                print("Hola"+str(n))
                the_sock.setblocking(True)
                ack = the_sock.recv(64)
           except socket.timeout, e:
                err = e.args[0]
                print(err)
                break`
      

      The problem is that the timeout it’s not working, I’ve checked some answers but the code looks good to me, can you help me please?

      Kind Regards

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @AHellLycan
        last edited by livius

        @ahelllycan
        change this to

        the_sock.settimeout(5)
        ack = the_sock.recv(64)
        

        setblocking is only shortcut for timeout
        if you settimeout first and then setblocking you change timeout to none

        summary
        settimeout(None) == setblocking(True)
        settimeout(0) == setblocking(False)
        settimeout(5) --- no equivalent in setblocking

        think about people first, then computers

        A 1 Reply Last reply Reply Quote 1
        • A Offline
          AHellLycan @livius
          last edited by

          @livius Thank you so much!!! that's exactly what I needed

          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