skaarj1989/mWebSockets

The used network controller should be configurable from the sketch

Anton-V-K opened this issue · 15 comments

The approach with selecting the network controller inside the library's config.h is hardly usable in real projects - it is impossible to tweak it for every build.

There are several approaches which can address this issue:

  1. Wrap #define NETWORK_CONTROLLER ETHERNET_CONTROLLER_W5X00 with #ifnded NETWORK_CONTROLLER and #endif so if the build system support global defines, the project will choose the proper network controller.
  2. Do a meaningful guess of the network controller (e.g., when ESP8266 or ESP32 is defined, the chances are high that WiFi is used), so for rigid build systems (like the one in Arduino IDE) the library can be used as is.

Environment info

  • IDE w/version: Arduino IDE 1.8.16
  • Platform/Board: esp8266
  • Network controller (shield or module): WiFi

I've been thinking about refactoring into templates.
No more #define NETWORK_CONTROLLER in config.h. Instead, you will need to specialize the client/server.

WebSocketServer<WifiServer, WiFiClient> server;
WebSocketClient<EthernetClient> client;

Additionally you could use multiple network controllers in a single (more powerful) board.

Initial commit pushed into the meta branch.