Skip to content

Commit d9bfc20

Browse files
authored
Adapt for LibreTuya compatibility (#7)
1 parent aa107a5 commit d9bfc20

6 files changed

Lines changed: 15 additions & 8 deletions

File tree

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"version": "2.1.0",
1616
"license": "LGPL-3.0",
1717
"frameworks": "arduino",
18-
"platforms": ["espressif8266", "espressif32"],
18+
"platforms": ["espressif8266", "espressif32", "libretuya"],
1919
"dependencies": [
2020
{
2121
"owner": "ottowinter",
@@ -25,7 +25,7 @@
2525
{
2626
"owner": "esphome",
2727
"name": "AsyncTCP-esphome",
28-
"platforms": "espressif32"
28+
"platforms": ["espressif32", "libretuya"]
2929
},
3030
{
3131
"name": "Hash",

src/AsyncEventSource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <Arduino.h>
2424
#include <Arduino.h>
25-
#ifdef ESP32
25+
#if defined(ESP32) || defined(LIBRETUYA)
2626
#include <AsyncTCP.h>
2727
#else
2828
#include <ESPAsyncTCP.h>
@@ -43,7 +43,7 @@
4343
#endif
4444
#endif
4545

46-
#ifdef ESP32
46+
#if defined(ESP32) || defined(LIBRETUYA)
4747
#define DEFAULT_MAX_SSE_CLIENTS 8
4848
#else
4949
#define DEFAULT_MAX_SSE_CLIENTS 4

src/AsyncWebSocket.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#ifndef ESP8266
2727
#include "mbedtls/sha1.h"
28+
#include "mbedtls/version.h"
2829
#else
2930
#include <Hash.h>
3031
#endif
@@ -1256,9 +1257,15 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
12561257
(String&)key += WS_STR_UUID;
12571258
mbedtls_sha1_context ctx;
12581259
mbedtls_sha1_init(&ctx);
1260+
#if MBEDTLS_VERSION_NUMBER >= 0x02070000 && MBEDTLS_VERSION_NUMBER < 0x03000000
12591261
mbedtls_sha1_starts_ret(&ctx);
12601262
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
12611263
mbedtls_sha1_finish_ret(&ctx, hash);
1264+
#else
1265+
mbedtls_sha1_starts(&ctx);
1266+
mbedtls_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length());
1267+
mbedtls_sha1_finish(&ctx, hash);
1268+
#endif
12621269
mbedtls_sha1_free(&ctx);
12631270
#endif
12641271
base64_encodestate _state;

src/AsyncWebSocket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define ASYNCWEBSOCKET_H_
2323

2424
#include <Arduino.h>
25-
#ifdef ESP32
25+
#if defined(ESP32) || defined(LIBRETUYA)
2626
#include <AsyncTCP.h>
2727
#define WS_MAX_QUEUED_MESSAGES 32
2828
#else
@@ -40,7 +40,7 @@
4040
#endif
4141
#endif
4242

43-
#ifdef ESP32
43+
#if defined(ESP32) || defined(LIBRETUYA)
4444
#define DEFAULT_MAX_WS_CLIENTS 8
4545
#else
4646
#define DEFAULT_MAX_WS_CLIENTS 4

src/AsyncWebSynchronization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <ESPAsyncWebServer.h>
77

8-
#ifdef ESP32
8+
#if defined(ESP32) || (defined(LIBRETUYA) && LT_HAS_FREERTOS)
99

1010
// This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore
1111
class AsyncWebLock

src/ESPAsyncWebServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "StringArray.h"
3030

31-
#ifdef ESP32
31+
#if defined(ESP32) || defined(LIBRETUYA)
3232
#include <WiFi.h>
3333
#include <AsyncTCP.h>
3434
#elif defined(ESP8266)

0 commit comments

Comments
 (0)