Mesh network: Get the ip address from station or access point

  • Hi,

    the problem:
    I want to create a wireless mesh network. with a LoPy as a endpoint and esp8266 as regular nodes. Every node is both a station and a access point. It seems that when a client connects to a access point, the access point uses something called "softAP" a virtual DHCP server. So technically the access point gives the client an ip address. Sooooo the problem is, how can you get that ip address that you give.

    It is possible to set a static ifconfig. But i want it dynamically..

  • @shariq I have the code below in, which sets up the device for connecting to my router with a fixed IP, which you then can use to access the device.

    WIFI_IP  = ""
    ROUTER_IP = "")
    WIFI_SSID = "your AP SSID"
    WIFI_PASS = "your AP Password"
    def do_connect():
        import network
        import time
        wlan = network.WLAN(mode=network.WLAN.STA) # create station interface
        if not wlan.isconnected():      # check if the station is connected to an AP
            wlan.ifconfig(config=(WIFI_IP, "", ROUTER_IP,  ROUTER_IP))
            wlan.connect(ssid=WIFI_SSID, auth=(network.WLAN.WPA2, WIFI_PASSWD))
            for _ in range(100):
                if wlan.isconnected():      # check if the station is connected to an AP
                print('.', end='')
                print("Connect attempt timed out\n")
        print('\nnetwork config:', wlan.ifconfig())

  • @robert-hh I want to access lopy remotely in atom ide with it being connected to same router, can you suggest pls

  • @livius Yes, I know. But in the AP the DHCP server has to be configured, and one of the seetings is the IP address of the gateway which it tells to its clients. That could be set to the IP adress of the LoPy, which acts as the endpoint. Obviously, another method would be to give the LoPy a fixed IP address, or at least a fixed value for the last byte. Then at least the clients can receive their IP adress from the DHCP server and access/determine the LoPy's address from that.

  • @robert-hh
    This is not the point
    he need to get address of connected client on AP side not on client side.

    Lopy(AP) <----- LoPy(STA) + Wlan.Connect..
    LoPy(AP) DHCP set some address for LoPy(STA)

    and he need to get address on LoPy(AP) side dynamically assigned to LoPy(STA)
    this is not common scenario but..

  • @andnil94 @livius
    ifconfig() returns a 4-tuple. The first is the own ip address, the 3rd the name of a gateway, which is normally not the AP, but an address, you configure in the AP. If your internet router is also AP, the the address of the router is distributed as gateway address. So you could use that with the endpoint's IP adress, which would have to be set fixed.
    B.t.w.: In a typical Home LAN the endpoint is the router, with addresses like

  • @andnil94
    hmm, from client node it is simple by ifconfig()
    but from "server" node i do not see how to get it
    if you do not connect by socket (accept) - only network link established

    @daniel @bucknall can you help here?

  • @livius Yes, only a network link is created. Every node has the same password and a node will only try to connect to a node with specific ssid prefix. E.g "ssid - xxxx". Am aware of the clock synchronization between the nodes. But after the network link is created, how can I communicate with the other nodes in the mesh network?

    Every node will sleep on the same given interval controlled by the master node. And when they wake up, every node will try mesh(connect to each other) in a static amount of time. first by connect by wlan, then either the host or client will create a socket with TCP as a protocol, and then connect to the client or host. Every node just listens on the socket. Only the master node can send data. I cannot connect all nodes to the master node. A node should connect to any arbitrary node. When the master node has sent the sleep command. All the tcp sockets gets closed, and the wlan is shut down. Then every node go to sleep on the same interval.

    I cannot connect to a node without an IP address. So yes the address before socket is created. Thank you!

  • @andnil94
    To do something like this - you must have clock synchronized between all meshes
    without this how can you accomplish this?:

    The connection is not permanent, they are only connected for a short amount of time.

    If you do not need to have all connected permanently then better is to connect "nodes" to "master node" in some interval and ask it if it need some data if not sleep again.

    but i forgot to answer your initial question
    look here for some sample - look for Simple HTTP server

    you should be interested about socket.accept it return you address
    Is this what you want?
    But i suppose that you talking about address before socket is created only network link established?

  • @livius Well you think of the LoPy as a remote. And I want it to broadcast different commands to the other nodes (esp8266). Esp8266 has sensors connected to it. So if i want to read from the sensors the LoPy can broadcast a message to all the other nodes. And then they can send the result back to the LoPy. The connection is not permanent, they are only connected for a short amount of time.

    Ty for answer

  • This post is deleted!

  • @andnil94
    I do not think that this is good way to accomplish this.
    Why do you need it? Do you try to have permanent connection between all meshes?
    Base your "protocol" on MAC(names) and list of networks scan.
    Autorize meshes and build list of accepted meshes. Then build neighborhood matrix and do e.g. BFS to find path. Save path.

    But maybe you have another concept?

Pycom on Twitter