Greetings,
i am trying to make a piece if code compile on both ESP8266 and ESP32.
there are differences in library names and parameters, which i solve like this
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#include <SPIFFS.h>
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#define FILE_MODE_R "r"
#define FILE_MODE_W "w"
typedef ESP8266WebServer WiFiWebServer;
#elif defined(ARDUINO_ARCH_ESP32)
#define FILE_MODE_R FILE_READ
#define FILE_MODE_W FILE_WRITE
typedef WebServer WiFiWebServer;
#endif
the problem is that some WiFi server class methods have a different name
Example is setting the host name
ESP8266 -> WiFi.hostname();
ESP32 -> WiFi.setHostname();
i tried #define Wifi.hostname WiFi.setHostname to replace the method name in the #elif defined(ARDUINO_ARCH_ESP32) section above, but that throws an error, i assume the point (.) is an illegal character in macros.
The code contains
WiFi.hostname(_hostname);
WiFi.begin(ssid, password);
this evetually results in the error: error: 'class WiFiClass' has no member named 'hostname'.
I know i can litter my code with #if defined(ARDUINO_ARCH_ESP8266) statements, but it would be so much easier to do this once.
If anyone has a suggestion for me, i would be grateful.
thanks for your time.
Rob.