浏览代码

Merge pull request #80 from ayushsharma82/dev

v2.0.1 Release
Ayush Sharma 10 月之前
父节点
当前提交
e6bbfd6d01
共有 10 个文件被更改,包括 688 次插入676 次删除
  1. 1 1
      .github/workflows/ci.yml
  2. 3 1
      .gitignore
  3. 3 3
      examples/Demo_AP/Demo_AP.ino
  4. 2 2
      library.json
  5. 1 1
      library.properties
  6. 2 2
      platformio.ini
  7. 25 11
      src/WebSerial.cpp
  8. 16 20
      src/WebSerial.h
  9. 633 633
      src/wslp.cpp
  10. 2 2
      src/wslp.h

+ 1 - 1
.github/workflows/ci.yml

@@ -64,7 +64,7 @@ jobs:
         run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0
 
       - name: Install ESPAsyncWebServer
-        run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v2.10.1
+        run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v2.10.4
 
       - name: Build Demo
         run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Demo/Demo.ino"

+ 3 - 1
.gitignore

@@ -57,4 +57,6 @@ dkms.conf
 
 /portal
 /.pio
-/logs
+/logs
+/.docusaurus
+/node_modules

+ 3 - 3
examples/Demo_AP/Demo_AP.ino

@@ -42,10 +42,10 @@ void setup() {
   WiFi.softAP(ssid, password);
   // Once connected, print IP
   Serial.print("IP Address: ");
-  Serial.println(WiFi.localIP());
+  Serial.println(WiFi.softAPIP());
 
   server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
-    request->send(200, "text/plain", "Hi! This is WebSerial demo. You can access webserial interface at http://" + WiFi.localIP().toString() + "/webserial");
+    request->send(200, "text/plain", "Hi! This is WebSerial demo. You can access webserial interface at http://" + WiFi.softAPIP().toString() + "/webserial");
   });
 
   // WebSerial is accessible at "<IP Address>/webserial" in browser
@@ -72,7 +72,7 @@ void loop() {
   // Print every 2 seconds (non-blocking)
   if ((unsigned long)(millis() - last_print_time) > 2000) {
     WebSerial.print(F("IP address: "));
-    WebSerial.println(WiFi.localIP());
+    WebSerial.println(WiFi.softAPIP());
     WebSerial.printf("Uptime: %lums\n", millis());
     WebSerial.printf("Free heap: %u\n", ESP.getFreeHeap());
     last_print_time = millis();

+ 2 - 2
library.json

@@ -15,14 +15,14 @@
       "maintainer": true
     }
   ],
-  "version": "2.0.0",
+  "version": "2.0.1",
   "frameworks": "arduino",
   "platforms": ["espressif8266", "espressif32"],
   "dependencies": [
     {
       "owner": "mathieucarbou",
       "name": "ESP Async WebServer",
-      "version": "^2.10.1",
+      "version": "^2.10.4",
       "platforms": ["espressif8266", "espressif32"]
     }
   ]

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=WebSerial
-version=2.0.0
+version=2.0.1
 author=Ayush Sharma
 category=Communication
 maintainer=Ayush Sharma <asrocks5@gmail.com>

+ 2 - 2
platformio.ini

@@ -6,7 +6,7 @@ build_flags =
   -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
 lib_deps = 
   mathieucarbou/Async TCP @ ^3.1.4
-  mathieucarbou/ESP Async WebServer @ 2.10.1
+  mathieucarbou/ESP Async WebServer @ 2.10.4
 upload_protocol = esptool
 monitor_speed = 115200
 monitor_filters = esp32_exception_decoder, log2file
@@ -35,5 +35,5 @@ board = esp32-s3-devkitc-1
 platform = espressif8266
 board = huzzah
 lib_deps = 
-  mathieucarbou/ESP Async WebServer @ 2.10.1
+  mathieucarbou/ESP Async WebServer @ 2.10.4
   esphome/ESPAsyncTCP-esphome @ 2.0.0

+ 25 - 11
src/WebSerial.cpp

@@ -1,12 +1,26 @@
 #include "WebSerial.h"
 
-void WebSerialClass::setAuthentication(const char* username, const char* password){
-  _authenticate = true;
-  strncpy(_username, username, sizeof(_username));
-  strncpy(_password, password, sizeof(_password));
-
+#include "wslp.h"
+
+// DO NOT change magic bytes
+#define WSL_MAGIC_BYTE_1              0xAB
+#define WSL_MAGIC_BYTE_2              0xCD
+#define WSL_LOG_PACKET_HEADER_SIZE    14
+#define WSL_CALC_LOG_PACKET_SIZE(len) (WSL_LOG_PACKET_HEADER_SIZE + len)
+
+typedef enum {
+  WSL_WRITE_ROW = 0x01,
+  WSL_MESSAGE = 0x02,
+  WSL_PING = 0x03,
+  WSL_PONG = 0x04,
+} WSLPacketType;
+
+void WebSerialClass::setAuthentication(const String& username, const String& password){
+  _username = username;
+  _password = password;
+  _authenticate = !_username.isEmpty() && !_password.isEmpty();
   if (_ws != nullptr) {
-    _ws->setAuthentication(_username, _password);
+    _ws->setAuthentication(_username.c_str(), _password.c_str());
   }
 }
 
@@ -20,8 +34,8 @@ void WebSerialClass::begin(AsyncWebServer *server, const char* url) {
 
   // Webpage Handler
   _server->on(url, HTTP_GET, [&](AsyncWebServerRequest *request){
-    if(_authenticate == true){
-      if(!request->authenticate(_username, _password))
+    if(_authenticate){
+      if(!request->authenticate(_username.c_str(), _password.c_str()))
         return request->requestAuthentication();
     }
     AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", WEBSERIAL_HTML, sizeof(WEBSERIAL_HTML));
@@ -30,7 +44,7 @@ void WebSerialClass::begin(AsyncWebServer *server, const char* url) {
   });
 
   // WS Handler
-  _ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) -> void {
+  _ws->onEvent([&](__unused AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, __unused void * arg, uint8_t *data, __unused size_t len) -> void {
     // if(type == WS_EVT_CONNECT){
     // } else if(type == WS_EVT_DISCONNECT){
     // } else if(type == WS_EVT_DATA){
@@ -42,7 +56,7 @@ void WebSerialClass::begin(AsyncWebServer *server, const char* url) {
           size_t message_size = (data[4] << 8) | data[3];
           // Issue callback
           if(_recv != nullptr){
-            _recv(data + 4, message_size);
+            _recv(data + 5, message_size);
           }
         } else if (data[2] == WSLPacketType::WSL_PING) {
           // Send pong
@@ -110,7 +124,7 @@ bool WebSerialClass::_has_enough_space(size_t size) {
   return (_buffer_offset + WSL_CALC_LOG_PACKET_SIZE(size) > WSL_BUFFER_SIZE);
 }
 
-size_t WebSerialClass::_write_row_packet(uint64_t reserved1, uint8_t reserved2, const uint8_t *payload, const size_t payload_size) {
+size_t WebSerialClass::_write_row_packet(__unused uint64_t reserved1, __unused uint8_t reserved2, const uint8_t *payload, const size_t payload_size) {
   size_t header_size = 0;
 
   // Write Magic Bytes

+ 16 - 20
src/WebSerial.h

@@ -35,24 +35,26 @@ License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
     #include "ESPAsyncWebServer.h"
 #endif
 
-#include "wslp.h"
-
-// DO NOT change magic bytes
-#define WSL_MAGIC_BYTE_1              0xAB
-#define WSL_MAGIC_BYTE_2              0xCD
-
 // Global buffer ( buffers all packets )
+#ifndef WSL_BUFFER_SIZE
 #define WSL_BUFFER_SIZE                       2048
+#endif
+#ifndef WSL_PRINT_BUFFER_SIZE
 #define WSL_PRINT_BUFFER_SIZE                 1024
+#endif
+#ifndef WSL_MAX_ROW_PACKET_PAYLOAD_SIZE
 #define WSL_MAX_ROW_PACKET_PAYLOAD_SIZE       512
+#endif
 
-#define WSL_LOG_PACKET_HEADER_SIZE            14
-#define WSL_MAX_LOG_PACKET_MESSAGE_SIZE       512
-#define WSL_CALC_LOG_PACKET_SIZE(len)         (WSL_LOG_PACKET_HEADER_SIZE + len)
-
+#ifndef WSL_PRINT_FLUSH_TIME_US
 #define WSL_PRINT_FLUSH_TIME_US               100
+#endif
+#ifndef WSL_GLOBAL_FLUSH_TIME_MS
 #define WSL_GLOBAL_FLUSH_TIME_MS              100
+#endif
+#ifndef WSL_CLEANUP_TIME_MS
 #define WSL_CLEANUP_TIME_MS                   5000
+#endif
 
 #if WSL_BUFFER_SIZE < 512
   #error "WSL_BUFFER_SIZE must be >= 512 bytes"
@@ -70,19 +72,13 @@ License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
   #error "WSL_GLOBAL_FLUSH_TIME_MS must be greater than 50ms"
 #endif
 
-typedef enum {
-  WSL_WRITE_ROW = 0x01,
-  WSL_MESSAGE = 0x02,
-  WSL_PING = 0x03,
-  WSL_PONG = 0x04,
-} WSLPacketType;
-
 typedef std::function<void(uint8_t *data, size_t len)> WSLMessageHandler;
 
 class WebSerialClass : public Print {
   public:
     void begin(AsyncWebServer *server, const char* url = "/webserial");
-    void setAuthentication(const char* username, const char* passsword);
+    inline void setAuthentication(const char* username, const char* password) { setAuthentication(String(username), String(password)); }
+    void setAuthentication(const String& username, const String& password);
     void onMessage(WSLMessageHandler recv);
     size_t write(uint8_t);
     size_t write(uint8_t* buffer, size_t size);
@@ -107,8 +103,8 @@ class WebSerialClass : public Print {
     WSLMessageHandler _recv = nullptr;
     unsigned long _last_cleanup_time = 0;
     bool _authenticate = false;
-    char _username[64];
-    char _password[64];
+    String _username;
+    String _password;
 
     // Print
     void _wait_for_global_mutex();

文件差异内容过多而无法显示
+ 633 - 633
src/wslp.cpp


+ 2 - 2
src/wslp.h

@@ -8,9 +8,9 @@
 #endif
 
 #if WEBSERIAL_USE_BROTLI_COMPRESSION == 1
-  extern const uint8_t WEBSERIAL_HTML[18923];
+  extern const uint8_t WEBSERIAL_HTML[18909];
 #else
-  extern const uint8_t WEBSERIAL_HTML[20887];
+  extern const uint8_t WEBSERIAL_HTML[20891];
 #endif
 
 #endif

部分文件因为文件数量过多而无法显示