Utilize SPIFFS for serving the app with web-server
With this commit the webserver of the controller can serve a folder (/react-app/build/), when the ip is accessed in a web-browser. Currently the react app is successfully served and the armchair can be controlled when in HTTP mode and connected via AP. - CMakeLists: Add command that creates and flashes the spiffs partition when running idf.py flash - main.cpp: Add function to initialize spiffs - http.cpp: uncomment handler for default URL (accesses spiffs) - Add partitions.csv: needed for the creation of spiffs.bin during compilation - Add sdkconfig: It was necessary to change the FLASH_SIZE from 2MB to 4MB. To avoid having the same trouble on other devices the sdkconfig is now added to the repository
This commit is contained in:
parent
7872a5fb21
commit
a80502f95b
@ -1,2 +1,18 @@
|
|||||||
idf_component_register(SRCS "main.cpp" "motordrivers.cpp" "motorctl.cpp" "config.cpp" "joystick.cpp" "buzzer.cpp" "control.cpp" "button.cpp" "fan.cpp" "wifi.c" "http.cpp"
|
idf_component_register(
|
||||||
INCLUDE_DIRS ".")
|
SRCS
|
||||||
|
"main.cpp"
|
||||||
|
"motordrivers.cpp"
|
||||||
|
"motorctl.cpp"
|
||||||
|
"config.cpp"
|
||||||
|
"joystick.cpp"
|
||||||
|
"buzzer.cpp"
|
||||||
|
"control.cpp"
|
||||||
|
"button.cpp"
|
||||||
|
"fan.cpp"
|
||||||
|
"wifi.c"
|
||||||
|
"http.cpp"
|
||||||
|
INCLUDE_DIRS
|
||||||
|
"."
|
||||||
|
)
|
||||||
|
|
||||||
|
spiffs_create_partition_image(spiffs ../react-app/build FLASH_IN_PROJECT)
|
||||||
|
@ -190,11 +190,11 @@ void http_init_server()
|
|||||||
};
|
};
|
||||||
httpd_register_uri_handler(server, &joystick_url);
|
httpd_register_uri_handler(server, &joystick_url);
|
||||||
|
|
||||||
// httpd_uri_t default_url = {
|
httpd_uri_t default_url = {
|
||||||
// .uri = "/*",
|
.uri = "/*",
|
||||||
// .method = HTTP_GET,
|
.method = HTTP_GET,
|
||||||
// .handler = on_default_url};
|
.handler = on_default_url};
|
||||||
// httpd_register_uri_handler(server, &default_url);
|
httpd_register_uri_handler(server, &default_url);
|
||||||
|
|
||||||
// httpd_uri_t socket_joystick_url = {
|
// httpd_uri_t socket_joystick_url = {
|
||||||
// .uri = "/ws-api/joystick",
|
// .uri = "/ws-api/joystick",
|
||||||
|
@ -9,6 +9,7 @@ extern "C"
|
|||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_spiffs.h"
|
||||||
|
|
||||||
#include "driver/ledc.h"
|
#include "driver/ledc.h"
|
||||||
|
|
||||||
@ -99,6 +100,29 @@ void task_fans( void * pvParameters ){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=================================
|
||||||
|
//========== init spiffs ==========
|
||||||
|
//=================================
|
||||||
|
//initialize spi flash filesystem (used for webserver)
|
||||||
|
void init_spiffs(){
|
||||||
|
ESP_LOGI(TAG, "init spiffs");
|
||||||
|
esp_vfs_spiffs_conf_t esp_vfs_spiffs_conf = {
|
||||||
|
.base_path = "/spiffs",
|
||||||
|
.partition_label = NULL,
|
||||||
|
.max_files = 5,
|
||||||
|
.format_if_mount_failed = true};
|
||||||
|
esp_vfs_spiffs_register(&esp_vfs_spiffs_conf);
|
||||||
|
|
||||||
|
size_t total = 0;
|
||||||
|
size_t used = 0;
|
||||||
|
esp_spiffs_info(NULL, &total, &used);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "SPIFFS: total %d, used %d", total, used);
|
||||||
|
esp_vfs_spiffs_unregister(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================================
|
//=================================
|
||||||
//=========== app_main ============
|
//=========== app_main ============
|
||||||
//=================================
|
//=================================
|
||||||
@ -167,6 +191,8 @@ extern "C" void app_main(void) {
|
|||||||
//--- initialize nvs-flash and netif (needed for wifi) ---
|
//--- initialize nvs-flash and netif (needed for wifi) ---
|
||||||
wifi_initNvs_initNetif();
|
wifi_initNvs_initNetif();
|
||||||
|
|
||||||
|
//--- initialize spiffs ---
|
||||||
|
init_spiffs();
|
||||||
|
|
||||||
//--- initialize and start wifi ---
|
//--- initialize and start wifi ---
|
||||||
//FIXME: run wifi_init_client or wifi_init_ap as intended from control.cpp when switching state
|
//FIXME: run wifi_init_client or wifi_init_ap as intended from control.cpp when switching state
|
||||||
|
6
partitions.csv
Normal file
6
partitions.csv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||||
|
nvs, data, nvs, , 0x6000,
|
||||||
|
phy_init, data, phy, , 0x1000,
|
||||||
|
factory, app, factory, , 1M,
|
||||||
|
spiffs, data, spiffs, , 1M
|
|
Loading…
x
Reference in New Issue
Block a user