From c24d012808554ea7e9254081f9d8b16e95c591c6 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Mon, 3 Jul 2023 17:00:32 +0530 Subject: [PATCH] remove(http2_request): Move http2_request example to idf-extra-components repository Related: https://github.com/espressif/idf-extra-components/pull/193/ --- .../release-5.x/5.2/protocols.rst | 6 + .../release-5.x/5.2/protocols.rst | 6 + examples/protocols/.build-test-rules.yml | 6 - .../protocols/http2_request/CMakeLists.txt | 10 -- examples/protocols/http2_request/README.md | 58 ------- .../http2_request/main/CMakeLists.txt | 2 - .../main/http2_request_example_main.c | 154 ------------------ .../http2_request/main/idf_component.yml | 3 - .../http2_request/pytest_http2_request.py | 56 ------- examples/protocols/http2_request/sdkconfig.ci | 11 -- .../http2_request/sdkconfig.defaults | 1 - tools/ci/check_copyright_ignore.txt | 1 - 12 files changed, 12 insertions(+), 302 deletions(-) delete mode 100644 examples/protocols/http2_request/CMakeLists.txt delete mode 100644 examples/protocols/http2_request/README.md delete mode 100644 examples/protocols/http2_request/main/CMakeLists.txt delete mode 100644 examples/protocols/http2_request/main/http2_request_example_main.c delete mode 100644 examples/protocols/http2_request/main/idf_component.yml delete mode 100644 examples/protocols/http2_request/pytest_http2_request.py delete mode 100644 examples/protocols/http2_request/sdkconfig.ci delete mode 100644 examples/protocols/http2_request/sdkconfig.defaults diff --git a/docs/en/migration-guides/release-5.x/5.2/protocols.rst b/docs/en/migration-guides/release-5.x/5.2/protocols.rst index dc97390f2f..9aabf04a50 100644 --- a/docs/en/migration-guides/release-5.x/5.2/protocols.rst +++ b/docs/en/migration-guides/release-5.x/5.2/protocols.rst @@ -8,3 +8,9 @@ CoAP ---- CoAP examples have been moved to `idf-extra-components `__ repository. + + +HTTP2 +----- + +http2_request example has been moved to `idf-extra-components `__ repository. diff --git a/docs/zh_CN/migration-guides/release-5.x/5.2/protocols.rst b/docs/zh_CN/migration-guides/release-5.x/5.2/protocols.rst index 3d3f8f0f8b..139ecd0148 100644 --- a/docs/zh_CN/migration-guides/release-5.x/5.2/protocols.rst +++ b/docs/zh_CN/migration-guides/release-5.x/5.2/protocols.rst @@ -8,3 +8,9 @@ CoAP ---- CoAP 相关示例已迁移至 `idf-extra-components `__ 仓库. + + +HTTP2 +----- + +http2_request 相关示例已迁移至 `idf-extra-components `__ 仓库. diff --git a/examples/protocols/.build-test-rules.yml b/examples/protocols/.build-test-rules.yml index 584f73fb4c..8d680a8605 100644 --- a/examples/protocols/.build-test-rules.yml +++ b/examples/protocols/.build-test-rules.yml @@ -16,12 +16,6 @@ examples/protocols/esp_local_ctrl: temporary: true reason: lack of runners -examples/protocols/http2_request: - disable_test: - - if: IDF_TARGET != "esp32" - temporary: true - reason: only test on esp32 - examples/protocols/http_request: disable_test: - if: IDF_TARGET != "esp32" diff --git a/examples/protocols/http2_request/CMakeLists.txt b/examples/protocols/http2_request/CMakeLists.txt deleted file mode 100644 index da07146f28..0000000000 --- a/examples/protocols/http2_request/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# The following lines of boilerplate have to be in your project's CMakeLists -# in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.16) - -# (Not part of the boilerplate) -# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection. -set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(http2_request) diff --git a/examples/protocols/http2_request/README.md b/examples/protocols/http2_request/README.md deleted file mode 100644 index e496fd338e..0000000000 --- a/examples/protocols/http2_request/README.md +++ /dev/null @@ -1,58 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | - -# HTTP/2 Request Example - -Establish an HTTP/2 connection with https://http2.github.io -- Performs a GET on /index.html - -## How to use example -Before project configuration and build, be sure to set the correct chip target using `idf.py set-target `. - -### Hardware Required - -* A development board with ESP32/ESP32-S2/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) -* A USB cable for power supply and programming - -### Configure the project - -``` -idf.py menuconfig -``` -Open the project configuration menu (`idf.py menuconfig`) to configure Wi-Fi or Ethernet. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details. - -### Build and Flash - -Build the project and flash it to the board, then run monitor tool to view serial output: - -``` -idf.py -p PORT flash monitor -``` - -(Replace PORT with the name of the serial port to use.) - -(To exit the serial monitor, type ``Ctrl-]``.) - -See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. - -## Example Output - -``` -I (5609) example_connect: - IPv4 address: 192.168.0.103 -I (5609) example_connect: - IPv6 address: fe80:0000:0000:0000:ae67:b2ff:fe45:0194, type: ESP_IP6_ADDR_IS_LINK_LOCAL -Connecting to server -Connection done -[get-response] - -. -. -. -Body of index.html -. -. -. -. - -[get-response] Frame fully received -[get-response] Stream Closed -``` diff --git a/examples/protocols/http2_request/main/CMakeLists.txt b/examples/protocols/http2_request/main/CMakeLists.txt deleted file mode 100644 index 40f03c8800..0000000000 --- a/examples/protocols/http2_request/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "http2_request_example_main.c" - INCLUDE_DIRS ".") diff --git a/examples/protocols/http2_request/main/http2_request_example_main.c b/examples/protocols/http2_request/main/http2_request_example_main.c deleted file mode 100644 index e1b79c3a66..0000000000 --- a/examples/protocols/http2_request/main/http2_request_example_main.c +++ /dev/null @@ -1,154 +0,0 @@ -/* HTTP2 GET Example using nghttp2 - - Contacts http2.github.io and executes the GET request. A thin API - wrapper on top of nghttp2, to properly demonstrate the interactions. - - 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 -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_wifi.h" -#include "esp_event.h" -#include "esp_system.h" -#include "nvs_flash.h" -#include "protocol_examples_common.h" -#include "esp_netif.h" -#include "esp_netif_sntp.h" -#include "sdkconfig.h" - -#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE -#include "esp_crt_bundle.h" -#endif - -#include "sh2lib.h" - -/* The HTTP/2 server to connect to */ -#define HTTP2_SERVER_URI "https://http2.github.io" -/* A GET request that keeps streaming current time every second */ -#define HTTP2_STREAMING_GET_PATH "/index.html" - - -int handle_get_response(struct sh2lib_handle *handle, const char *data, size_t len, int flags) -{ - if (len) { - printf("[get-response] %.*s\n", len, data); - } - if (flags == DATA_RECV_FRAME_COMPLETE) { - printf("[get-response] Frame fully received\n"); - } - if (flags == DATA_RECV_RST_STREAM) { - printf("[get-response] Stream Closed\n"); - } - return 0; -} - -int handle_echo_response(struct sh2lib_handle *handle, const char *data, size_t len, int flags) -{ - if (len) { - printf("[echo-response] %.*s\n", len, data); - } - if (flags == DATA_RECV_FRAME_COMPLETE) { - printf("[echo-response] Frame fully received\n"); - } - if (flags == DATA_RECV_RST_STREAM) { - printf("[echo-response] Stream Closed\n"); - } - return 0; -} - -int send_put_data(struct sh2lib_handle *handle, char *buf, size_t length, uint32_t *data_flags) -{ -#define DATA_TO_SEND "Hello World" - int copylen = strlen(DATA_TO_SEND); - if (copylen < length) { - printf("[data-prvd] Sending %d bytes\n", copylen); - memcpy(buf, DATA_TO_SEND, copylen); - } else { - copylen = 0; - } - - (*data_flags) |= NGHTTP2_DATA_FLAG_EOF; - return copylen; -} - -static void set_time(void) -{ - struct timeval tv = { - .tv_sec = 1509449941, - }; - struct timezone tz = { - 0, 0 - }; - settimeofday(&tv, &tz); - - /* Start SNTP service */ - esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG("time.windows.com"); - esp_netif_sntp_init(&config); - if (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(10000)) != ESP_OK) { - printf("Failed to update system time, continuing"); - } - esp_netif_deinit(); -} - -static void http2_task(void *args) -{ - /* Set current time: proper system time is required for TLS based - * certificate verification. - */ - set_time(); - - /* HTTP2: one connection multiple requests. Do the TLS/TCP connection first */ - printf("Connecting to server\n"); - - struct sh2lib_config_t cfg = { - .uri = HTTP2_SERVER_URI, -#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE - .crt_bundle_attach = esp_crt_bundle_attach, -#endif - }; - struct sh2lib_handle hd; - - if (sh2lib_connect(&cfg, &hd) != 0) { - printf("Failed to connect\n"); - vTaskDelete(NULL); - return; - } - printf("Connection done\n"); - - /* HTTP GET */ - sh2lib_do_get(&hd, HTTP2_STREAMING_GET_PATH, handle_get_response); - while (1) { - /* Process HTTP2 send/receive */ - if (sh2lib_execute(&hd) < 0) { - printf("Error in send/receive\n"); - break; - } - vTaskDelay(2); - } - - sh2lib_free(&hd); - vTaskDelete(NULL); -} - -void app_main(void) -{ - ESP_ERROR_CHECK( nvs_flash_init() ); - ESP_ERROR_CHECK(esp_netif_init()); - ESP_ERROR_CHECK(esp_event_loop_create_default()); - - /* 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()); - - xTaskCreate(&http2_task, "http2_task", (1024 * 32), NULL, 5, NULL); -} diff --git a/examples/protocols/http2_request/main/idf_component.yml b/examples/protocols/http2_request/main/idf_component.yml deleted file mode 100644 index b50694dcdb..0000000000 --- a/examples/protocols/http2_request/main/idf_component.yml +++ /dev/null @@ -1,3 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/sh2lib: "^1.0.0" diff --git a/examples/protocols/http2_request/pytest_http2_request.py b/examples/protocols/http2_request/pytest_http2_request.py deleted file mode 100644 index ab508aa95c..0000000000 --- a/examples/protocols/http2_request/pytest_http2_request.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Apache-2.0 - -import http.client -import logging -import os - -import pytest -from pytest_embedded import Dut - -HTTP_OK = 200 -TEST_SERVER = 'http2.github.io' - - -def is_test_server_available(): # type: () -> bool - # 443 - default https port - try: - conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10) - conn.request('GET', '/') - resp = conn.getresponse() - return True if resp.status == HTTP_OK else False - except Exception as msg: - logging.info('Exception occurred when connecting to {}: {}'.format(TEST_SERVER, msg)) - return False - finally: - conn.close() - - -@pytest.mark.esp32 -@pytest.mark.ethernet -def test_examples_protocol_http2_request(dut: Dut) -> None: - """ - steps: | - 1. join AP - 2. connect to http2.github.io - 3. send http2 request - 4. send http2 put response - """ - # check and log bin size - binary_file = os.path.join(dut.app.binary_path, 'http2_request.bin') - bin_size = os.path.getsize(binary_file) - logging.info('http2_request_bin_size : {}KB'.format(bin_size // 1024)) - # start the test - # check if test server is avilable - test_server_available = is_test_server_available() - # Skip the test if the server test server (http2.github.io) is not available at the moment. - if test_server_available: - logging.info('test server \"{}\" is available'.format(TEST_SERVER)) - # check for connection - dut.expect('Connection done', timeout=30) - # check for get response - dut.expect('Frame fully received') - else: - logging.info('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER)) diff --git a/examples/protocols/http2_request/sdkconfig.ci b/examples/protocols/http2_request/sdkconfig.ci deleted file mode 100644 index 81b8c599e6..0000000000 --- a/examples/protocols/http2_request/sdkconfig.ci +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_SPIRAM=y -CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y -CONFIG_EXAMPLE_CONNECT_ETHERNET=y -CONFIG_EXAMPLE_CONNECT_WIFI=n -CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y -CONFIG_EXAMPLE_ETH_PHY_IP101=y -CONFIG_EXAMPLE_ETH_MDC_GPIO=23 -CONFIG_EXAMPLE_ETH_MDIO_GPIO=18 -CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5 -CONFIG_EXAMPLE_ETH_PHY_ADDR=1 -CONFIG_EXAMPLE_CONNECT_IPV6=y diff --git a/examples/protocols/http2_request/sdkconfig.defaults b/examples/protocols/http2_request/sdkconfig.defaults deleted file mode 100644 index 998be296ee..0000000000 --- a/examples/protocols/http2_request/sdkconfig.defaults +++ /dev/null @@ -1 +0,0 @@ -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 6d66b8db94..8f2f082c45 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1396,7 +1396,6 @@ examples/protocols/esp_http_client/main/esp_http_client_example.c examples/protocols/esp_local_ctrl/example_test.py examples/protocols/esp_local_ctrl/main/app_main.c examples/protocols/esp_local_ctrl/main/esp_local_ctrl_service.c -examples/protocols/http2_request/main/http2_request_example_main.c examples/protocols/http_request/main/http_request_example_main.c examples/protocols/http_server/advanced_tests/http_server_advanced_test.py examples/protocols/http_server/advanced_tests/main/include/tests.h