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

    How to receive data from UDP socket (over WiFi)

    Scheduled Pinned Locked Moved Guides
    6 Posts 2 Posters 63 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.
    • N Offline
      nadvorvo
      last edited by

      Hi everyone,
      I am trying to send UDP packet using GPy. For testing I am using service QOTD (djxmmx.net).
      On my desktop python the code if functional, on GPy no data received.

      Thank you in advance for your assistance.
      Regards, Vojtech

      code snipet from GPy

      >>> uos.uname()
      (sysname='GPy', nodename='GPy', release='1.20.2.r3', version='v1.11-d945d33ee on 2020-03-08', machine='GPy with ESP32',pybytes='1.3.1')
      
      >>> wifi1.wlan.isconnected()
      True
      >>> import socket
      >>> UDP_IP = "68.228.188.226"
      >>> UDP_PORT = 17
      >>> MESSAGE = b''
      >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
      >>> s.settimeout(5)
      >>> s.sendto(MESSAGE, (UDP_IP, UDP_PORT))
      0
      >>> data, address = s.recvfrom(1024)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TimeoutError: timed out
      >>>
      

      when do same from my desktop the code is successful:

      >>> import socket
      >>> UDP_IP = "68.228.188.226"
      >>> UDP_PORT = 17
      >>> MESSAGE = b''
      >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
      >>> s.settimeout(5)
      >>> s.sendto(MESSAGE, (UDP_IP, UDP_PORT))
      0
      >>> data, address = s.recvfrom(1024)
      >>> print(data.decode())
      "The secret of being miserable is to have leisure to bother about whether
       you are happy or not.  The cure for it is occupation."
       George Bernard Shaw (1856-1950)
      
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @nadvorvo
        last edited by

        @nadvorvo Could it be a setting of your internet router?

        1 Reply Last reply Reply Quote 0
        • N Offline
          nadvorvo
          last edited by

          Hi @robert-hh,
          Thank you for your reply. I am connected to same wifi network from both devices (desktop notebook, GPy). Router settings should not be problem.

          robert-hhR 2 Replies Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @nadvorvo
            last edited by

            @nadvorvo So I could replicate your problem. Interestingly it also exists in different flavors on other micropython (non-pycom) variants and devices.
            With Pycom MicroPython the receive fails.
            On ESP32 and Winnermicro W600 ports the send returns a timeout error, but the following receive succeeds.
            On ESP8266 and Pyboard UD is not supported.
            Big mess.

            BUT: if you do not send an empty message, but for instance a single space, it works. So there is a problem dealing with an empty packet.

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

              @nadvorvo Update: on all devices this modified code works:

              import socket
              UDP_IP = "68.228.188.226"
              UDP_PORT = 17
              MESSAGE = b' '
              s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
              s.settimeout(5)
              print(s.sendto(MESSAGE, (UDP_IP, UDP_PORT)))
              
              data, address = s.recvfrom(1024)
              print(data.decode())
              
              
              N 1 Reply Last reply Reply Quote 2
              • N Offline
                nadvorvo @robert-hh
                last edited by

                Hi @robert-hh,
                I really appreciate the support you’ve given me. Thank you.
                Also functional on my side.

                Regards, Vojtech

                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