Open MicSG-dev opened 2 months ago
you can use my EthernetESP32 library
https://github.com/espressif/arduino-esp32/pull/9522#issuecomment-2066815363
Hey @JAndrassy
I am using the ArduinoOTA bundled library, and I would like to use a custom MAC address or static IP. I am using the W5500 ethernet module Does your custom EthernetESP32 library work with ArduinoOTA (which uses ETH.cpp) ?
If your library doesn't work with ArduinoOTA, could you point me to what you changed in order to set it. I could try and hack around ETH.cpp to port this particular change.
@me-no-dev tagging you as well in case you can help
Ei@JAndrassy
Estou usando a biblioteca empacotada ArduinoOTA e gostaria de usar um endereço MAC personalizado ou IP estático. Estou usando o módulo ethernet W5500. Sua biblioteca EthernetESP32 personalizada funciona com ArduinoOTA (que usa ETH.cpp)?
Se sua biblioteca não funcionar com ArduinoOTA, você poderia me indicar o que você alterou para configurá-la. Eu poderia tentar hackear o ETH.cpp para portar essa alteração em particular.
@me-no-devmarcando você também caso possa ajudar
Replace the ArduinoOTA library with the Update.h library, which is compatible with ETH.h (see a basic example here, but if you are going to use a webserver to perform the update, I suggest using it together with the ESPAsyncWebServer library).
To set a static IP address, use the config method (from the ETH library) with the following parameters:
Usage example:
#include <ETH.h>
void setup() {
// Initialize the Ethernet interface
ETH.begin();
// Defining the parameters for the static IP
IPAddress local_ip(192, 168, 1, 100); // static IP
IPAddress gateway(192, 168, 1, 1); // Gateway
IPAddress subnet(255, 255, 255, 0); // Subnet mask
IPAddress dns1(8, 8, 8, 8); // First DNS server (Google DNS)
IPAddress dns2(8, 8, 4, 4); // Second DNS server (Google DNS)
IPAddress dns3(1, 1, 1, 1); // Third DNS server (Cloudflare DNS, optional)
// Setting the static IP
ETH.config(local_ip, gateway, subnet, dns1, dns2, dns3);
// Your code here
}
void loop() {
// Main code
}
To set a custom MAC address, I'm using a library, which I forked from this main one, that allows you to set a custom MAC address: github.com/MicSG-dev/ETH-Mac. Usage example:
uint8_t mac[6] = {0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5D};
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI, mac)
@JAndrassy I tried your library and I am seeing this conflicting declaration error:
In file included from /home/user/Arduino/libraries/EthernetESP32/src/EthernetESP32.h:4,
from /home/user/projects/smartpadel/smartpadelFW/src/ProdinoOTA.cpp:51:
/home/user/Arduino/libraries/EthernetESP32/src/utility/EMACDriver.h:32:3: error: 'ETH_PHY_LAN8720' conflicts with a previous declaration
32 | ETH_PHY_LAN8720,
| ^~~~~~~~~~~~~~~
In file included from /home/user/projects/smartpadel/smartpadelFW/src/ProdinoOTA.cpp:1:
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.5/libraries/Ethernet/src/ETH.h:101:3: note: previous declaration 'eth_phy_type_t ETH_PHY_LAN8720'
101 | ETH_PHY_LAN8720,
| ^~~~~~~~~~~~~~~
/home/user/Arduino/libraries/EthernetESP32/src/utility/EMACDriver.h:33:3: error: 'ETH_PHY_TLK110' conflicts with a previous declaration
33 | ETH_PHY_TLK110,
| ^~~~~~~~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.5/libraries/Ethernet/src/ETH.h:102:3: note: previous declaration 'eth_phy_type_t ETH_PHY_TLK110'
102 | ETH_PHY_TLK110,
| ^~~~~~~~~~~~~~
/home/user/Arduino/libraries/EthernetESP32/src/utility/EMACDriver.h:34:3: error: 'ETH_PHY_RTL8201' conflicts with a previous declaration
34 | ETH_PHY_RTL8201,
| ^~~~~~~~~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.5/libraries/Ethernet/src/ETH.h:103:3: note: previous declaration 'eth_phy_type_t ETH_PHY_RTL8201'
103 | ETH_PHY_RTL8201,
| ^~~~~~~~~~~~~~~
/home/user/Arduino/libraries/EthernetESP32/src/utility/EMACDriver.h:35:3: error: 'ETH_PHY_DP83848' conflicts with a previous declaration
35 | ETH_PHY_DP83848,
| ^~~~~~~~~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.5/libraries/Ethernet/src/ETH.h:104:3: note: previous declaration 'eth_phy_type_t ETH_PHY_DP83848'
104 | ETH_PHY_DP83848,
| ^~~~~~~~~~~~~~~
/home/user/Arduino/libraries/EthernetESP32/src/utility/EMACDriver.h:37:3: error: 'ETH_PHY_MAX' conflicts with a previous declaration
37 | ETH_PHY_MAX
| ^~~~~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.5/libraries/Ethernet/src/ETH.h:117:3: note: previous declaration 'eth_phy_type_t ETH_PHY_MAX'
117 | ETH_PHY_MAX
| ^~~~~~~~~~~
exit status 1
Compilation error: exit status 1
Am I doing something wrong or is this a bug in the library?
Do I need to replace the bundled Ethernet library with yours?
don't use both ETH.h and EthernetESP32.h in same sketch
Thanks very much. I can confirm your library works like a charm
Related area
Mac Address Ethernet W5500 SPI
Hardware specification
ESP32 DevKitC
Is your feature request related to a problem?
Currently the MAC address configuration in the ETH library happens internally, so the user cannot decide which MAC address he wants to use.
Describe the solution you'd like
I want it to be possible to change the MAC address through the begin function of the ETH.h library.
Describe alternatives you've considered
The solution would be to create a new method for the ETH library. See below: File ETH.h, line 125:
BEFORE:
AFTER:
File ETH.cpp, line 810:
BEFORE:
AFTER:
Additional context
The usage of this new library method would be:
I have checked existing list of Feature requests and the Contribution Guide