真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

ESP32——WEB服務(wù)程序移植(基于示例restful-創(chuàng)新互聯(lián)

一、簡(jiǎn)介

將ESP32——WEB服務(wù)程序測(cè)試項(xiàng)目移植到一個(gè)現(xiàn)有項(xiàng)目中,現(xiàn)有項(xiàng)目包括基于固定IP的WIFI連接、OTA升級(jí)、Websocket等功能。

創(chuàng)新互聯(lián)公司-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比獨(dú)山網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式獨(dú)山網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋獨(dú)山地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴(lài)。二、移植 2.1 參考restful_server項(xiàng)目下分區(qū)表文件partitions_example.csv修改項(xiàng)目分區(qū)

因模塊采用ESP32-WROVER-E(4MB),故分區(qū)表內(nèi)容修改如下(后發(fā)現(xiàn)問(wèn)題,下面會(huì)提到)。

# Name,   Type, SubType,  Offset,   Size,  Flags
nvs,      data, nvs,      0x9000,  0x4000
otadata,  data, ota,      0xd000,  0x2000
phy_init, data, phy,      0xf000,  0x1000
ota_0,    app,  ota_0,    0x10000,  1M
ota_1,    app,  ota_1,    ,         1M
www,      data, spiffs,   ,         1M

并修改配置如下圖項(xiàng)。

2.2 復(fù)制前端代碼

將restful_server項(xiàng)目front目錄及其下所有內(nèi)容復(fù)制到現(xiàn)有項(xiàng)目根目錄下。

2.3 復(fù)制rest_server.c文件到現(xiàn)有項(xiàng)目main目錄下

并在main目錄下CMakeLists.txt文件中添加 "rest_server.c"

idf_component_register(SRCS "ota.c" "wifi.c" "websocket.c" "rest_server.c" "main.c"
                    INCLUDE_DIRS "."
                    # Embed the server root certificate into the final binary
                    EMBED_TXTFILES ${project_dir}/server_certs/ca_cert.pem)
2.4 復(fù)制esp_rest_main.c文件中如下內(nèi)容到現(xiàn)有項(xiàng)目main.c文件中
//此處略去了必要的頭文件和變量定義

esp_err_t start_rest_server(const char *base_path);

#if CONFIG_EXAMPLE_WEB_DEPLOY_SF
esp_err_t init_fs(void)
{
    esp_vfs_spiffs_conf_t conf = {
        .base_path = CONFIG_EXAMPLE_WEB_MOUNT_POINT,
        .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 ESP_FAIL;
    }

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    } else {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }
    return ESP_OK;
}
#endif

void app_main(void)
{
    esp_err_t err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK( err );

    IO_Init();  
    ip_set();
    wifi_init_sta();
    xTaskCreate(&advanced_ota_example_task, "advanced_ota_example_task", 1024 * 8, service_ip, 5, NULL);
    websocket_app_start(service_ip);
    ESP_ERROR_CHECK(init_fs());
    ESP_ERROR_CHECK(start_rest_server(CONFIG_EXAMPLE_WEB_MOUNT_POINT));
    // tasklist_show();   
    while (1)
    {
        LED_Run();
        Key_Read();
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }    
}
2.5 復(fù)制main目錄下Kconfig.projbuild中如下內(nèi)容到現(xiàn)有項(xiàng)目對(duì)應(yīng)文件中

注:項(xiàng)目Kconfig.projbuild中原來(lái)的內(nèi)容因?qū)嶋H未用到,故刪除了。

menu "Example Configuration"

    config EXAMPLE_MDNS_HOST_NAME
        string "mDNS Host Name"
        default "esp-home"
        help
            Specify the domain name used in the mDNS service.
            Note that webpage also take it as a part of URL where it will send GET/POST requests to.

    choice EXAMPLE_WEB_DEPLOY_MODE
        prompt "Website deploy mode"
        default EXAMPLE_WEB_DEPLOY_SEMIHOST
        help
            Select website deploy mode.
            You can deploy website to host, and ESP32 will retrieve them in a semihost way (JTAG is needed).
            You can deploy website to SD card or SPI flash, and ESP32 will retrieve them via SDIO/SPI interface.
            Detailed operation steps are listed in the example README file.
        config EXAMPLE_WEB_DEPLOY_SEMIHOST
            bool "Deploy website to host (JTAG is needed)"
            help
                Deploy website to host.
                It is recommended to choose this mode during developing.
        config EXAMPLE_WEB_DEPLOY_SD
            depends on IDF_TARGET_ESP32
            bool "Deploy website to SD card"
            help
                Deploy website to SD card.
                Choose this production mode if the size of website is too large (bigger than 2MB).
        config EXAMPLE_WEB_DEPLOY_SF
            bool "Deploy website to SPI Nor Flash"
            help
                Deploy website to SPI Nor Flash.
                Choose this production mode if the size of website is small (less than 2MB).
    endchoice

    if EXAMPLE_WEB_DEPLOY_SEMIHOST
        config EXAMPLE_HOST_PATH_TO_MOUNT
            string "Host path to mount (e.g. absolute path to web dist directory)"
            default "PATH-TO-WEB-DIST_DIR"
            help
                When using semihost in ESP32, you should specify the host path which will be mounted to VFS.
                Note that only absolute path is acceptable.
    endif

    config EXAMPLE_WEB_MOUNT_POINT
        string "Website mount point in VFS"
        default "/www"
        help
            Specify the mount point in VFS.

endmenu

保存后,重新打開(kāi)配置出現(xiàn)如下選項(xiàng),并做如下設(shè)置

2.6 復(fù)制main目錄下CMakeLists.txt中如下內(nèi)容到現(xiàn)有項(xiàng)目對(duì)應(yīng)文件中
if(CONFIG_EXAMPLE_WEB_DEPLOY_SF)
    set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../front/web-demo")
    if(EXISTS ${WEB_SRC_DIR}/dist)
        spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist FLASH_IN_PROJECT)
    else()
        message(FATAL_ERROR "${WEB_SRC_DIR}/dist doesn't exit. Please run 'npm run build' in ${WEB_SRC_DIR}")
    endif()
endif()
2.7 復(fù)制根目錄下Makefilet中如下內(nèi)容到現(xiàn)有項(xiàng)目對(duì)應(yīng)文件中
ifdef CONFIG_EXAMPLE_WEB_DEPLOY_SF
WEB_SRC_DIR = $(shell pwd)/front/web-demo
ifneq ($(wildcard $(WEB_SRC_DIR)/dist/.*),)
SPIFFS_IMAGE_FLASH_IN_PROJECT := 1
$(eval $(call spiffs_create_partition_image,www,$(WEB_SRC_DIR)/dist))
else
$(error $(WEB_SRC_DIR)/dist doesn't exist. Please run 'npm run build' in $(WEB_SRC_DIR))
endif
endif
2.8 修改配置如下部分:

?

此處文件名長(zhǎng)度如設(shè)置太小,編譯項(xiàng)目時(shí)會(huì)報(bào)錯(cuò)(前端部分生成的文件名比較長(zhǎng))。

三、調(diào)試

項(xiàng)目修改完成后,編譯出現(xiàn)下圖錯(cuò)誤

后來(lái)發(fā)現(xiàn)是因?yàn)榍岸松傻膁ist目錄內(nèi)容占用存儲(chǔ)空間超過(guò)1M,調(diào)整分區(qū)大小后正常。

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧


當(dāng)前名稱(chēng):ESP32——WEB服務(wù)程序移植(基于示例restful-創(chuàng)新互聯(lián)
瀏覽路徑:http://www.weahome.cn/article/pcjed.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部