diff --git a/src/mqtt.cpp b/src/mqtt.cpp index bada3d5..992ce79 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -5,7 +5,13 @@ #pragma message "MQTT_ENABLE is false. Skipping MQTT." #else -#include +#if defined( ESP8266 ) + #include +#elif defined( ESP32 ) + #include +#else + #error "Neither ESP32 nor ESP8266 set..." +#endif #include #include "EffectEntry.h" #include "Effect.h" @@ -47,7 +53,15 @@ void mqtt_callback(char* complete_topic, byte* pl, unsigned int length) { boolean mqtt_connect() { char client_id[30]; - snprintf(client_id, 30, HOSTNAME, ESP.getChipId()); + int chipid; + #if defined( ESP8266 ) + chipid = ESP.getChipId(); + #elif defined( ESP32 ) + chipid = ESP.getEfuseMac() & 0xFFFFFF; + #else + #error Neither ESP32 nor ESP8266 set. + #endif + snprintf(client_id, 30, HOSTNAME, chipid); LOG("MQTT * Connecting to MQTT server with client id "); LOGln(client_id); if (mqtt_client.connect(client_id, MQTT_USER, MQTT_PASS)) { LOGln("MQTT * Connected."); diff --git a/src/ota.cpp b/src/ota.cpp index feb83e0..2099db0 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -1,4 +1,12 @@ #include +#if defined( ESP8266 ) + #include +#elif defined( ESP32 ) + #include +#else + #error Neither ESP32 nor ESP8266 set! +#endif +#include #include "config.h" void ota_setup() { @@ -27,7 +35,16 @@ void ota_setup() { else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); char client_id[30]; - snprintf(client_id, 30, HOSTNAME, ESP.getChipId()); + int chipid; + #if defined( ESP8266 ) + chipid = ESP.getChipId(); + #elif defined( ESP32 ) + chipid = ESP.getEfuseMac() & 0xFFFFFF; + #else + #error Neither ESP32 nor ESP8266 set. + #endif + + snprintf(client_id, 30, HOSTNAME, chipid); LOG("OTA * Starting OTA with client_id "); LOGln(client_id); ArduinoOTA.setHostname(client_id); ArduinoOTA.begin(); diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 84131f7..eb379ca 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -1,7 +1,4 @@ #include -#include -#include -#include #include #include "ntp.h" diff --git a/src/wifi.cpp b/src/wifi.cpp index 249ec19..7703a02 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -1,5 +1,9 @@ #include -#include +#if defined( ESP8266 ) + #include +#elif defined( ESP32 ) + #include +#endif #include "wifi.h" #include "config.h"