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

    Sending packets via WiFi from Gateway to PC

    Scheduled Pinned Locked Moved LoPy
    lopywifi send data
    6 Posts 4 Posters 2.4k 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.
    • F Offline
      finnzc
      last edited by livius

      Hello everyone,

      I'm quite new with LoPy and had very limited knowledge in network. I followed a simple tutorial on setting up a server on PC and a client on Pycom but it didn't connect with PC.

      PC (server):

      import socket               # Import socket module
      
      s = socket.socket()         # Create a socket object
      host = name          # Get local machine name
      port = port_number                   # Reserve a port for your service.
      s.bind((host, port))        # Bind to the port
      
      s.listen(5)                          # Now wait for client connection.
      while True:
                 c, addr = s.accept()        # Establish connection with client.
                 print 'Got connection from', addr
                 c.send('Thank you for connecting')
                  c.close()                # Close the connection
      
      

      Pycom(client):

      import socket       # Import socket module
      
      s = socket.socket()         # Create a socket object
      host = name           # Get local machine name
      port = port_number              # Reserve a port for your service.
      
      s.connect((host, port))
      print(s.recv(1024))
      s.close                                # Close the socket when done
      

      I'd like to send simple packets of data from Pycom using socket.send() and receive it in my laptop using socket.recv(). However, the problem I'm encountering is that as I run the code in Pycom, I'm getting OSError: -1 in s.connect(). Help is very appreciated :)

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

        @finnzc
        did you connected Lopy by Wifi to your router?
        https://docs.pycom.io/chapter/tutorials/all/wlan.html

        think about people first, then computers

        1 Reply Last reply Reply Quote 0
        • F Offline
          finnzc
          last edited by

          No, I haven't connected LoPy to the router. I was thinking of sending WiFi packets directly to the laptop. Could you explain why is connecting to the router necessary?
          Thanks @livius

          ahaw021A 1 Reply Last reply Reply Quote 0
          • B Offline
            bnjroos
            last edited by

            @finnzc if you want to send the wifi paquet to your laptop you still need to connect the LoPy to your laptop with maybe your laptop setup as AP.

            1 Reply Last reply Reply Quote 0
            • ahaw021A Offline
              ahaw021 @finnzc
              last edited by

              hi @finnzc

              I suggest a quick google of how Wi-Fi networks work may be useful

              To answer you question - in order for devices to communicate in WiFi they all need to be joined to the same network. This can be done one of two ways

              A) Using a router - this is the most common way for example your LoPy, Laptop etc are all connected to your "home wifi" which is a router advertising something called an SSID. The router keeps tracks of all devices on the network and is able to pass packets between them

              B) Using your laptop as a router. You can configure your latpop to not join a network instead act as the router itself. I don't recommend this path as it does require a good understanding of wifi networking principles

              Andrei

              F 1 Reply Last reply Reply Quote 0
              • F Offline
                finnzc @ahaw021
                last edited by

                @ahaw021
                @bnjroos

                Thanks for the information, I really appreciate it. I'd like to give a go for option A as it seems more straightforward. :)

                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