Generating a serial number based on a MAC address

Hi, back again with my Rally Rampage button programming issues.
I am getting an error connected to generating a serial number based on a MAC address.
I have tried the suggested change by IDE but to no avail.
I have the following error - 'ESP_MAC_WIFI_STA' was not declared in this scope

My code


// Function to generate a serial number based on the last 3 bytes of the MAC address
// Function to generate a 6-digit serial number based on the last 3 bytes of the MAC address
String generateSerialNumber() {
  uint8_t baseMac[6];
  esp_read_mac(baseMac, ESP_MAC_WIFI_STA); // Read the MAC address
  // Extract the last 3 bytes of the MAC address and convert them to a 6-character string
  char serialNumber[7]; // 6 hex digits + null terminator
  sprintf(serialNumber, "%02X%02X%02X", baseMac[3], baseMac[4], baseMac[5]);

  return String(serialNumber); // Return the 6-character serial number
}

Try:

	uint8_t macAddrBytes[6];
	WiFi.macAddress(macAddrBytes);

or

	String macAddrString {WiFi.macAddress()};

Hi, I get the same. I have tried both and still getting errors.

The functions I posted compile fine for me.

You haven't supplied enough information. Post a complete code that demonstrates the error. Tell us which version of the ESP32 Arduino Core you are using.

Hi @sloth1 ,

ESP_MAC_WIFI_STA is of type enum and defined in the file "esp_mac.h" ...

See here
https://github.com/espressif/esp-idf/blob/master/components/esp_hw_support/include/esp_mac.h

typedef enum {
    ESP_MAC_WIFI_STA,      /**< MAC for WiFi Station (6 bytes) */
    ESP_MAC_WIFI_SOFTAP,   /**< MAC for WiFi Soft-AP (6 bytes) */
    ESP_MAC_BT,            /**< MAC for Bluetooth (6 bytes) */
    ESP_MAC_ETH,           /**< MAC for Ethernet (6 bytes) */
    ESP_MAC_IEEE802154,    /**< if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) */
    ESP_MAC_BASE,          /**< Base MAC for that used for other MAC types (6 bytes) */
    ESP_MAC_EFUSE_FACTORY, /**< MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) */
    ESP_MAC_EFUSE_CUSTOM,  /**< MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) */
    ESP_MAC_EFUSE_EXT,     /**< if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) */
} esp_mac_type_t;

If you get the error message 'ESP_MAC_WIFI_STA' was not declared in this scope a link to this file is missing, either a direct include in your code or (most likely) a missing include of another library that includes this file or you haven't chosen the correct board setup ...

As @gfvalvo wrote: To find the reason requires that you post your complete code ...

Good luck!
ec2021

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.