Selaa lähdekoodia

remove(http2_request): Move http2_request example to idf-extra-components repository

Related: https://github.com/espressif/idf-extra-components/pull/193/
Harshit Malpani 2 vuotta sitten
vanhempi
sitoutus
c24d012808

+ 6 - 0
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 <https://github.com/espressif/idf-extra-components/tree/master/coap/examples>`__ repository.
+
+
+HTTP2
+-----
+
+http2_request example has been moved to `idf-extra-components <https://github.com/espressif/idf-extra-components/tree/master/sh2lib/examples/http2_request>`__ repository.

+ 6 - 0
docs/zh_CN/migration-guides/release-5.x/5.2/protocols.rst

@@ -8,3 +8,9 @@ CoAP
 ----
 
 CoAP 相关示例已迁移至 `idf-extra-components <https://github.com/espressif/idf-extra-components/tree/master/coap/examples>`__ 仓库.
+
+
+HTTP2
+-----
+
+http2_request 相关示例已迁移至 `idf-extra-components <https://github.com/espressif/idf-extra-components/tree/master/sh2lib/examples/http2_request>`__ 仓库.

+ 0 - 6
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"

+ 0 - 10
examples/protocols/http2_request/CMakeLists.txt

@@ -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)

+ 0 - 58
examples/protocols/http2_request/README.md

@@ -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 <chip_name>`.
-
-### 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] <!DOCTYPE HTML>
-<html lang="en">
-.
-.
-.
-Body of index.html
-.
-.
-.
-.
-</html>
-[get-response] Frame fully received
-[get-response] Stream Closed
-```

+ 0 - 2
examples/protocols/http2_request/main/CMakeLists.txt

@@ -1,2 +0,0 @@
-idf_component_register(SRCS "http2_request_example_main.c"
-                    INCLUDE_DIRS ".")

+ 0 - 154
examples/protocols/http2_request/main/http2_request_example_main.c

@@ -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 <string.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#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);
-}

+ 0 - 3
examples/protocols/http2_request/main/idf_component.yml

@@ -1,3 +0,0 @@
-## IDF Component Manager Manifest File
-dependencies:
-  espressif/sh2lib: "^1.0.0"

+ 0 - 56
examples/protocols/http2_request/pytest_http2_request.py

@@ -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))

+ 0 - 11
examples/protocols/http2_request/sdkconfig.ci

@@ -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

+ 0 - 1
examples/protocols/http2_request/sdkconfig.defaults

@@ -1 +0,0 @@
-CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y

+ 0 - 1
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