Skip to content

Commit d37bd16

Browse files
committed
Initial ESP32 compatibility
1 parent 30f9dab commit d37bd16

10 files changed

+344
-276
lines changed

component.mk

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
COMPONENT_ADD_INCLUDEDIRS := src
2+
COMPONENT_SRCDIRS := src
3+
CXXFLAGS += -fno-rtti

src/AsyncEventSource.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
#define ASYNCEVENTSOURCE_H_
2222

2323
#include <Arduino.h>
24+
#ifdef ESP32
25+
#include <AsyncTCP.h>
26+
#else
2427
#include <ESPAsyncTCP.h>
28+
#endif
2529
#include <ESPAsyncWebServer.h>
2630

2731
class AsyncEventSource;

src/AsyncWebSocket.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ size_t AsyncWebSocketClient::printf(const char *format, ...) {
672672
return len;
673673
}
674674

675+
#ifndef ESP32
675676
size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...) {
676677
va_list arg;
677678
va_start(arg, formatP);
@@ -700,6 +701,7 @@ size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...) {
700701
delete[] temp;
701702
return len;
702703
}
704+
#endif
703705

704706
void AsyncWebSocketClient::text(const char * message, size_t len){
705707
_queueMessage(new AsyncWebSocketBasicMessage(message, len));
@@ -955,6 +957,7 @@ size_t AsyncWebSocket::printfAll(const char *format, ...) {
955957
return len;
956958
}
957959

960+
#ifndef ESP32
958961
size_t AsyncWebSocket::printf_P(uint32_t id, PGM_P formatP, ...){
959962
AsyncWebSocketClient * c = client(id);
960963
if(c != NULL){
@@ -966,6 +969,7 @@ size_t AsyncWebSocket::printf_P(uint32_t id, PGM_P formatP, ...){
966969
}
967970
return 0;
968971
}
972+
#endif
969973

970974
size_t AsyncWebSocket::printfAll_P(PGM_P formatP, ...) {
971975
va_list arg;
@@ -1160,7 +1164,7 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
11601164
#ifdef ESP8266
11611165
sha1(key + WS_STR_UUID, hash);
11621166
#else
1163-
key += WS_STR_UUID;
1167+
(String&)key += WS_STR_UUID;
11641168
SHA1_CTX ctx;
11651169
SHA1Init(&ctx);
11661170
SHA1Update(&ctx, (const unsigned char*)key.c_str(), key.length());

src/AsyncWebSocket.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
#define ASYNCWEBSOCKET_H_
2323

2424
#include <Arduino.h>
25+
#ifdef ESP32
26+
#include <AsyncTCP.h>
27+
#else
2528
#include <ESPAsyncTCP.h>
29+
#endif
2630
#include <ESPAsyncWebServer.h>
2731

2832
class AsyncWebSocket;
@@ -168,8 +172,9 @@ class AsyncWebSocketClient {
168172
void message(AsyncWebSocketMessage *message){ _queueMessage(message); }
169173

170174
size_t printf(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
175+
#ifndef ESP32
171176
size_t printf_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
172-
177+
#endif
173178
void text(const char * message, size_t len);
174179
void text(const char * message);
175180
void text(uint8_t * message, size_t len);
@@ -257,7 +262,9 @@ class AsyncWebSocket: public AsyncWebHandler {
257262

258263
size_t printf(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
259264
size_t printfAll(const char *format, ...) __attribute__ ((format (printf, 2, 3)));
265+
#ifndef ESP32
260266
size_t printf_P(uint32_t id, PGM_P formatP, ...) __attribute__ ((format (printf, 3, 4)));
267+
#endif
261268
size_t printfAll_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
262269

263270
//event listener

src/ESPAsyncWebServer.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,23 @@
2424
#include "Arduino.h"
2525

2626
#include <functional>
27-
#include <ESPAsyncTCP.h>
2827
#include "FS.h"
2928

3029
#include "StringArray.h"
3130

32-
#if defined(ESP31B)
33-
#include <ESP31BWiFi.h>
31+
#ifdef ESP32
32+
#include <WiFi.h>
33+
#include <AsyncTCP.h>
34+
#include "SPIFFS.h"
3435
#elif defined(ESP8266)
3536
#include <ESP8266WiFi.h>
37+
#include <ESPAsyncTCP.h>
3638
#else
3739
#error Platform not supported
3840
#endif
3941

4042
#define DEBUGF(...) //Serial.printf(__VA_ARGS__)
4143

42-
4344
class AsyncWebServer;
4445
class AsyncWebServerRequest;
4546
class AsyncWebServerResponse;

src/SPIFFSEditor.cpp

+275-260
Large diffs are not rendered by default.

src/WebAuthentication.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
*/
2121
#include "WebAuthentication.h"
2222
#include <libb64/cencode.h>
23+
#ifdef ESP32
24+
#include "mbedtls/md5.h"
25+
#else
2326
#include "md5.h"
27+
#endif
28+
2429

2530
// Basic Auth hash = base64("username:password")
2631

@@ -54,15 +59,26 @@ bool checkBasicAuthentication(const char * hash, const char * username, const ch
5459
}
5560

5661
static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or more
57-
md5_context_t _ctx;
62+
#ifdef ESP32
63+
mbedtls_md5_context _ctx;
64+
#else
65+
md5_context_t _ctx;
66+
#endif
5867
uint8_t i;
5968
uint8_t * _buf = (uint8_t*)malloc(16);
6069
if(_buf == NULL)
6170
return false;
6271
memset(_buf, 0x00, 16);
72+
#ifdef ESP32
73+
mbedtls_md5_init(&_ctx);
74+
mbedtls_md5_starts(&_ctx);
75+
mbedtls_md5_update(&_ctx, data, len);
76+
mbedtls_md5_finish(&_ctx, _buf);
77+
#else
6378
MD5Init(&_ctx);
6479
MD5Update(&_ctx, data, len);
6580
MD5Final(_buf, &_ctx);
81+
#endif
6682
for(i = 0; i < 16; i++) {
6783
sprintf(output + (i * 2), "%02x", _buf[i]);
6884
}

src/WebHandlers.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ bool AsyncStaticWebHandler::_getFile(AsyncWebServerRequest *request)
128128
return _fileExists(request, path);
129129
}
130130

131+
#ifdef ESP32
132+
#define FILE_IS_REAL(f) (f == true && !f.isDirectory())
133+
#else
134+
#define FILE_IS_REAL(f) (f == true)
135+
#endif
136+
131137
bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest *request, const String& path)
132138
{
133139
bool fileFound = false;
@@ -137,17 +143,17 @@ bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest *request, const St
137143

138144
if (_gzipFirst) {
139145
request->_tempFile = _fs.open(gzip, "r");
140-
gzipFound = request->_tempFile == true;
146+
gzipFound = FILE_IS_REAL(request->_tempFile);
141147
if (!gzipFound){
142148
request->_tempFile = _fs.open(path, "r");
143-
fileFound = request->_tempFile == true;
149+
fileFound = FILE_IS_REAL(request->_tempFile);
144150
}
145151
} else {
146152
request->_tempFile = _fs.open(path, "r");
147-
fileFound = request->_tempFile == true;
153+
fileFound = FILE_IS_REAL(request->_tempFile);
148154
if (!fileFound){
149155
request->_tempFile = _fs.open(gzip, "r");
150-
gzipFound = request->_tempFile == true;
156+
gzipFound = FILE_IS_REAL(request->_tempFile);
151157
}
152158
}
153159

src/WebRequest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void AsyncWebServerRequest::_onError(int8_t error){
202202
}
203203

204204
void AsyncWebServerRequest::_onTimeout(uint32_t time){
205-
os_printf("TIMEOUT: %u, state: %s\n", time, _client->stateToString());
205+
//os_printf("TIMEOUT: %u, state: %s\n", time, _client->stateToString());
206206
_client->close();
207207
}
208208

@@ -505,7 +505,7 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){
505505
}
506506
} else if(_multiParseState == DASH3_OR_RETURN2){
507507
if(data == '-' && (_contentLength - _parsedLength - 4) != 0){
508-
os_printf("ERROR: The parser got to the end of the POST but is expecting %u bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4);
508+
//os_printf("ERROR: The parser got to the end of the POST but is expecting %u bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4);
509509
_contentLength = _parsedLength + 4;//lets close the request gracefully
510510
}
511511
if(data == '\r'){

src/edit.htm

+15-3
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,29 @@
222222

223223
function createFileUploader(element, tree, editor){
224224
var xmlHttp;
225+
226+
var refresh = ce("button");
227+
refresh.innerHTML = 'Refresh List';
228+
ge(element).appendChild(refresh);
229+
225230
var input = ce("input");
226231
input.type = "file";
227232
input.multiple = false;
228233
input.name = "data";
229234
input.id="upload-select";
230235
ge(element).appendChild(input);
236+
231237
var path = ce("input");
232238
path.id = "upload-path";
233239
path.type = "text";
234240
path.name = "path";
235241
path.defaultValue = "/";
236242
ge(element).appendChild(path);
243+
237244
var button = ce("button");
238245
button.innerHTML = 'Upload';
239246
ge(element).appendChild(button);
247+
240248
var mkfile = ce("button");
241249
mkfile.innerHTML = 'Create';
242250
ge(element).appendChild(mkfile);
@@ -274,6 +282,10 @@
274282
editor.execCommand('saveCommand');
275283
};
276284

285+
refresh.onclick = function(e){
286+
tree.refreshPath(path.value);
287+
};
288+
277289
button.onclick = function(e){
278290
if(input.files.length === 0){
279291
return;
@@ -294,7 +306,7 @@
294306
if(typeof name !== undefined){
295307
filename = name;
296308
}
297-
path.value = "/"+filename;
309+
path.value = "/"+filename+"."+ext;
298310
};
299311
}
300312

@@ -594,11 +606,11 @@
594606
editor.loadUrl(vars.file);
595607
};
596608
</script>
597-
<script id='ace' src="/ace.js" type="text/javascript" charset="utf-8"></script>
609+
<script id='ace' src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript" charset="utf-8"></script>
598610
<script>
599611
if (typeof ace.edit == "undefined") {
600612
var script = document.createElement('script');
601-
script.src = "https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js";
613+
script.src = "/ace.js";
602614
script.async = false;
603615
document.head.appendChild(script);
604616
}

0 commit comments

Comments
 (0)