Browse Source

fix compilation of ESP8266

pull/1670/head^2
lumapu 8 months ago
parent
commit
7336981c62
  1. 12
      src/publisher/pubMqtt.h

12
src/publisher/pubMqtt.h

@ -11,6 +11,8 @@
#if defined(ENABLE_MQTT) #if defined(ENABLE_MQTT)
#ifdef ESP8266 #ifdef ESP8266
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#define xSemaphoreTake(a, b) { while(a) { yield(); } a = true; }
#define xSemaphoreGive(a) { a = false; }
#elif defined(ESP32) #elif defined(ESP32)
#include <WiFi.h> #include <WiFi.h>
#endif #endif
@ -39,8 +41,12 @@ template<class HMSYSTEM>
class PubMqtt { class PubMqtt {
public: public:
PubMqtt() : SendIvData() { PubMqtt() : SendIvData() {
#if defined(ESP32)
mutex = xSemaphoreCreateBinaryStatic(&mutexBuffer); mutex = xSemaphoreCreateBinaryStatic(&mutexBuffer);
xSemaphoreGive(mutex); xSemaphoreGive(mutex);
#else
mutex = false;
#endif
mLastIvState.fill(InverterStatus::OFF); mLastIvState.fill(InverterStatus::OFF);
mIvLastRTRpub.fill(0); mIvLastRTRpub.fill(0);
@ -54,7 +60,9 @@ class PubMqtt {
} }
~PubMqtt() { ~PubMqtt() {
#if defined(ESP32)
vSemaphoreDelete(mutex); vSemaphoreDelete(mutex);
#endif
} }
void setup(IApp *app, cfgMqtt_t *cfg_mqtt, const char *devName, const char *version, HMSYSTEM *sys, uint32_t *utcTs, uint32_t *uptime) { void setup(IApp *app, cfgMqtt_t *cfg_mqtt, const char *devName, const char *version, HMSYSTEM *sys, uint32_t *utcTs, uint32_t *uptime) {
@ -667,9 +675,11 @@ class PubMqtt {
IApp *mApp; IApp *mApp;
#if defined(ESP8266) #if defined(ESP8266)
WiFiEventHandler mHWifiCon, mHWifiDiscon; WiFiEventHandler mHWifiCon, mHWifiDiscon;
#endif volatile bool mutex;
#else
SemaphoreHandle_t mutex; SemaphoreHandle_t mutex;
StaticSemaphore_t mutexBuffer; StaticSemaphore_t mutexBuffer;
#endif
HMSYSTEM *mSys = nullptr; HMSYSTEM *mSys = nullptr;
PubMqttIvData<HMSYSTEM> SendIvData; PubMqttIvData<HMSYSTEM> SendIvData;

Loading…
Cancel
Save