Problems with socket connect OSError: -1



  • Connecting to different WLAN access points behaves differently.
    After having OSError:-1, I tested several WLAN-AP's.
    My home WLAN router Fritzbox, the phone Samsung S5 with hotspot, an LTE hotspot from Netgear AC762S and others.
    All AP's have been used over years now without anay problems.
    With my fipy I get a OSError: -1 in the special case when connecting to a socket with a port different from 80 (http).
    So my MQTT connection fails.
    This happens only with Netgear devices, with all other AP's I tested it works fine.

    from network import WLAN
    import usocket as socket
    import machine
    
    wlan = WLAN(mode=WLAN.STA)
    
    def wlanTest(accesspoint, password, domainname, port):
        print(str.format("\n\nwlan connect to AP: \'{}\'", accesspoint))
        wlan.connect(accesspoint, auth=(WLAN.WPA2, password), timeout=5000)
        print("wait for connection")
        while not wlan.isconnected(): 
            machine.idle()
    
        if (wlan.isconnected()):
            print("wlan connection successfull")
            print("STA ifconfig", wlan.ifconfig())
            print("create socket")
            sock = socket.socket()
    
            addrinfo = socket.getaddrinfo(domainname, port)[0]
            print(str.format("addressinfo for \'{}\':{} family:{} type:{} proto:{} sockaddr:{}",domainname, port, addrinfo[0], addrinfo[1], addrinfo[2], addrinfo[4]))
            addr = addrinfo[-1]
    
            print("socket connect")
            sock.connect(addr)
            print("socket connection successfull")
            sock.close()
            print("socket closed")
        else:
            print("wlan connection failed")
    

    Here are the console printouts

    #wlanTest("DaniDowntown", "xxx", "www.google.ch", 80)
    '''
    wlan connect to AP: 'DaniDowntown'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.43.65', '255.255.255.0', '192.168.43.1', '192.168.43.1')
    create socket
    addressinfo for 'www.google.ch':80 family:2 type:1 proto:0 sockaddr:('216.58.213.227', 80)
    socket connect
    socket connection successfull
    socket closed
    '''
    #wlanTest("DaniDowntown", "xxx", "eu.thethings.network", 1883)
    '''
    wlan connect to AP: 'DaniDowntown'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.43.65', '255.255.255.0', '192.168.43.1', '192.168.43.1')
    create socket
    addressinfo for 'eu.thethings.network':1883 family:2 type:1 proto:0 sockaddr:('52.169.76.255', 1883)
    socket connect
    socket connection successfull
    socket closed
    '''
    
    
    #wlanTest("AirCard-9343", "xxx", "www.google.ch", 80)
    '''
    wlan connect to AP: 'AirCard-9343'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.1.2', '255.255.255.0', '192.168.1.1', '192.168.1.1')
    create socket
    addressinfo for 'www.google.ch':80 family:2 type:1 proto:0 sockaddr:('216.58.213.195', 80)
    socket connect
    socket connection successfull
    socket closed
    '''
    #wlanTest("AirCard-9343", "xxx", "eu.thethings.network", 1883)
    '''
    wlan connect to AP: 'AirCard-9343'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.1.2', '255.255.255.0', '192.168.1.1', '192.168.1.1')
    create socket
    addressinfo for 'eu.thethings.network':1883 family:2 type:1 proto:0 sockaddr:('52.169.76.255', 1883)
    socket connect
    ╝Traceback (most recent call last):
    File "<stdin>", line 35, in <module>
    File "<stdin>", line 26, in wlanTest
    OSError: -1
    '''
    
    
    #wlanTest("FRITZ!Box Fon WLAN 7050 Annex A", "xxx", "www.google.ch", 80)
    '''
    wlan connect to AP: 'FRITZ!Box Fon WLAN 7050 Annex A'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.1.162', '255.255.255.0', '192.168.1.1', '192.168.1.1')
    create socket
    addressinfo for 'www.google.ch':80 family:2 type:1 proto:0 sockaddr:('172.217.19.67', 80)
    socket connect
    socket connection successfull
    socket closed
    '''
    #wlanTest("FRITZ!Box Fon WLAN 7050 Annex A", "xxx", "eu.thethings.network", 1883)
    '''
    wlan connect to AP: 'FRITZ!Box Fon WLAN 7050 Annex A'
    wait for connection
    wlan connection successfull
    STA ifconfig ('192.168.1.162', '255.255.255.0', '192.168.1.1', '192.168.1.1')
    create socket
    addressinfo for 'eu.thethings.network':1883 family:2 type:1 proto:0 sockaddr:('52.169.76.255', 1883)
    socket connect
    socket connection successfull
    socket closed
    '''
    

    Does anyone have an idea what the problem could be?
    If a customer changes the WLAN router or the mobile hotspot, that would be bad.
    Thanks for any hints or solutions.


 

Pycom on Twitter