sforkowany z mirror/meshtastic-firmware
Merge pull request #573 from mc-hamster/master
New feature #571 - Report contents of spiffs in a json data structure.1.2-legacy
commit
7135a12300
|
@ -60,6 +60,7 @@ void handleRestart(HTTPRequest *req, HTTPResponse *res);
|
|||
void handle404(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleFormUpload(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleScanNetworks(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res);
|
||||
|
||||
void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
|
||||
void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
|
||||
|
@ -125,11 +126,12 @@ void taskCreateCert(void *parameter)
|
|||
DEBUG_MSG("Existing SSL Certificate found!\n");
|
||||
} else {
|
||||
DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n");
|
||||
yield();
|
||||
cert = new SSLCert();
|
||||
// disableCore1WDT();
|
||||
yield();
|
||||
int createCertResult = createSelfSignedCert(*cert, KEYSIZE_2048, "CN=meshtastic.local,O=Meshtastic,C=US",
|
||||
"20190101000000", "20300101000000");
|
||||
// enableCore1WDT();
|
||||
yield();
|
||||
|
||||
if (createCertResult != 0) {
|
||||
DEBUG_MSG("Creating the certificate failed\n");
|
||||
|
@ -241,6 +243,7 @@ void initWebServer()
|
|||
ResourceNode *node404 = new ResourceNode("", "GET", &handle404);
|
||||
ResourceNode *nodeFormUpload = new ResourceNode("/upload", "POST", &handleFormUpload);
|
||||
ResourceNode *nodeJsonScanNetworks = new ResourceNode("/json/scanNetworks", "GET", &handleScanNetworks);
|
||||
ResourceNode *nodeJsonSpiffsBrowseStatic = new ResourceNode("/json/spiffs/browse/static/", "GET", &handleSpiffsBrowseStatic);
|
||||
|
||||
// Secure nodes
|
||||
secureServer->registerNode(nodeAPIv1ToRadioOptions);
|
||||
|
@ -255,6 +258,7 @@ void initWebServer()
|
|||
secureServer->registerNode(nodeRestart);
|
||||
secureServer->registerNode(nodeFormUpload);
|
||||
secureServer->registerNode(nodeJsonScanNetworks);
|
||||
secureServer->registerNode(nodeJsonSpiffsBrowseStatic);
|
||||
secureServer->setDefaultNode(node404);
|
||||
|
||||
secureServer->addMiddleware(&middlewareSpeedUp240);
|
||||
|
@ -272,6 +276,7 @@ void initWebServer()
|
|||
insecureServer->registerNode(nodeRestart);
|
||||
insecureServer->registerNode(nodeFormUpload);
|
||||
insecureServer->registerNode(nodeJsonScanNetworks);
|
||||
insecureServer->registerNode(nodeJsonSpiffsBrowseStatic);
|
||||
insecureServer->setDefaultNode(node404);
|
||||
|
||||
insecureServer->addMiddleware(&middlewareSpeedUp160);
|
||||
|
@ -379,6 +384,60 @@ void handleStaticPost(HTTPRequest *req, HTTPResponse *res)
|
|||
res->println("</body></html>");
|
||||
}
|
||||
|
||||
void handleSpiffsBrowseStatic(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
// jm
|
||||
|
||||
res->setHeader("Content-Type", "application/json");
|
||||
// res->setHeader("Content-Type", "text/html");
|
||||
|
||||
File root = SPIFFS.open("/");
|
||||
|
||||
if (root.isDirectory()) {
|
||||
res->println("{");
|
||||
res->println("\"data\": {");
|
||||
|
||||
File file = root.openNextFile();
|
||||
res->print("\"files\": [");
|
||||
bool firstFile = 1;
|
||||
while (file) {
|
||||
if (firstFile) {
|
||||
firstFile = 0;
|
||||
} else {
|
||||
res->println(",");
|
||||
}
|
||||
|
||||
res->println("{");
|
||||
|
||||
String filePath = String(file.name());
|
||||
if (filePath.indexOf("/static") == 0) {
|
||||
if (String(file.name()).substring(1).endsWith(".gz")) {
|
||||
String modifiedFile = String(file.name()).substring(1);
|
||||
modifiedFile.remove((modifiedFile.length() - 3), 3);
|
||||
res->print("\"nameModified\": \"" + modifiedFile + "\",");
|
||||
res->print("\"name\": \"" + String(file.name()).substring(1) + "\",");
|
||||
|
||||
} else {
|
||||
res->print("\"name\": \"" + String(file.name()).substring(1) + "\",");
|
||||
}
|
||||
res->print("\"size\": " + String(file.size()));
|
||||
}
|
||||
|
||||
file = root.openNextFile();
|
||||
res->print("}");
|
||||
}
|
||||
res->print("],");
|
||||
res->print("\"filesystem\" : {");
|
||||
res->print("\"total\" : " + String(SPIFFS.totalBytes()) + ",");
|
||||
res->print("\"used\" : " + String(SPIFFS.usedBytes()) + ",");
|
||||
res->print("\"free\" : " + String(SPIFFS.totalBytes() - SPIFFS.usedBytes()));
|
||||
res->println("}");
|
||||
res->println("},");
|
||||
res->println("\"status\": \"ok\"");
|
||||
res->println("}");
|
||||
}
|
||||
}
|
||||
|
||||
void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
// Get access to the parameters
|
||||
|
@ -929,17 +988,16 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res)
|
|||
for (int i = 0; i < n; ++i) {
|
||||
char ssidArray[50];
|
||||
String ssidString = String(WiFi.SSID(i));
|
||||
//String ssidString = String(WiFi.SSID(i)).toCharArray(ssidArray, WiFi.SSID(i).length());
|
||||
// String ssidString = String(WiFi.SSID(i)).toCharArray(ssidArray, WiFi.SSID(i).length());
|
||||
ssidString.replace("\"", "\\\"");
|
||||
ssidString.toCharArray(ssidArray, 50);
|
||||
|
||||
|
||||
if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) {
|
||||
//res->println("{\"ssid\": \"%s\",\"rssi\": -75}, ", String(WiFi.SSID(i).c_str() );
|
||||
// res->println("{\"ssid\": \"%s\",\"rssi\": -75}, ", String(WiFi.SSID(i).c_str() );
|
||||
|
||||
res->printf("{\"ssid\": \"%s\",\"rssi\": %d}", ssidArray, WiFi.RSSI(i) ) ;
|
||||
//WiFi.RSSI(i)
|
||||
if (i != n-1) {
|
||||
res->printf("{\"ssid\": \"%s\",\"rssi\": %d}", ssidArray, WiFi.RSSI(i));
|
||||
// WiFi.RSSI(i)
|
||||
if (i != n - 1) {
|
||||
res->printf(",");
|
||||
}
|
||||
}
|
||||
|
@ -953,7 +1011,6 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res)
|
|||
res->println("},");
|
||||
res->println("\"status\": \"ok\"");
|
||||
res->println("}");
|
||||
|
||||
}
|
||||
|
||||
void handleFavicon(HTTPRequest *req, HTTPResponse *res)
|
||||
|
|
Ładowanie…
Reference in New Issue