STM32Ethernet icon indicating copy to clipboard operation
STM32Ethernet copied to clipboard

Ethernet.MACAddress should be a getter, not setter

Open JAndrassy opened this issue 1 year ago • 5 comments

Ethernet.MACAddress should be a getter, not setter

https://github.com/arduino-libraries/Ethernet/blob/39103da0e1bc569023625ee4693272773397dbb6/src/Ethernet.cpp#L147-L153

void EthernetClass::MACAddress(uint8_t *mac_address)
{
	SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
	W5100.getMACAddress(mac_address);
	SPI.endTransaction();
}

JAndrassy avatar Dec 24 '23 13:12 JAndrassy

I'm confused, what is the problem for this library? You mention the Arduino Ethernet library which uses the WIZnet chips.

sstaub avatar Dec 24 '23 14:12 sstaub

in this library it is a setter. that is wrong

JAndrassy avatar Dec 24 '23 15:12 JAndrassy

Have a look to the documentation. The implementation is different to the original Arduino library. This is necessary to override builtin mac address.

sstaub avatar Dec 24 '23 16:12 sstaub

Agreed with @sstaub . Getter is available with different prototype which is more clear: https://github.com/stm32duino/STM32Ethernet/blob/cd50f45d53fefd1b947b2a2552f672f328321a3f/src/STM32Ethernet.cpp#L136C1-L136C1

fpistm avatar Dec 24 '23 16:12 fpistm

isn't Arduino about using same functions on different hardware? at least functions with the same name should do the same thing.

Arduino Ethernet libraries have MACAddress and WiFi libraries have macAddress as a getter, as a way to read the MAC address. I few libraries have setMACAddress, but usually the way to set the MAC address in Ethernet library is the first parameter of begin

A few months back I stared to write down all my experience with creating and maintaining Arduino networking libraries, because new libraries appear and have the same mistakes I try to eliminate in old libraries. But writing the Guide let to necessity of defining the networking API by analyzing the significant libraries. I found many often simple differences so I started to do PR in all repositories. Then I wrote test sketches for basic functions and those found more errors in implementations than I would expect (even in my libraries.). So more PR.

https://github.com/JAndrassy/Arduino-Networking-API

JAndrassy avatar Dec 24 '23 20:12 JAndrassy