Explorar o código

Add auto reconnect

jblanked hai 1 ano
pai
achega
14666978cf

+ 27 - 6
assets/FlipperHTTP/Arduino/FlipperHTTP.h

@@ -3,7 +3,7 @@ Author: JBlanked
 Github: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 Github: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 Info: This library is a wrapper around the HTTPClient library and is used to communicate with the FlipperZero over serial.
 Info: This library is a wrapper around the HTTPClient library and is used to communicate with the FlipperZero over serial.
 Created: 2024-09-30
 Created: 2024-09-30
-Updated: 2024-10-22
+Updated: 2024-10-25
 
 
 Change Log:
 Change Log:
 - 2024-09-30: Initial commit
 - 2024-09-30: Initial commit
@@ -15,6 +15,7 @@ Change Log:
 - 2024-10-19: Added [WIFI/IP] command
 - 2024-10-19: Added [WIFI/IP] command
 - 2024-10-21: Removed unnecessary println
 - 2024-10-21: Removed unnecessary println
 - 2024-10-22: Updated Post Bytes and Get Bytes methods
 - 2024-10-22: Updated Post Bytes and Get Bytes methods
+- 2024-10-25: Updated to automatically connect to WiFi on boot if settings are saved
 */
 */
 
 
 #include <WiFi.h>
 #include <WiFi.h>
@@ -52,6 +53,7 @@ public:
         }
         }
         this->useLED = true;
         this->useLED = true;
         this->ledStart();
         this->ledStart();
+        this->loadWifiSettings();
         Serial.flush();
         Serial.flush();
     }
     }
 
 
@@ -221,15 +223,34 @@ bool FlipperHTTP::loadWifiSettings()
     File file = SPIFFS.open(settingsFilePath, FILE_READ);
     File file = SPIFFS.open(settingsFilePath, FILE_READ);
     if (!file)
     if (!file)
     {
     {
-        Serial.println("[ERROR] Failed to open file for reading.");
-        return "";
+        return false;
     }
     }
 
 
     // Read the entire file content
     // Read the entire file content
     String fileContent = file.readString();
     String fileContent = file.readString();
     file.close();
     file.close();
 
 
-    return fileContent;
+    // Attempt to parse the JSON data
+    DynamicJsonDocument doc(1024);
+    DeserializationError error = deserializeJson(doc, fileContent);
+
+    if (error)
+    {
+        return false;
+    }
+
+    // Extract values from JSON
+    if (doc.containsKey("ssid") && doc.containsKey("password"))
+    {
+        strlcpy(loadedSSID, doc["ssid"], sizeof(loadedSSID));             // save ssid
+        strlcpy(loadedPassword, doc["password"], sizeof(loadedPassword)); // save password
+    }
+    else
+    {
+        return false;
+    }
+
+    return this->connectToWifi();
 }
 }
 
 
 String FlipperHTTP::readSerialLine()
 String FlipperHTTP::readSerialLine()
@@ -267,8 +288,8 @@ bool FlipperHTTP::readSerialSettings(String receivedData, bool connectAfterSave)
     // Extract values from JSON
     // Extract values from JSON
     if (doc.containsKey("ssid") && doc.containsKey("password"))
     if (doc.containsKey("ssid") && doc.containsKey("password"))
     {
     {
-        strlcpy(loadedSSID, doc["ssid"], sizeof(loadedSSID));
-        strlcpy(loadedPassword, doc["password"], sizeof(loadedPassword));
+        strlcpy(loadedSSID, doc["ssid"], sizeof(loadedSSID));             // save ssid
+        strlcpy(loadedPassword, doc["password"], sizeof(loadedPassword)); // save password
     }
     }
     else
     else
     {
     {

+ 1 - 1
assets/FlipperHTTP/Arduino/flipper-http.ino

@@ -3,7 +3,7 @@ Author: JBlanked
 Github: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 Github: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 Info: This library is a wrapper around the HTTPClient library and is used to communicate with the FlipperZero over serial.
 Info: This library is a wrapper around the HTTPClient library and is used to communicate with the FlipperZero over serial.
 Created: 2024-09-30
 Created: 2024-09-30
-Updated: 2024-10-22
+Updated: 2024-10-25
 */
 */
 
 
 #include <FlipperHTTP.h>
 #include <FlipperHTTP.h>

BIN=BIN
assets/FlipperHTTP/flipper_http_bootloader.bin


BIN=BIN
assets/FlipperHTTP/flipper_http_firmware_a.bin


BIN=BIN
assets/FlipperHTTP/flipper_http_partitions.bin