浏览代码

Minor fixes related to v2.2.5

Ayush Sharma 3 年之前
父节点
当前提交
39968bc177
共有 2 个文件被更改,包括 14 次插入10 次删除
  1. 12 9
      src/ElegantOTA.cpp
  2. 2 1
      src/ElegantOTA.h

+ 12 - 9
src/ElegantOTA.cpp

@@ -22,11 +22,14 @@ void ElegantOtaClass::setID(const char* id){
 #endif
     _server = server;
 
-    strlcpy(_username, username, sizeof(_username));
-    strlcpy(_password, password, sizeof(_password));
+    if (strlen(username) > 0) {
+      strlcpy(_username, username, sizeof(_username));
+      strlcpy(_password, password, sizeof(_password));
+      authenticate = true;
+    }
 
     _server->on("/update", HTTP_GET, [&](){
-      if (strlen(_username) > 0 && !_server->authenticate(_username, _password)) {
+      if (authenticate && !_server->authenticate(_username, _password)) {
         return _server->requestAuthentication();
       }
       _server->sendHeader("Content-Encoding", "gzip");
@@ -34,18 +37,18 @@ void ElegantOtaClass::setID(const char* id){
     });
 
     _server->on("/update/identity", HTTP_GET, [&](){
-      if (strlen(_username) > 0 && !_server->authenticate(_username, _password)) {
+      if (authenticate && !_server->authenticate(_username, _password)) {
         return _server->requestAuthentication();
       }
 
       #if defined(ESP8266)
-          _server->send(200, "application/json", "{\"id\": "+_id+", \"hardware\": \"ESP8266\"}");
+          _server->send(200, "application/json", "{\"id\": \""+_id+"\", \"hardware\": \"ESP8266\"}");
       #elif defined(ESP32)
-          _server->send(200, "application/json", "{\"id\": "+_id+", \"hardware\": \"ESP32\"}");
+          _server->send(200, "application/json", "{\"id\": \""+_id+"\", \"hardware\": \"ESP32\"}");
       #endif
 
       #if defined(ESP8266)
-        if (strlen(_username) > 0) {
+        if (authenticate) {
           _httpUpdater.setup(server, "/update");
         } else {
           _httpUpdater.setup(server, "/update", _username, _password);
@@ -56,7 +59,7 @@ void ElegantOtaClass::setID(const char* id){
 
     #if defined(ESP32)
       _server->on("/update", HTTP_POST, [&](){
-        if (strlen(_username) > 0 && !_server->authenticate(_username, _password)) {
+        if (authenticate && !_server->authenticate(_username, _password)) {
           return;
         }
         _server->sendHeader("Connection", "close");
@@ -64,7 +67,7 @@ void ElegantOtaClass::setID(const char* id){
         ESP.restart();
       }, [&](){
         // Actual OTA Download
-        if (strlen(_username) > 0 && !_server->authenticate(_username, _password)) {
+        if (authenticate && !_server->authenticate(_username, _password)) {
           return;
         }
 

+ 2 - 1
src/ElegantOTA.h

@@ -43,7 +43,8 @@ class ElegantOtaClass{
 
       char _username[64];
       char _password[64];
-      String _id;
+      bool authenticate;
+      String _id = getID();
       
 };