Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not discovered if used two connection types #259

Open
proasnet opened this issue Jul 9, 2024 · 1 comment
Open

Not discovered if used two connection types #259

proasnet opened this issue Jul 9, 2024 · 1 comment

Comments

@proasnet
Copy link

proasnet commented Jul 9, 2024

Dear @dawidchyrzynski, very thanks for your library.

In my project with ESP32 I am using two connection types ( Wifi or Ethernet W5500 ) selectable via UI, so only one connection in time, not simultaneously

WiFiClient wificlient;
EthernetClient ethernetclient;

HADevice device;
HAMqtt wifi_mqtt( wificlient , device , 40 );
HAMqtt ethernet_mqtt( ethernetclient , device , 40 );

If I comment "//" one of them, discovery working. Else not.
Is any way for use both constructors and working discovery by HA?
Thank you

@proasnet
Copy link
Author

proasnet commented Jul 19, 2024

I am trying another methods...
Method 1:

WiFiClient wificlient;
EthernetClient ethernetclient;

HADevice device;
HAMqtt *mqtt;

void setup() {
  if ( ethernet_connected ) {
    mqtt = new HAMqtt( ethernetclient , device , 40 );
    debug.println( "eth MQTT" );
  }

  if ( wifi_connected ) {
    mqtt = new HAMqtt( wificlient , device , 40 );
    debug.println( "wifi MQTT" );
  }
}

Method 2:

Client *client;

HADevice device;
HAMqtt *mqtt;

void setup() {
  if ( ethernet_connected ) {
    client = new EthernetClient;
    debug.println( "eth MQTT" );
  }

  if ( wifi_connected ) {
    client = new WifiClient;
    debug.println( "wifi MQTT" );
  }
  mqtt = new HAMqtt( client , device , 40 );
}

Compile is work fine, but not discovered too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant