Merge applications/external/webcrawler updates from webcrawler

This commit is contained in:
RogueMaster 2024-10-25 23:32:11 -04:00
commit 8d3e21607a
6 changed files with 51 additions and 12 deletions

View file

@ -3,7 +3,7 @@ Author: JBlanked
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.
Created: 2024-09-30
Updated: 2024-10-22
Updated: 2024-10-25
Change Log:
- 2024-09-30: Initial commit
@ -15,6 +15,7 @@ Change Log:
- 2024-10-19: Added [WIFI/IP] command
- 2024-10-21: Removed unnecessary println
- 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>
@ -52,6 +53,7 @@ public:
}
this->useLED = true;
this->ledStart();
this->loadWifiSettings();
Serial.flush();
}
@ -221,15 +223,34 @@ bool FlipperHTTP::loadWifiSettings()
File file = SPIFFS.open(settingsFilePath, FILE_READ);
if (!file)
{
Serial.println("[ERROR] Failed to open file for reading.");
return "";
return false;
}
// Read the entire file content
String fileContent = file.readString();
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()
@ -267,8 +288,8 @@ bool FlipperHTTP::readSerialSettings(String receivedData, bool connectAfterSave)
// Extract values from JSON
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
{

View file

@ -7,7 +7,7 @@ Updated: 2024-10-25
Change Log:
- 2024-10-24: Initial commit
- 2024-10-25: Updated the readSerialLine method to use readStringUntil instead of reading char by char
- 2024-10-25: Updated the readSerialLine method to use readStringUntil instead of reading char by char, and added Auto connect
- Reading char by char worked on the dev board but was missing chars on the Pico
*/
@ -60,7 +60,7 @@ public:
return;
}
}
this->loadWifiSettings();
this->useLED = true;
this->ledStart();
SerialPico.flush();
@ -224,7 +224,6 @@ bool FlipperHTTP::loadWifiSettings()
File file = LittleFS.open(settingsFilePath, "r");
if (!file)
{
SerialPico.println("[ERROR] Failed to open file for reading.");
return false;
}
@ -232,8 +231,27 @@ bool FlipperHTTP::loadWifiSettings()
String fileContent = file.readString();
file.close();
SerialPico.println("[SUCCESS] Settings loaded from LittleFS.");
return true;
// 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()

View file

@ -3,7 +3,7 @@ Author: JBlanked
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.
Created: 2024-09-30
Updated: 2024-10-22
Updated: 2024-10-25
*/
#include <FlipperHTTP.h>