Page 1 of 1

Bind socket to different interface

Posted: Thu Sep 16, 2021 2:02 pm
by KonssnoK
Hello,
I am using an ESP32 with both ETH (lan8720) and WIFI.

How can i choose which interface to use when creating a socket?

basically i have both:

Code: Select all

        self.sta_if = network.WLAN(network.STA_IF)
        
        self.eth = network.LAN(id = 0, 
                    mdc = machine.Pin(23), 
                    mdio = machine.Pin(18), 
                    power = None, 
                    phy_addr = 1, 
                    phy_type = network.PHY_LAN8720)

Thanks!

Re: Bind socket to different interface

Posted: Fri Sep 17, 2021 7:50 am
by KonssnoK
i think the answer is

Code: Select all

s = socket.socket()
s.bind(self.eth.ifconfig()[0])
but haven't tried yet