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

    Problems with socket connect OSError: -1

    Scheduled Pinned Locked Moved Comments & Feedback
    wlansocket connectoserror -1
    1 Posts 1 Posters 832 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.
    • D Offline
      DanielA
      last edited by

      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.

      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