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

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

    Scheduled Pinned Locked Moved LoPy
    lopywifiwifi send dataoserrorlopy4
    3 Posts 2 Posters 285 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.
    • G Offline
      goro
      last edited by

      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

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @goro
        last edited by

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

        1 Reply Last reply Reply Quote 0
        • G Offline
          goro
          last edited by

          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!

          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