esp-idf/examples/protocols/http_server/file_serving/main/main.c
Ivan Grokhotkov be56c85b18
examples: file_serving: add support for ESP32-S3, refactoring
* Move filesystem mounting code into a separate file to simplify the
  main source file.
* Clean up SDMMC and SDSPI related code. Move pin configuration into
  Kconfig.
* Use same base_path ('/data') for either SPIFFS or SD. Remove the
  check in file_server.c about the base path.
* Update README according to the changes above.
2022-04-19 13:46:37 +02:00

51 lines
1.5 KiB
C

/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* HTTP File Server Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_err.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include "file_serving_example_common.h"
/* This example demonstrates how to create file server
* using esp_http_server. This file has only startup code.
* Look in file_server.c for the implementation.
*/
static const char *TAG = "example";
void app_main(void)
{
ESP_LOGI(TAG, "Starting example");
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* Initialize file storage */
const char* base_path = "/data";
ESP_ERROR_CHECK(example_mount_storage(base_path));
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
/* Start the file server */
ESP_ERROR_CHECK(example_start_file_server(base_path));
ESP_LOGI(TAG, "File server started");
}