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

    Socket connect address

    Scheduled Pinned Locked Moved WiPy 2&3
    wipywipy 1wifisocket
    9 Posts 3 Posters 4.2k Views 3 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.
    • M Offline
      michalt38
      last edited by

      Re: Sending data via WiFi
      If I want to connect to my home router, which address should I enter here: socket.connect(('207.58.139.247', 80))?

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @michalt38
        last edited by livius

        @michalt38
        this command is not for connecting to router
        only to connect one socket with another opened on the end address here 207.58.139.247 and on port here is : 80

        to connect to router use

        wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
        

        details:
        https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/wlan.html

        think about people first, then computers

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          michalt38 @livius
          last edited by

          @livius
          I've got OSError: 111. What does it mean?

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

            @michalt38
            You could use something like:

            import network
            import time
            # setup as a station
            wlan = network.WLAN(mode=network.WLAN.STA)
            wlan.connect(ssid="your ssid", auth=(network.WLAN.WPA2, "your router password"))
            while not wlan.isconnected():
                time.sleep_ms(1000)
                print(".", end="")
            print(wlan.ifconfig())
            
            M 1 Reply Last reply Reply Quote 0
            • M Offline
              michalt38 @robert-hh
              last edited by

              @robert-hh
              I got ('192.168.1.141', '255.255.255.0', '192.168.1.1', '8.8.8.8')
              But why I got error 111? Should I configure this socket on router first?

              L robert-hhR 2 Replies Last reply Reply Quote 0
              • L Offline
                livius @michalt38
                last edited by

                @michalt38 said in Socket connect address:

                I got ('192.168.1.141', '255.255.255.0', '192.168.1.1', '8.8.8.8')

                192.168.1.141 is ip configured for your Wipy in network
                '255.255.255.0' is net mask
                192.168.1.1 is your router
                '8.8.8.8' is DNS

                And questions are:

                1. Is your router IP 192.168.1.1 ?
                2. is 192.168.1.141 free ip in your network?
                3. is '255.255.255.0' valid mask for your network - problaby yes but..

                think about people first, then computers

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

                  @michalt38
                  Hello, it seems that things are still a little bit mixed up. There are two kinds of connect we seem to talk about:
                  a) connect to a network. That's the one you do with the wlan.connect(). Once it succeeds ( and it should it the script returned ('192.168.1.141', '255.255.255.0', '192.168.1.1', '8.8.8.8'), then your little micro is connected to the network created by your router, like you PC or other devices are. You should be able to get a response with ping 192.168.1.141 from it. Once your device is connected to the network, you can access any other entity on your LAN or in the Internet.
                  c) connect to a service. That's done with socket.connect(), which connects you to another device which has issued a socket.accept(), like a server does. Routers normally do not offer such a service, but they may. For connection, you need the IP-address of the device and it port number of the service.
                  Now my question is: what is your intention?

                  M 1 Reply Last reply Reply Quote 0
                  • M Offline
                    michalt38 @robert-hh
                    last edited by

                    @robert-hh I have to write a program on a PC that can recive data from WiPy through WiFi and I need to send some example data from WiPy to PC.

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

                      @michalt38 OK. Then you'll need two steps:
                      First, you have to connect the WiPy to the network. That's done with wlan.connect, as given in my sample scripts.
                      Second: you have to write a little program for you WiPy and your PC that connects through sockets and sends the data. The IP adresses used are those of the WiPy and the PC, not the one of the router. You have to define which entity connects (socket.connect() ) and which entity accepts (socket.accept()).
                      For initial testing, you can use for the PC side netcat (nc), which is a simple raw socket send/receive program.
                      Examples for the WIPy side are here:
                      https://docs.python.org/3/howto/sockets.html
                      or here:
                      https://www.tutorialspoint.com/python3/python_networking.htm

                      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