Frage

I'm currently working on an Arduino sketch, and need a way to convert the following mac address:

const char *ss = "00:1E:C0:04:9F:F3";

into a unit8_t*, so that I can use it as the argument for the network_set_MAC function below:

/Sets the MAC address of the device/ void network_set_MAC(uint8_t* mac);

Any ideas on how to do this within the Arduino IDE?

War es hilfreich?

Lösung

Automatically converting a text-representation to a machine-readable representation is harder than it looks. It would require some careful parsing.

Since you're hard-coding the MAC address into your sketch though, you don't need to worry about that. You can simply write it as an array of hexadecimal literals:

uint8_t mac[] = {0x00, 0x1E, 0xC0, 0x04, 0x9F, 0xF3};

In C++, an array type will happily decay to a pointer, so you should be able to pass it directly to your function like this:

network_set_MAC(mac);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top