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

Choosing between WiFi and Ethernet during runtime #128

Open
baender opened this issue Dec 19, 2024 · 5 comments
Open

Choosing between WiFi and Ethernet during runtime #128

baender opened this issue Dec 19, 2024 · 5 comments

Comments

@baender
Copy link

baender commented Dec 19, 2024

This issue is similar to #85 but I was not able to solve it the way it was suggested.

Situation:

The user shall be able to choose between Art-Net via WiFi or Ethernet during runtime.

Initially I thought, I could pass the interface of choice to a generalized Artnet class (e.g an artnet.setInterface() method) . I realized, that this is not possible. Therefore, I tried to have one instance of each class using only one of the two.

When including ArtnetWiFi.h AND ArtnetEther.h I get a compiler error, when parsing Artnet (ethernet). That is not surprising since the library documentation explicitly says NOT to include both.

Here is my minimal example:

#include <ArtnetWiFi.h>
#include <ArtnetEther.h>

ArtnetWiFiReceiver artnetWiFi;
ArtnetReceiver artnetEthernet;

bool useWiFi;


void receiveArtNetWiFiCallback(const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {
  // do nothing
}

void receiveArtNetEthernetCallback(const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {
  // do nothing
}


void setup() {
  useWiFi = false;  // defined during runtime

  if (useWiFi) {
    WiFi.begin("ssid", "password");
    artnetWiFi.begin();
    artnetWiFi.subscribeArtDmxUniverse(0, receiveArtNetWiFiCallback);
  } else {
    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
    Ethernet.begin(mac);
    artnetEthernet.begin();
    artnetEthernet.subscribeArtDmxUniverse(0, receiveArtNetEthernetCallback);
  }
}


void loop() {
  if (useWiFi) {
    artnetWiFi.parse();
  } else {
    artnetEthernet.parse();  // Triggers the compiler error
  }
}

These are the compiler errors

.pio/libdeps/arduino_nano_esp32/ArtNet/Artnet/Receiver.h:378:25: error: no matching function for call to 'art_net::Receiver_<EthernetUDP>::localIP()'

.pio/libdeps/arduino_nano_esp32/ArtNet/Artnet/Receiver.h:380:9: error: no matching function for call to 'art_net::Receiver_<EthernetUDP>::macAddress(uint8_t [6])'

I wonder if there is any way I can support both interfaces on runtime.

Information to my setup:
Board: Arduino Nano ESP32
ArtNet: 0.8.0
Ethernet: 2.0.2

@hideakitai
Copy link
Owner

Making multiple interfaces available would be possible, but this is not currently planned.

Out of curiosity, in what situations would both Ethernet and WiFi interfaces be needed?

@Petzl026
Copy link

The one could be the Backup of the other ohne if for example wired would fail you could use WiFi till you fix wired again

@hideakitai
Copy link
Owner

hideakitai commented Dec 22, 2024

Is it difficult to switch Ethernet/WiFi in the preprocessor (e.g., #ifdef) and rewrite the program again? Do you want to make it so that it is impossible to rewrite, and if you start the program while pressing some physical button, it will switch to Ethernet/WiFi?

@baender
Copy link
Author

baender commented Dec 22, 2024 via email

@hideakitai
Copy link
Owner

hideakitai commented Dec 23, 2024

Okay, I see several requests to use both Wi-Fi and Ethernet. I don't know when I can support this, as I am working on it in my spare time, but I will look into improving the ability to use multiple backends simultaneously. Of course, pull requests are welcome.

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

3 participants