Dear all,
I have a project with ESP32 and using Wifi or Ethernet (W5500), selectable via UI, and connecting via Wireguard to Home Assistant.
Over Wifi, Wireguard working fine. But over ethernet not.
I discused it with @Juraj , use ESP platform 3+.
This thread is closed
If I compilling code, I get this error
C:\Users\j.jirutka\Documents\Arduino\libraries\WireGuard-ESP32\src\wireguardif.c:51:10: fatal error: tcpip_adapter.h: No such file or directory
51 | #include "tcpip_adapter.h"
| ^~~~~~~~~~~~~~~~~
compilation terminated.
C:\Users\j.jirutka\Documents\Arduino\libraries\WireGuard-ESP32\src\wireguardif.c:925:33: error: 'TCPIP_ADAPTER_IF_STA' undeclared (first use in this function)
925 | tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_STA, &underlying_netif);
| ^~~~~~~~~~~~~~~~~~~~
C:\Users\j.jirutka\Documents\Arduino\libraries\WireGuard-ESP32\src\wireguardif.c:925:33: note: each undeclared identifier is reported only once for each function it appears in
Is there a straightforward solution to my problem please?
The device used in tcpip is decided by the metric value assigned to that device.
How are you determining which network device is handling your traffic?
A connection object is not defined in the Wireguard examples.
Only then does the communication object itself determine the client, in my case Home Assistant Integration, to use
I still have the main program where everything works except wireguard. Ethernet connects, web interface works. It is too large for publication.
I first test each software component in simple programs based on examples from the libraries.
I don't use wifi and ethernet at the same time, just one of them. But the choice is given by the user in UI, not defined in the source code. So, in main program is bool for choice.
It works by loading the MAC address of the ESP from Wifi into a byte array, and using that mac address for ethernet. I have tried it.
So you have 2 network devices with duplicate mac addresses connected to the same router? Is that correct?
Edit: This can be done, but not at the same time. I've done this before. It's called "mac spoofing". Connect to a wifi net, watch traffic. Determine which mac addresses get immediate access without logging in. Change your wifi device to that mac. Connect.
No, only one device connects at a time. The user chooses the connection method (Wifi or ethernet) in the UI.
Here is part of the source code for the full main connection initialization program.
Ethernet.init( 5 );
if ( !exchange_data.wifi_enable ) {
debug.println( F("Setup Ethernet..."));
if ( ethernet_config.use_dhcp ) {
if ( Ethernet.begin( mac )) { // Dynamic IP setup
debug.println( F(" ETH DHCP OK!"));
debug.print( F(" ETH Status: "));
debug.print( String( Ethernet.linkStatus()));
if ( Ethernet.linkStatus() == 1 ) ethernet_connected = true; else ethernet_connected = false;
} else {
debug.println( F("Failed to configure Ethernet using DHCP"));
}
delay( 2000 );
debug.print( F(" Local IP : "));
debug.println( Ethernet.localIP());
debug.print( F(" Subnet Mask : "));
debug.println( Ethernet.subnetMask());
debug.print( F(" Gateway IP : "));
debug.println( Ethernet.gatewayIP());
debug.print( F(" DNS Server : "));
debug.println( Ethernet.dnsServerIP());
debug.println( F(" Ethernet Successfully Initialized"));
} else {
Ethernet.begin( mac , ethernet_config.ip , ethernet_config.dns_server , ethernet_config.gateway , ethernet_config.subnet );
if ( Ethernet.linkStatus() == LinkON ) ethernet_connected = true; else ethernet_connected = false;
debug.println( F(" ETH STATIC OK!"));
}
}
// WIFI
if ( exchange_data.wifi_enable ) {
debug.println( F("Setup Wifi..."));
WiFi.mode( WIFI_STA );
if ( ethernet_config.use_dhcp ) {
if ( WiFi.begin( exchange_data.wifi_ssid , exchange_data.wifi_psw )) {
debug.println( F(" WIFI DHCP OK!"));
debug.print( F(" WIFI Status: "));
debug.println( String( WiFi.status()));
if ( WiFi.status() == 6 ) wifi_connected = true; else wifi_connected = false;
} else {
debug.println( F("Failed to configure Wifi using DHCP"));
}
delay( 2000 );
debug.print( F(" Local IP : "));
debug.println( WiFi.localIP());
debug.print( F(" Subnet Mask : "));
debug.println( WiFi.subnetMask());
debug.print( F(" Gateway IP : "));
debug.println( WiFi.gatewayIP());
debug.println( F(" Wifi Successfully Initialized"));
} else {
WiFi.config( ethernet_config.ip , ethernet_config.gateway , ethernet_config.subnet , ethernet_config.dns_server );
if ( WiFi.begin( exchange_data.wifi_ssid , exchange_data.wifi_psw )) {
debug.println( F(" WIFI STATIC OK!"));
if ( WiFi.status() == WL_CONNECTED ) wifi_connected = true; else wifi_connected = false;
}
if ( WiFi.status() == WL_CONNECTED ) wifi_connected = true; else wifi_connected = false;
}
}
As you see, the bool
exchange_data.wifi_enable
is choice, what connection is selected.
The entire device has a uniform mac address, extracted from Wifi.
This ethernet/wifi init code working fine.
In the project, I has another device services, as a WebUI, MODBUS TCP and this working via selected connection.
But Wireguard not, only over Wifi.