Teensy 4.1 Using both Ethernet and Wifi?

karl101

Member
Hello

On this teensy 4.1 I have a wired Ethernet connection on the hardware port as well as a ESP-01s attached to Serial8. Individually they work as expected, but when I include both of them in the program, the compiler complains with a load of already defined (below) errors and exits.

The .h files I've been using are (this is enough to cause the error):
Code:
#include <WiFiEsp.h>
#include <QNEthernet.h>
#include <QNEthernetUDP.h>

WiFiEspClient wlanClient;

namespace qn = qindesign::network;
qn::EthernetClient ethClient;
qn::EthernetUDP Udp;
QNEthernet from : https://github.com/ssilverman/QNEthernet
WiFiEsp: https://github.com/bportaluri/WiFiEsp

Those errors:
Code:
Compiling .pio\build\teensy41\src\main.cpp.o
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:103:16: error: redeclaration of 'CLOSED'
  CLOSED      = 0,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:57:3: note: previous declaration 'tcp_state CLOSED'
   CLOSED      = 0,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:104:16: error: redeclaration of 'LISTEN'
  LISTEN      = 1,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:58:3: note: previous declaration 'tcp_state LISTEN'
   LISTEN      = 1,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:105:16: error: redeclaration of 'SYN_SENT'
  SYN_SENT    = 2,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:59:3: note: previous declaration 'tcp_state SYN_SENT'
   SYN_SENT    = 2,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:106:16: error: redeclaration of 'SYN_RCVD'
  SYN_RCVD    = 3,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:60:3: note: previous declaration 'tcp_state SYN_RCVD'
   SYN_RCVD    = 3,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:107:16: error: redeclaration of 'ESTABLISHED'
  ESTABLISHED = 4,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:61:3: note: previous declaration 'tcp_state ESTABLISHED'
   ESTABLISHED = 4,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:108:16: error: redeclaration of 'FIN_WAIT_1'
  FIN_WAIT_1  = 5,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:62:3: note: previous declaration 'tcp_state FIN_WAIT_1'
   FIN_WAIT_1  = 5,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:109:16: error: redeclaration of 'FIN_WAIT_2'
  FIN_WAIT_2  = 6,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:63:3: note: previous declaration 'tcp_state FIN_WAIT_2'
   FIN_WAIT_2  = 6,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:110:16: error: redeclaration of 'CLOSE_WAIT'
  CLOSE_WAIT  = 7,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:64:3: note: previous declaration 'tcp_state CLOSE_WAIT'
   CLOSE_WAIT  = 7,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:111:16: error: redeclaration of 'CLOSING'
  CLOSING     = 8,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:65:3: note: previous declaration 'tcp_state CLOSING'
   CLOSING     = 8,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:112:16: error: redeclaration of 'LAST_ACK'
  LAST_ACK    = 9,
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:66:3: note: previous declaration 'tcp_state LAST_ACK'
   LAST_ACK    = 9,
   ^
In file included from .pio\libdeps\teensy41\WiFiEsp\src/WiFiEsp.h:30:0,
                 from src\main.cpp:21:
.pio\libdeps\teensy41\WiFiEsp\src/utility/EspDrv.h:113:16: error: redeclaration of 'TIME_WAIT'
  TIME_WAIT   = 10
                ^
In file included from lib\QNEthernet\src/lwip/tcp.h:45:0,
                 from lib\QNEthernet\src/internal/ConnectionState.h:14,
                 from lib\QNEthernet\src/internal/ConnectionHolder.h:13,
                 from lib\QNEthernet\src/QNEthernetClient.h:18,
                 from lib\QNEthernet\src/QNEthernet.h:19,
                 from src\main.cpp:18:
lib\QNEthernet\src/lwip/tcpbase.h:67:3: note: previous declaration 'tcp_state TIME_WAIT'
   TIME_WAIT   = 10
   ^
*** [.pio\build\teensy41\src\main.cpp.o] Error 1

Is there anyway of getting these two to lay nice together without having to go into one of them and change the declaration names, or have I missed something obvious?

Thanks
Karl.
 
One way to fix this that I think might work is to include these library headers separately in two different compilation units instead of both from the main file.
 
Back
Top