Bind socket to different interface

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
KonssnoK
Posts: 2
Joined: Thu Sep 16, 2021 1:53 pm

Bind socket to different interface

Post by KonssnoK » Thu Sep 16, 2021 2:02 pm

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!

KonssnoK
Posts: 2
Joined: Thu Sep 16, 2021 1:53 pm

Re: Bind socket to different interface

Post by KonssnoK » Fri Sep 17, 2021 7:50 am

i think the answer is

Code: Select all

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

Post Reply