LoPy to LoPy over WIFI, socket Exception <class 'OSError'> -1



  • Hi, I'm triying to connect 2 loPy's over Wifi to send information but I get this error:

    <class 'OSError'>
    -1

    This is the code I'm using:

    wlan = WLAN()
    wlan.deinit()
    wlan = WLAN(mode=WLAN.STA)
    
    for i in range(sendRetry):
        nets = wlan.scan()
        for net in nets:
            if net[0] == connectTo:
                wlan.connect(ssid=net[0], auth=(net[2],"witeklab@2018"),bssid=net[1])
                while not wlan.isconnected():
                    continue
                print(wlan.ifconfig())
                break
        else:
            print(connectTo+" not found")
        if wlan.isconnected():
            break
    
    if wlan.isconnected():
        pycom.rgbled(0x00000f)
        sendInfo(wlan)
        wlan.disconnect()
    
    def sendInfo(wlan):
        sock = socket.socket()
        try:
            fullpath = "/flash/registry"
            ficheros = os.listdir(fullpath)
            if len(ficheros) > 0:
                print("______START______")
                ip, subnet, gateway, dns = wlan.ifconfig(id=0)
                port = 80
                add = socket.getaddrinfo(gateway, port)[0][-1]
                print(socket.getaddrinfo(gateway, port))
                print("connecting socket to ->",add)
                sock.setblocking(True)
                sock.settimeout(1)
                sock.connect(add)
    
                print("socket connected")
    
                #rest of code is not executed
        except Exception as e:
            print(type(e))
            print(str(e))
        finally:
            sock.close()
    

    And this is the output:

    ('192.168.4.2', '255.255.255.0', '192.168.4.1', '192.168.4.1')
    ______START______
    [(2, 1, 0, '', ('192.168.4.1', 80))]
    connecting socket to -> ('192.168.4.1', 80)
    <class 'OSError'>
    -1
    

    Thank you



  • Indeed we have the "socket.accept ()" method in the first LoPy, but the problem was in the pointing address to the other LoPy which was wrong.

    It's already solved, thank you!



  • @goro Do you have a matching socket.accept() open at the device you want to connect to?



Pycom on Twitter