On Boron with ethernet feather - Mqtt broker is gone when network is switched

Hi
I’m trying to find a way to deter when the Boron has switched networks. Using the EthernetCellularRK library, I’m successfully able to switch back and forth between Enternet and Cellular. But have not found a way to know that it switched. Since I’m using MQTT topics to update a MQTT broker, after the switch the MQTT connection is gone. Does any know a way to accomplish this. Tried testing when either EthernetIP or cellularIP = 0.0.0.0 but that never seems to occur. Any Ideas? Or at least point me in the right direction so I can do a client.disconnect() and the reconnect .
thanks.
5310

If you can connect to Particle cloud, you can use this tool. Here is some info:

https://community.particle.io/t/how-to-obtains-cellular-base-station-id/58397/2

I added two new functions to EthernetCellularRK that allow you to poll for the currently active interface, or register a callback function to notify when the interface changes. There are three states, NONE, ETHERNET, and CELLULAR.

0.0.2 (2021-10-13)

  • Added getActiveInterface() and withInterfaceChangeCallback()
5 Likes

Hi
Thanks. It a much better solution then the hack I came up with.

5310

Hi
Thanks for the quick fix. Could you please provide an example how to use this? It’s above my pay grade, sorry.

5310

Hi
Again thanks for adding this but I don’t have a clue how I get the value of activeInterface to be accessible in my program.

Tried
EthernetCellular::instance().getActiveInterface();

I would have expected it to just return an ‘int’ but your function is using ‘void’

Can you please help? I have not worked with ‘instance()’ before.

5310

Yes, you do use EthernetCellular::instance().getActiveInterface(). It doesn’t return a void, it returns a EthernetCellular::ActiveInterface. So you test it like:

if (EthernetCellular::instance().getActiveInterface() == EthernetCellular::ActiveInterface::CELLULAR)

Thank you so much. Guess it shows you never stop learning. Totally new to me.

5310

Hi
I’ve gotten the switching between cellular and Ethernet working using EthernetCellularRK but I am seeing issues when it switches to cellular. Sometimes it acts like it is rebooting and stops. Sometimes I get a green led that is is searching and than sometime it switches without a problem. My bigger issue is I run a connection to a MQTT broker that after switching doesn’t seem to ever reconnect again. I tried using a unique MQTT ID and increased alivetime, and added a wait for cellular.ready before doing the client.connect. If I switch from Ethernet to Cellular, it goes through what looks like a reboot and stops but I get a valid IP. If I reconnect the Ethernet again it does a reboot thing, and reconnects successfully and continues mqtt messages right there it left off. Does anyone have any ideas? What am I missing? I have also checked the logs of the broker and see a connect that a disconnection when it starts switching.

LOST…

5310

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.