Sending packets via WiFi from Gateway to PC



  • 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 :)



  • @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. :)



  • 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



  • @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.



  • 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



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


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.