Update to v0.9.0

This commit is contained in:
jomjol
2020-09-04 18:59:00 +02:00
parent 78e3256493
commit d51eaa1428
48 changed files with 10625 additions and 633 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,7 @@
#include "server_help.h"
#include "Helper.h"
#include "miniz.h"
/* Max length a file path can have on storage */
// #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
@@ -487,6 +488,103 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
}
void delete_all_in_directory(std::string _directory)
{
struct dirent *entry;
DIR *dir = opendir(_directory.c_str());
std::string filename;
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", _directory.c_str());
return;
}
/* Iterate over all files / folders and fetch their names and sizes */
while ((entry = readdir(dir)) != NULL) {
if (!(entry->d_type == DT_DIR)){
filename = _directory + std::string(entry->d_name);
ESP_LOGI(TAG, "Deleting file : %s", filename.c_str());
/* Delete file */
unlink(filename.c_str());
};
}
closedir(dir);
}
void unzip(std::string _in_zip_file, std::string _target_directory){
int i, sort_iter;
mz_bool status;
size_t uncomp_size;
mz_zip_archive zip_archive;
void* p;
const int N = 50;
char data[2048];
char archive_filename[64];
std::string zw;
// static const char* s_Test_archive_filename = "testhtml.zip";
printf("miniz.c version: %s\n", MZ_VERSION);
// Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
return;
}
// Get and print information about each file in the archive.
int numberoffiles = (int)mz_zip_reader_get_num_files(&zip_archive);
for (sort_iter = 0; sort_iter < 2; sort_iter++)
{
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
return;
}
for (i = 0; i < numberoffiles; i++)
{
mz_zip_archive_file_stat file_stat;
mz_zip_reader_file_stat(&zip_archive, i, &file_stat);
sprintf(archive_filename, file_stat.m_filename);
// Try to extract all the files to the heap.
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
if (!p)
{
printf("mz_zip_reader_extract_file_to_heap() failed!\n");
mz_zip_reader_end(&zip_archive);
return;
}
// Save to File.
zw = std::string(archive_filename);
zw = _target_directory + zw;
printf("Filename to extract: %s", zw.c_str());
FILE* fpTargetFile = fopen(zw.c_str(), "wb");
fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile);
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
// printf("File data: \"%s\"\n", (const char*)p);
// We're done.
mz_free(p);
}
// Close the archive, freeing any resources it was using
mz_zip_reader_end(&zip_archive);
}
printf("Success.\n");
}
void register_server_file_uri(httpd_handle_t server, const char *base_path)
{
static struct file_server_data *server_data = NULL;

View File

@@ -1,3 +1,8 @@
#include <esp_http_server.h>
#include <string>
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void unzip(std::string _in_zip_file, std::string _target_directory);
void delete_all_in_directory(std::string _directory);

View File

@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include "server_tflite.h"
#include "server_file.h"
#include "ClassLogFile.h"
@@ -301,14 +302,23 @@ void CheckOTAUpdate(void)
esp_err_t handler_ota_update(httpd_req_t *req)
{
LogFile.WriteToFile("handler_ota_update");
char _query[100];
char _query[200];
char _filename[30];
char _valuechar[30];
std::string fn = "/sdcard/firmware/";
bool _file_del = false;
std::string _task;
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
printf("Query: "); printf(_query); printf("\n");
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
printf("task is found"); printf(_valuechar); printf("\n");
_task = std::string(_valuechar);
}
if (httpd_query_key_value(_query, "file", _filename, 30) == ESP_OK)
{
fn.append(_filename);
@@ -323,6 +333,20 @@ esp_err_t handler_ota_update(httpd_req_t *req)
};
if (_task.compare("unziphtml") == 0)
{
std::string in, out, zw;
in = "/sdcard/firmware/html.zip";
out = "/sdcard/html/";
unzip(in, out);
zw = "Unzip html Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_file_del)
{
struct stat file_stat;