Socket connect address

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

  • @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:
    or here:

  • @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.

  • @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 ('', '', '', ''), 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 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?

  • @michalt38 said in Socket connect address:

    I got ('', '', '', '') is ip configured for your Wipy in network
    '' is net mask is your router
    '' is DNS

    And questions are:

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

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

  • @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():
        print(".", end="")

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

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

    to connect to router use

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


Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.