lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] switch between pppos and ethernet netif


From: Bas Prins
Subject: [lwip-users] switch between pppos and ethernet netif
Date: Fri, 19 Jan 2024 09:36:38 +0100

Hi,
I am hoping somebody can give me some pointers managing two netif's in lwip.
We have an MCU which has a modem connected to uart, and an ethernet connector. If both peripherals are available, and working, it's up to user settings which interface to prefer as default.

What I currently do (very suboptimal) is:
- check if the modem is present, initialize it through AT commands and use lwip to setup PPP.
- in parallel, check if ethernet PHY get autonegotiate, and use lwip to get an IP address through dhcp
- depending on configuration I set either one of them default.
- connect mqtt to a broker, and start

During operation, I monitor PHY, and I monitor the mqtt disconnects. When either PHY detects a link down on ethernet, or when mqtt disconnects, the following happens:
- if on ethernet, and link remains down, switch to pppos
- if on pppos, and mqtt can't reconnect, switch to ethernet
- try to reach a known server on the internet
- reconnect mqtt
- continue

The "switching" between ethernet/pppos is done "wrong" (I think). I simply set the desired netif as default. So if pppos was default, then I set the ethernet netif as default. When ethernet netif was default, then i set pppos as default.

That works, but has the consequence that lwip/mqtt will disconnect. Depending on the timeout I choose for mqtt, the board is temporarily unreachable.(we use mqtt to receive commands from  som remote server)

Initially, I started out with adding both netif's, setting ethernet as "default", and use the lwip api to set ethernet link up/down  (netifapi_netif_set_link_up/netifapi_netif_set_link_down). But this just leaves one netif available for lwip which it will never use in my case.

Is it possible to do something like that when I set things up properly? Can lwip use multiple netif and can I specify dynamically which of the known netifs it should prefer when the corresponding netif has the flag "link up', but skip that netif in case the netif has the flag link down?

So what I would like more specifically: prefer ethernet, but when link is down, use pppos. And then, if the link comes up again, switch to ethernet.

Or maybe better put: I want to be able to set pppos as "default", but when ethernet is available, have lwip prefer the ethernet netif.

Best regards, Bas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]