Using ESP32 and ESP8266 with the same source file
/If you want to use the same solution on both ESP8266 and ESP32 devices you find that there are a few inconsitencies between their libraries and include files. I've made this tiny set of conditional includes which pulls in the properly named elements for each processor. It also provides a symbol called PROC_ID that returns the processsor ID in a way that can be used in both types of program.
#if defined(ARDUINO_ARCH_ESP32)
#include <Arduino.h>
#include <WiFi.h>
#include <DNSServer.h>
#include <WiFiUdp.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <HTTPUpdate.h>
#include <WebServer.h>
#define LED_BUILTIN 2
#define PROC_ID (unsigned long)ESP.getEfuseMac()
#define PROC_NAME "ESP32"
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <WiFiClientSecure.h>
#include <ESP8266httpUpdate.h>
#include <ESP8266WebServer.h>
#define PROC_ID (unsigned long)ESP.getChipId()
#define PROC_NAME "ESP8266"
#endif
Just put this at the top of your program and when you build your program it will pull in the files that it needs.