Skip to content

Commit

Permalink
Adapt for usage with LibreTuya
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Jan 19, 2023
1 parent 1dacb48 commit a659596
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/AsyncMqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ AsyncMqttClient::AsyncMqttClient()
_xSemaphore = xSemaphoreCreateMutex();
#elif defined(ESP8266)
sprintf(_generatedClientId, "esp8266-%06x", ESP.getChipId());
#elif defined(LIBRETUYA)
sprintf(_generatedClientId, "lt-%06x", LT.getChipId());
_xSemaphore = xSemaphoreCreateMutex();
#endif
_clientId = _generatedClientId;

Expand All @@ -50,7 +53,7 @@ AsyncMqttClient::AsyncMqttClient()
AsyncMqttClient::~AsyncMqttClient() {
delete _currentParsedPacket;
delete[] _parsingInformation.topicBuffer;
#ifdef ESP32
#if defined(ESP32) || defined(LIBRETUYA)
vSemaphoreDelete(_xSemaphore);
#endif
}
Expand Down
7 changes: 5 additions & 2 deletions src/AsyncMqttClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <freertos/semphr.h>
#elif defined(ESP8266)
#include <ESPAsyncTCP.h>
#elif defined(LIBRETUYA)
#include <AsyncTCP.h>
#include <semphr.h>
#else
#error Platform not supported
#endif
Expand Down Expand Up @@ -38,7 +41,7 @@
#include "AsyncMqttClient/Packets/PubRecPacket.hpp"
#include "AsyncMqttClient/Packets/PubCompPacket.hpp"

#if ESP32
#if ESP32 || defined(LIBRETUYA)
#define SEMAPHORE_TAKE(X) if (xSemaphoreTake(_xSemaphore, 1000 / portTICK_PERIOD_MS) != pdTRUE) { return X; } // Waits max 1000ms
#define SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore);
#elif defined(ESP8266)
Expand Down Expand Up @@ -132,7 +135,7 @@ class AsyncMqttClient {

std::vector<AsyncMqttClientInternals::PendingAck> _toSendAcks;

#ifdef ESP32
#if defined(ESP32) || defined(LIBRETUYA)
SemaphoreHandle_t _xSemaphore = nullptr;
#endif

Expand Down

0 comments on commit a659596

Please sign in to comment.