mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'fix/fix_https_server_linux_build_v6.0' into 'release/v6.0'
fix(https_server): fixes failing example build for linux target (v6.0) See merge request espressif/esp-idf!48205
This commit is contained in:
@@ -509,8 +509,11 @@ endif()
|
|||||||
|
|
||||||
target_link_libraries(${COMPONENT_LIB} ${linkage_type} ${mbedtls_link_targets})
|
target_link_libraries(${COMPONENT_LIB} ${linkage_type} ${mbedtls_link_targets})
|
||||||
|
|
||||||
# Ensure PSA crypto initialization is included in the build
|
# Ensure PSA crypto initialization is included in the build.
|
||||||
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
# On macOS (Mach-O), C symbols have a leading underscore prefix.
|
||||||
|
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND ${IDF_TARGET} STREQUAL "linux")
|
||||||
|
target_link_libraries(${COMPONENT_LIB} ${linkage_type} "-u _mbedtls_psa_crypto_init_include_impl")
|
||||||
|
else()
|
||||||
target_link_libraries(${COMPONENT_LIB} ${linkage_type} "-u mbedtls_psa_crypto_init_include_impl")
|
target_link_libraries(${COMPONENT_LIB} ${linkage_type} "-u mbedtls_psa_crypto_init_include_impl")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
|
set(requires esp_https_server nvs_flash)
|
||||||
|
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"
|
idf_component_register(SRCS "main.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES esp_https_server esp_wifi nvs_flash esp_eth
|
PRIV_REQUIRES ${requires}
|
||||||
EMBED_TXTFILES "certs/servercert.pem"
|
EMBED_TXTFILES "certs/servercert.pem"
|
||||||
"certs/prvtkey.pem"
|
"certs/prvtkey.pem"
|
||||||
"certs/cacert.pem"
|
"certs/cacert.pem"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
protocol_examples_common:
|
protocol_examples_common:
|
||||||
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
|
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
|
||||||
|
esp_stubs:
|
||||||
|
path: ${IDF_PATH}/examples/protocols/linux_stubs/esp_stubs
|
||||||
|
rules:
|
||||||
|
- if: "target in [linux]"
|
||||||
|
|||||||
@@ -7,18 +7,21 @@
|
|||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <esp_wifi.h>
|
#include <unistd.h>
|
||||||
#include <esp_event.h>
|
#include <esp_event.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_system.h>
|
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
#include "esp_eth.h"
|
|
||||||
#include "protocol_examples_common.h"
|
#include "protocol_examples_common.h"
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
|
#include <esp_wifi.h>
|
||||||
|
#include <esp_system.h>
|
||||||
|
#include "esp_eth.h"
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
#include <esp_https_server.h>
|
#include <esp_https_server.h>
|
||||||
#include "esp_tls.h"
|
#include "esp_tls.h"
|
||||||
@@ -179,6 +182,11 @@ static httpd_handle_t start_webserver(void)
|
|||||||
|
|
||||||
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
|
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_LINUX
|
||||||
|
/* Use non-privileged port on Linux since port 443 requires root */
|
||||||
|
conf.port_secure = 8443;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern const unsigned char servercert_start[] asm("_binary_servercert_pem_start");
|
extern const unsigned char servercert_start[] asm("_binary_servercert_pem_start");
|
||||||
extern const unsigned char servercert_end[] asm("_binary_servercert_pem_end");
|
extern const unsigned char servercert_end[] asm("_binary_servercert_pem_end");
|
||||||
|
|
||||||
@@ -235,6 +243,7 @@ static httpd_handle_t start_webserver(void)
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
static esp_err_t stop_webserver(httpd_handle_t server)
|
static esp_err_t stop_webserver(httpd_handle_t server)
|
||||||
{
|
{
|
||||||
// Stop the httpd server
|
// Stop the httpd server
|
||||||
@@ -262,6 +271,7 @@ static void connect_handler(void* arg, esp_event_base_t event_base,
|
|||||||
*server = start_webserver();
|
*server = start_webserver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
@@ -275,6 +285,7 @@ void app_main(void)
|
|||||||
* and stop server when disconnection happens.
|
* and stop server when disconnection happens.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
|
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
|
||||||
@@ -283,6 +294,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler, &server));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
|
||||||
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
|
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_SERVER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_SERVER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||||
|
|
||||||
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
|
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
|
||||||
@@ -290,4 +302,12 @@ void app_main(void)
|
|||||||
* examples/protocols/README.md for more information about this function.
|
* examples/protocols/README.md for more information about this function.
|
||||||
*/
|
*/
|
||||||
ESP_ERROR_CHECK(example_connect());
|
ESP_ERROR_CHECK(example_connect());
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_LINUX
|
||||||
|
/* On Linux, start the server directly since there are no WiFi/Ethernet events */
|
||||||
|
server = start_webserver();
|
||||||
|
while (server) {
|
||||||
|
sleep(5);
|
||||||
|
}
|
||||||
|
#endif // CONFIG_IDF_TARGET_LINUX
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
|
set(requires esp_https_server nvs_flash esp_timer esp_netif)
|
||||||
|
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 "wss_server_example.c" "keep_alive.c"
|
idf_component_register(SRCS "wss_server_example.c" "keep_alive.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES esp_https_server nvs_flash esp_timer esp_netif esp_eth esp_wifi
|
PRIV_REQUIRES ${requires}
|
||||||
EMBED_TXTFILES "certs/servercert.pem"
|
EMBED_TXTFILES "certs/servercert.pem"
|
||||||
"certs/prvtkey.pem")
|
"certs/prvtkey.pem")
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
protocol_examples_common:
|
protocol_examples_common:
|
||||||
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
|
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
|
||||||
|
esp_stubs:
|
||||||
|
path: ${IDF_PATH}/examples/protocols/linux_stubs/esp_stubs
|
||||||
|
rules:
|
||||||
|
- if: "target in [linux]"
|
||||||
|
|||||||
@@ -8,12 +8,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_system.h>
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "keep_alive.h"
|
#include "keep_alive.h"
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
|
#include <esp_system.h>
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
|
#else
|
||||||
|
#include <time.h>
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NO_CLIENT = 0,
|
NO_CLIENT = 0,
|
||||||
@@ -47,7 +51,13 @@ static const char *TAG = "wss_keep_alive";
|
|||||||
|
|
||||||
static uint64_t _tick_get_ms(void)
|
static uint64_t _tick_get_ms(void)
|
||||||
{
|
{
|
||||||
return esp_timer_get_time()/1000;
|
#if CONFIG_IDF_TARGET_LINUX
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||||
|
#else
|
||||||
|
return esp_timer_get_time() / 1000;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Goes over active clients to find out how long we could sleep before checking who's alive
|
// Goes over active clients to find out how long we could sleep before checking who's alive
|
||||||
|
|||||||
@@ -9,14 +9,18 @@
|
|||||||
|
|
||||||
#include <esp_event.h>
|
#include <esp_event.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_system.h>
|
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include "protocol_examples_common.h"
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
|
#include <esp_system.h>
|
||||||
#include "esp_eth.h"
|
#include "esp_eth.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "protocol_examples_common.h"
|
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
#include <esp_https_server.h>
|
#include <esp_https_server.h>
|
||||||
#include "keep_alive.h"
|
#include "keep_alive.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
@@ -191,6 +195,10 @@ static httpd_handle_t start_wss_echo_server(void)
|
|||||||
ESP_LOGI(TAG, "Starting server");
|
ESP_LOGI(TAG, "Starting server");
|
||||||
|
|
||||||
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
|
httpd_ssl_config_t conf = HTTPD_SSL_CONFIG_DEFAULT();
|
||||||
|
#if CONFIG_IDF_TARGET_LINUX
|
||||||
|
/* Use non-privileged port on Linux since port 443 requires root */
|
||||||
|
conf.port_secure = 8443;
|
||||||
|
#endif
|
||||||
conf.httpd.max_open_sockets = max_clients;
|
conf.httpd.max_open_sockets = max_clients;
|
||||||
conf.httpd.global_user_ctx = keep_alive;
|
conf.httpd.global_user_ctx = keep_alive;
|
||||||
conf.httpd.open_fn = wss_open_fd;
|
conf.httpd.open_fn = wss_open_fd;
|
||||||
@@ -220,6 +228,7 @@ static httpd_handle_t start_wss_echo_server(void)
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
static esp_err_t stop_wss_echo_server(httpd_handle_t server)
|
static esp_err_t stop_wss_echo_server(httpd_handle_t server)
|
||||||
{
|
{
|
||||||
// Stop keep alive thread
|
// Stop keep alive thread
|
||||||
@@ -249,6 +258,7 @@ static void connect_handler(void* arg, esp_event_base_t event_base,
|
|||||||
*server = start_wss_echo_server();
|
*server = start_wss_echo_server();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
// Get all clients and send async message
|
// Get all clients and send async message
|
||||||
static void wss_server_send_messages(httpd_handle_t* server)
|
static void wss_server_send_messages(httpd_handle_t* server)
|
||||||
@@ -299,6 +309,7 @@ void app_main(void)
|
|||||||
* and stop server when disconnection happens.
|
* and stop server when disconnection happens.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !CONFIG_IDF_TARGET_LINUX
|
||||||
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
|
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
|
||||||
@@ -307,6 +318,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler, &server));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
|
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
|
||||||
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
|
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||||
|
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
|
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
|
||||||
* Read "Establishing Wi-Fi or Ethernet Connection" section in
|
* Read "Establishing Wi-Fi or Ethernet Connection" section in
|
||||||
@@ -314,6 +326,11 @@ void app_main(void)
|
|||||||
*/
|
*/
|
||||||
ESP_ERROR_CHECK(example_connect());
|
ESP_ERROR_CHECK(example_connect());
|
||||||
|
|
||||||
|
#if CONFIG_IDF_TARGET_LINUX
|
||||||
|
/* On Linux, start the server directly since there are no WiFi/Ethernet events */
|
||||||
|
server = start_wss_echo_server();
|
||||||
|
#endif // CONFIG_IDF_TARGET_LINUX
|
||||||
|
|
||||||
/* This function demonstrates periodic sending Websocket messages
|
/* This function demonstrates periodic sending Websocket messages
|
||||||
* to all connected clients to this server
|
* to all connected clients to this server
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user