Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch Mac address from Ethernet module instead of using hardcoded value. #172

Open
tyeth opened this issue May 28, 2024 · 1 comment
Open

Comments

@tyeth
Copy link

tyeth commented May 28, 2024

A user emailed Adafruit IO support suggesting an improvement to the IO library to fetch the Ethernet mac address before starting the module:

Hello! I'm Gavin, I made an adafruit.io related application, and adafruit's blog also reported on this application: https://blog.adafruit.com/2024/05/24/a-raspberry-pi-pico-board-with-dvi-video-and-ethernet/

I am using "Adafruit IO Arduino 4.3", the MAC address for Ethernet initialization is defined and initialized in: Adafruit_IO_Arduino/src
/AdafruitIO_Ethernet.h

But there are some unreasonable things about doing this:
If the user uses several devices: they need to change the MAC address of each device in the library, otherwise multiple devices will not work at the same time (because the devices have the same MAC address);

Can my suggestion be changed to this?

STEUP() in Sketch:

   Ethernet.begin(mac);
   // connect to io.adafruit.com
   adafruit_io.connect();</p>

Change AdafruitIO_Ethernet.h to this, first read the MAC address from the WIZnet chip, and then re-initialize:

   void _connect() {
     byte macAddress_[6];
     Ethernet.MACAddress(macAddress_); //read mac address from Wiznet Chip
     if (Ethernet.begin(macAddress_) == 0) {
       _status = AIO_NET_DISCONNECTED;
       if (Ethernet.hardwareStatus() == EthernetNoHardware) {
         AIO_DEBUG_PRINTLN("Ethernet FeatherWing not found! Please recheck "
                           "wiring connections.");
         while(true)
           delay(1); // do nothing, no point running without Ethernet hardware
       }
     } else {
       // Ethernet.MACAddress(macAddress_);
       // for (int i = 0; i &lt; 6; i++) {
       // Serial.print(macAddress_[i], HEX);
       // if (i &lt; 5) Serial.print(':');
       // }
       _status = AIO_NET_CONNECTED;
     }
   }

This eliminates the need to change the MAC address every time you enter the library file.

@tyeth
Copy link
Author

tyeth commented May 28, 2024

It's probably worth looking at #149 and closing that at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant