mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-29 17:16:32 +03:00
fix(https_server): fixes failing example build for linux target
This commit is contained in:
@@ -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"
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES esp_https_server esp_wifi nvs_flash esp_eth
|
||||
PRIV_REQUIRES ${requires}
|
||||
EMBED_TXTFILES "certs/servercert.pem"
|
||||
"certs/prvtkey.pem"
|
||||
"certs/cacert.pem"
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
dependencies:
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <esp_wifi.h>
|
||||
#include <unistd.h>
|
||||
#include <esp_event.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_system.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "esp_netif.h"
|
||||
#include "esp_eth.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_tls.h"
|
||||
@@ -181,6 +184,11 @@ static httpd_handle_t start_webserver(void)
|
||||
|
||||
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_end[] asm("_binary_servercert_pem_end");
|
||||
|
||||
@@ -237,6 +245,7 @@ static httpd_handle_t start_webserver(void)
|
||||
return server;
|
||||
}
|
||||
|
||||
#if !CONFIG_IDF_TARGET_LINUX
|
||||
static esp_err_t stop_webserver(httpd_handle_t server)
|
||||
{
|
||||
// Stop the httpd server
|
||||
@@ -264,6 +273,7 @@ static void connect_handler(void* arg, esp_event_base_t event_base,
|
||||
*server = start_webserver();
|
||||
}
|
||||
}
|
||||
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
@@ -277,6 +287,7 @@ void app_main(void)
|
||||
* and stop server when disconnection happens.
|
||||
*/
|
||||
|
||||
#if !CONFIG_IDF_TARGET_LINUX
|
||||
#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(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server));
|
||||
@@ -285,6 +296,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(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &server));
|
||||
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||
#endif // !CONFIG_IDF_TARGET_LINUX
|
||||
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_SERVER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS
|
||||
@@ -294,4 +306,12 @@ void app_main(void)
|
||||
* examples/protocols/README.md for more information about this function.
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user