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

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

    Scheduled Pinned Locked Moved LoPy
    wlansocketnetworkmesh
    12 Posts 4 Posters 4.8k Views 4 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.
    • L Offline
      livius @andnil94
      last edited by livius

      @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?

      think about people first, then computers

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        andnil94
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • A Offline
          andnil94 @livius
          last edited by

          @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

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

            @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
            https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/network_tcp.html

            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?

            think about people first, then computers

            A 1 Reply Last reply Reply Quote 0
            • A Offline
              andnil94 @livius
              last edited by

              @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?

              Summarize:
              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!

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

                @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?

                think about people first, then computers

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

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

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    livius @robert-hh
                    last edited by livius

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

                    Lopy(AP) <----- LoPy(STA) + Wlan.Connect..
                    and 
                    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..

                    think about people first, then computers

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

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

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        shariq @robert-hh
                        last edited by

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

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

                          @shariq I have the code below in main.py, 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  = "aa.bb.cc.ss"
                          ROUTER_IP = "aa.bb.cc.rr")
                          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, "255.255.255.0", 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
                                          break
                                      print('.', end='')
                                      time.sleep_ms(200)
                                  else:
                                      print("Connect attempt timed out\n")
                                      return
                              print('\nnetwork config:', wlan.ifconfig())
                          
                          do_connect()
                          
                          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