Merge branch 'bugfix/enable_simple_http_server_on_linux' into 'master'

fix(examples): simple http_server example build for Linux target

See merge request espressif/esp-idf!36277
This commit is contained in:
Mahavir Jain
2025-01-13 19:44:45 +08:00
7 changed files with 39 additions and 87 deletions

View File

@@ -1,13 +1,6 @@
set(priv_req mbedtls)
set(priv_inc_dir "src/util")
set(priv_req mbedtls lwip esp_timer)
set(priv_inc_dir "src/util" "src/port/esp32")
set(requires http_parser esp_event)
if(NOT ${IDF_TARGET} STREQUAL "linux")
list(APPEND priv_req lwip esp_timer)
list(APPEND priv_inc_dir "src/port/esp32")
else()
list(APPEND priv_inc_dir "src/port/linux")
list(APPEND priv_req pthread)
endif()
idf_component_register(SRCS "src/httpd_main.c"
"src/httpd_parse.c"

View File

@@ -1,55 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <unistd.h>
#include <stdint.h>
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OS_SUCCESS ESP_OK
#define OS_FAIL ESP_FAIL
typedef TaskHandle_t othread_t;
static inline int httpd_os_thread_create(othread_t *thread,
const char *name, uint16_t stacksize, int prio,
void (*thread_routine)(void *arg), void *arg,
BaseType_t core_id, uint32_t caps)
{
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setstacksize(&thread_attr, stacksize);
int ret = pthread_create((pthread_t *)thread, &thread_attr, (void*)thread_routine, arg);
if (ret == 0) {
return OS_SUCCESS;
}
return OS_FAIL;
}
/* Only self delete is supported */
static inline void httpd_os_thread_delete(void)
{
int x;
pthread_exit((void *)&x);
}
static inline void httpd_os_thread_sleep(int msecs)
{
usleep(msecs * 1000);
}
static inline othread_t httpd_os_thread_handle(void)
{
return (othread_t)pthread_self();
}
#ifdef __cplusplus
}
#endif

View File

@@ -47,7 +47,7 @@
/* Allocate memory for the task's stack using the provided memory caps
* */
pxStack = heap_caps_malloc( usStackDepth, ( uint32_t ) uxMemoryCaps );
pxStack = heap_caps_malloc( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ), ( uint32_t ) uxMemoryCaps );
if( ( pxTaskBuffer == NULL ) || ( pxStack == NULL ) )
{

View File

@@ -23,8 +23,8 @@ examples/protocols/esp_http_client:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
disable_test:
- if: IDF_TARGET not in ["esp32", "linux"]
depends_filepatterns:
- components/esp_http_client/**/*
depends_components+:
- esp_http_client
examples/protocols/esp_local_ctrl:
<<: *default_dependencies
@@ -36,8 +36,9 @@ examples/protocols/esp_local_ctrl:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/protocomm/**/*
- tools/esp_prov/**/*
depends_components+:
- protocomm
examples/protocols/http_request:
<<: *default_dependencies
@@ -50,8 +51,8 @@ examples/protocols/http_server:
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server
examples/protocols/http_server/captive_portal:
<<: *default_dependencies
@@ -61,8 +62,8 @@ examples/protocols/http_server/captive_portal:
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server
examples/protocols/http_server/restful_server:
<<: *default_dependencies
@@ -70,16 +71,26 @@ examples/protocols/http_server/restful_server:
- if: IDF_TARGET in ["esp32h2"]
temporary: true
reason: not supported yet
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server
examples/protocols/http_server/simple:
<<: *default_dependencies
enable:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_components+:
- esp_http_server
examples/protocols/http_server/ws_echo_server:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_http_server/**/*
depends_components+:
- esp_http_server
examples/protocols/https_mbedtls:
<<: *default_dependencies
@@ -104,25 +115,25 @@ examples/protocols/https_server/simple:
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
reason: only test on these targets
depends_filepatterns:
- components/esp_https_server/**/*
- components/esp_tls/**/*
depends_components+:
- esp_https_server
- esp-tls
examples/protocols/https_server/wss_server:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_https_server/**/*
depends_components+:
- esp_https_server
examples/protocols/https_x509_bundle:
<<: *default_dependencies
disable_test:
- if: IDF_TARGET != "esp32"
reason: only test on esp32
depends_filepatterns:
- components/esp_tls/**/*
depends_components+:
- esp-tls
examples/protocols/icmp_echo:
<<: *default_dependencies

View File

@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |
# Simple HTTPD Server Example

View File

@@ -1,9 +1,12 @@
set(requires esp-tls nvs_flash esp_netif esp_http_server esp_wifi esp_eth)
set(requires esp-tls nvs_flash esp_netif esp_http_server)
idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "linux")
list(APPEND requires esp_stubs protocol_examples_common)
else()
list(APPEND requires esp_wifi esp_eth)
endif()
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES ${requires})

View File

@@ -407,7 +407,7 @@ static esp_err_t sse_handler(httpd_req_t *req)
gettimeofday(&tv, NULL); // Get the current time
int64_t time_since_boot = tv.tv_sec; // Time since boot in seconds
esp_err_t err;
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %lld seconds\n\n", time_since_boot);
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %" PRIi64 " seconds\n\n", time_since_boot);
if ((err = httpd_resp_send_chunk(req, sse_data, len)) != ESP_OK) {
ESP_LOGE(TAG, "Failed to send sse data (returned %02X)", err);
break;