How to query the board selected for the project?

Hello
I’m wondering is it possible to query in the code the board that I have selected when creating the project?
I want to do something like this
snippet:


#if defined(ESP32)
#include <WiFi.h>
char deviceType[ ] = “ESP32”;
#else
#include <ESP8266WiFi.h>
char deviceType[ ] = “ESP8266”;
#endif

Or is there another way to achieve this?
Thanks in advance.

PlatformIO with Arduino extension on Linux.

Thanks for the quick reply but I’m not sure whether it’s addressing my problem.
I want to determine which include statement I have to execute (#include <WiFi.h>) or (#include <ESP8266Wifi.h> (conditional) depending in the board/platform that is defined in PlatformIO (That’s why #if defined() ).
Perhaps something like:

IF PlatformIO.Platform = “Espressif8266” Then #include <ESP8266WiFi.h>
ELSEIF PlatformIO.Platform = Espressif32" Then #include <WiFi.h>
#ENDIF

I hope that makes sense. :slight_smile:

This is exactly correct already. When building for any ESP32* board and framework = arduino, the macro ESP32 will be defined by the builder script, as it would also be in the Arduino IDE. The ARDUINO_ARCH_XXX macros are also a good discriminator. For example, for ESP32, ARDUINO_ARCH_ESP32.

It would be ESP8266 or ARDUINO_ARCH_ESP8266 in the ESP8266 case. (example).

That is so cool.
Thanks for sharing.

Is there also macro for Arduino (Uno) board? (AVR ?)
(That would be the last branch of the if-else-endif construct.)
TY

ARDUINO_ARCH_AVR per

It’s amazing what you all know. :smiley:
Thank you.

Is there perhaps some documentation about all these macros that can be used without searching and looking in the source code?
I was looking already at PlatformIO IDE — PlatformIO latest documentation but wasn’t successful yet in my effort.
Any suggestion is much appreciated.

If needed, I can post a short snippet of my code that demonstrates what I’m looking for.

Thanks fellows.