Giter Club home page Giter Club logo

Comments (1)

loathingKernel avatar loathingKernel commented on July 4, 2024

The MAC address is different that the IP address as the NetEEPROM.readMAC(); returns a pointer to an array allocated in the memory. The readIP();, readGW(); and readSN(); return an object of type IPAddress.

In C++, functions can return object instances, much like they can return any other type, such as int, float, double and so on. But just like C, they cannot return an array. Instead of that, they can return a pointer to an array.

So what happens in the case of the first three is: somewhere in your code, before the call of NetEEPROM.readIP();
you have declared a variable ip with type IPAddress which is the class used by Arduino to store IP addresses.
What happens when you do something like ip = NetEEPROM.readIP(); is that the NetEEPROM.readIP(); reads the IP address and returns an IPAddress object, which is then copied to the ip variable through the = operator.
After that you can manipulate it as any other object of this type.

In the case of the MAC address, there isn't such an object, so it returns a pointer to a byte array. So to 'read' the MAC address you have to do something like byte *mac = NetEEPROM.readMAC();. After that you can get the individual elements of the array with mac[0] to mac[5]. To give you an example, this is how the MAC is printed in NetEEPROM.printNet(&serial);:

    byte* mac = readMAC();
    serial->print("    MAC: ");
    for(uint8_t i = 0; i < 6; i++) {
        serial->print("0x");
        serial->print(mac[i], HEX);
        if(i != 5) serial->print(".");
        else serial->println();
    }
    free(mac);

One more thing to notice is the free(mac); line. In the readMAC(); the array is being allocated in the memory, and it is not automatically freed. So after doing whatever you want with the MAC address, you should free it, otherwise, you will end up with all of the Arduino memory polluted with MAC arrays.

from ariadne-bootloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.