Aatif Shaikh
Aatif Shaikh

Reputation: 345

How to get Arduino/ESP32 device details in code?

I'm working on a project in which there is a server and several clients (ESP32). In short, It's client-server communication over WIFI. Right now, I'm using ESP32-wroom-32D. In future, for a client device, I might use some other Arduino device or other ESP32 module or a combination of both. For code simplicity, I shall be using the same code for both types of devices (Arduino/ ESP32) as they support a common Arduino platform. Therefore, I want to know if there is a way which I can get the device's information.

Eg. Function: Get_device_details( ) or Get_device_id( ).

Output: "ESP32-Wroom-32D" or "Arduino Mega 2560"

Upvotes: 1

Views: 4336

Answers (2)

balun
balun

Reputation: 1324

For esp boards, you can use the following arduino code to get chip ID,

#ifdef ESP8266
int chip_id = ESP.getChipId();
#elif defined(ESP32)
int chip_id = ESP.getEfuseMac();
#endif

Upvotes: 1

Juraj
Juraj

Reputation: 3736

The Arduino defines to identify a board are in form of ARDUINO_<board>, where <board> is the value from <x>.build.board from boards.txt for board <x>

For example for Arduino AVR boards, in the boards.txt file is uno.build.board=AVR_UNO so the define is ARDUINO_AVR_UNO.

And Arduino has 'architecture' identification define too. This has form of ARDUINO_ARCH_<arch.name>. The <arch.name> is the uppercase version of the folder name with the boards package version. For example AVR for packages/arduino/hardware/avr/1.6.21.

Upvotes: 1

Related Questions