Skip to content

Commit

Permalink
fix compilation of ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
lumapu committed Jun 9, 2024
1 parent 10423d7 commit 7336981
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/publisher/pubMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#if defined(ENABLE_MQTT)
#ifdef ESP8266
#include <ESP8266WiFi.h>
#define xSemaphoreTake(a, b) { while(a) { yield(); } a = true; }
#define xSemaphoreGive(a) { a = false; }
#elif defined(ESP32)
#include <WiFi.h>
#endif
Expand Down Expand Up @@ -39,8 +41,12 @@ template<class HMSYSTEM>
class PubMqtt {
public:
PubMqtt() : SendIvData() {
mutex = xSemaphoreCreateBinaryStatic(&mutexBuffer);
xSemaphoreGive(mutex);
#if defined(ESP32)
mutex = xSemaphoreCreateBinaryStatic(&mutexBuffer);
xSemaphoreGive(mutex);
#else
mutex = false;
#endif

mLastIvState.fill(InverterStatus::OFF);
mIvLastRTRpub.fill(0);
Expand All @@ -54,7 +60,9 @@ class PubMqtt {
}

~PubMqtt() {
#if defined(ESP32)
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) {
Expand Down Expand Up @@ -667,9 +675,11 @@ class PubMqtt {
IApp *mApp;
#if defined(ESP8266)
WiFiEventHandler mHWifiCon, mHWifiDiscon;
#endif
volatile bool mutex;
#else
SemaphoreHandle_t mutex;
StaticSemaphore_t mutexBuffer;
#endif

HMSYSTEM *mSys = nullptr;
PubMqttIvData<HMSYSTEM> SendIvData;
Expand Down

0 comments on commit 7336981

Please sign in to comment.