httpd_start and spiffs
Posted: Fri Jan 11, 2019 10:15 pm
I am trying to add spiffs functionality to http_server/simple example. For some reason adding spiffs initialization into server start routine breaks the code and it no longer responds to requests from browser, so if I type xx.xx.xx.xx/hello into browser bar I get timeout. The code is shown below. It is literally http_server example code with few lines from spiffs example inserted (plus relevant #include, not shown here)
If I added the spiffs initialization earlier, at the beginning of the function, the example runs correctly. Just this particular order is problematic. Program displays the message "Registering URI handlers" and the returned value is not-NULL so it is not early return from the function. The partition table is set up, spiffs partition is uploaded and files can be read.
I probably shall place spiff initialization even earlier, before initializing wifi in app_main, but since I noticed there is a problem here, can someone explain to me what are hidden interactions between spiffs and httpd and what can go wrong ?
Thanks in advance.
If I added the spiffs initialization earlier, at the beginning of the function, the example runs correctly. Just this particular order is problematic. Program displays the message "Registering URI handlers" and the returned value is not-NULL so it is not early return from the function. The partition table is set up, spiffs partition is uploaded and files can be read.
I probably shall place spiff initialization even earlier, before initializing wifi in app_main, but since I noticed there is a problem here, can someone explain to me what are hidden interactions between spiffs and httpd and what can go wrong ?
Thanks in advance.
- httpd_handle_t start_webserver(void)
- {
- httpd_handle_t server = NULL;
- httpd_config_t config = HTTPD_DEFAULT_CONFIG();
- // Start the httpd server
- ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
- if (httpd_start(&server, &config) == ESP_OK) {
- ESP_LOGI(TAG, "Initializing SPIFFS");
- esp_vfs_spiffs_conf_t conf = {
- .base_path = "/spiffs",
- .partition_label = NULL,
- .max_files = 5,
- .format_if_mount_failed = false
- };
- esp_err_t ret = esp_vfs_spiffs_register(&conf);
- if (ret != ESP_OK) {
- if (ret == ESP_FAIL) {
- ESP_LOGE(TAG, "Failed to mount or format filesystem");
- } else if (ret == ESP_ERR_NOT_FOUND) {
- ESP_LOGE(TAG, "Failed to find SPIFFS partition");
- } else {
- ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
- }
- return NULL;
- }
- // Set URI handlers
- ESP_LOGI(TAG, "Registering URI handlers");
- httpd_register_uri_handler(server, &hello);
- httpd_register_uri_handler(server, &echo);
- httpd_register_uri_handler(server, &ctrl);
- return server;
- }
- ESP_LOGI(TAG, "Error starting server!");
- return NULL;
- }
- Partition table binary generated. Contents:
- *******************************************************************************
- # Espressif ESP32 Partition Table
- # Name, Type, SubType, Offset, Size, Flags
- nvs,data,nvs,0x9000,24K,
- phy_init,data,phy,0xf000,4K,
- factory,app,factory,0x10000,1M,
- www,data,spiffs,0x110000,64K,
- *******************************************************************************
- ../../../tools/mkspiffs/mkspiffs --version
- mkspiffs ver. 0.2.3-5-g9f4acb5
- Build configuration name: generic
- SPIFFS ver. 0.3.7-5-gf5e26c4
- Extra build flags: (none)
- SPIFFS configuration:
- SPIFFS_OBJ_NAME_LEN: 32
- SPIFFS_OBJ_META_LEN: 0
- SPIFFS_USE_MAGIC: 1
- SPIFFS_USE_MAGIC_LENGTH: 1
- SPIFFS_ALIGNED_OBJECT_INDEX_TABLES: 0
- ##
- # SPIFFS Configuration
- #
- CONFIG_SPIFFS_MAX_PARTITIONS=3
- #
- # SPIFFS Cache Configuration
- #
- CONFIG_SPIFFS_CACHE=y
- CONFIG_SPIFFS_CACHE_WR=y
- CONFIG_SPIFFS_CACHE_STATS=
- CONFIG_SPIFFS_PAGE_CHECK=y
- CONFIG_SPIFFS_GC_MAX_RUNS=10
- CONFIG_SPIFFS_GC_STATS=
- CONFIG_SPIFFS_PAGE_SIZE=256
- CONFIG_SPIFFS_OBJ_NAME_LEN=32
- CONFIG_SPIFFS_USE_MAGIC=y
- CONFIG_SPIFFS_USE_MAGIC_LENGTH=y
- CONFIG_SPIFFS_META_LENGTH=0
- #
- # Debug Configuration
- #
- CONFIG_SPIFFS_DBG=
- CONFIG_SPIFFS_API_DBG=
- CONFIG_SPIFFS_GC_DBG=
- CONFIG_SPIFFS_CACHE_DBG=
- CONFIG_SPIFFS_CHECK_DBG=
- CONFIG_SPIFFS_TEST_VISUALISATION=