Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include <string.h>
#include <esp_err.h>
#include <esp_log.h>
#include "mdns.h"
#include <esp_netif.h>
#include <protocomm_httpd.h>
#include <esp_local_ctrl.h>
#include <esp_https_server.h>
#include <esp_http_server.h>
#define esp_local_ctrl_httpd_start
#define esp_local_ctrl_httpd_stop
#define esp_local_ctrl_httpd_start
#define esp_local_ctrl_httpd_stop
#include "esp_local_ctrl_priv.h"
#define LOCAL_CTRL_VERSION
TAG
server_handle
start_httpd_transport(protocomm_t *, const esp_local_ctrl_transport_config_t *)
stop_httpd_transport(protocomm_t *)
copy_httpd_config(esp_local_ctrl_transport_config_t *, const esp_local_ctrl_transport_config_t *)
free_config(esp_local_ctrl_transport_config_t *)
esp_local_ctrl_get_transport_httpd()
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
include
proto-c
src
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_local_ctrl/src/esp_local_ctrl_transport_httpd.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdio.h> #include <string.h> #include <esp_err.h> #include <esp_log.h> #if defined __has_include # if __has_include("mdns.h") # define WITH_MDNS # include "mdns.h"/* ... */ # endif/* ... */ #endif #include <esp_netif.h> #include <protocomm_httpd.h> #include <esp_local_ctrl.h> #ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE #include <esp_https_server.h> #else #include <esp_http_server.h> #endif #ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE #define esp_local_ctrl_httpd_start httpd_ssl_start #define esp_local_ctrl_httpd_stop httpd_ssl_stop/* ... */ #else #define esp_local_ctrl_httpd_start httpd_start #define esp_local_ctrl_httpd_stop httpd_stop/* ... */ #endif #include "esp_local_ctrl_priv.h" #define LOCAL_CTRL_VERSION "v1.0" static const char *TAG = "esp_local_ctrl_transport_httpd"; static httpd_handle_t server_handle = NULL; static esp_err_t start_httpd_transport(protocomm_t *pc, const esp_local_ctrl_transport_config_t *config) { if (!config || !config->httpd) { ESP_LOGE(TAG, "NULL configuration provided"); return ESP_ERR_INVALID_ARG; }{...} esp_err_t err; #ifdef WITH_MDNS uint16_t port = 0; #ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE /* Extract configured port */ port = ( config->httpd->transport_mode == HTTPD_SSL_TRANSPORT_SECURE ? config->httpd->port_secure : config->httpd->port_insecure );/* ... */ #else port = config->httpd->server_port; #endif err = mdns_service_add("Local Control Service", "_esp_local_ctrl", "_tcp", port, NULL, 0); if (err != ESP_OK) { /* mDNS is not mandatory for provisioning to work, * so print warning and return without failure *//* ... */ ESP_LOGW(TAG, "Error adding mDNS service! Check if mDNS is running"); }{...} else { /* Information to identify the roles of the various * protocomm endpoint URIs provided by the service *//* ... */ err |= mdns_service_txt_item_set("_esp_local_ctrl", "_tcp", "version_endpoint", "/esp_local_ctrl/version"); err |= mdns_service_txt_item_set("_esp_local_ctrl", "_tcp", "session_endpoint", "/esp_local_ctrl/session"); err |= mdns_service_txt_item_set("_esp_local_ctrl", "_tcp", "control_endpoint", "/esp_local_ctrl/control"); if (err != ESP_OK) { ESP_LOGE(TAG, "Error adding mDNS service text item"); }{...} }{...} #endif/* ... */ err = esp_local_ctrl_httpd_start(&server_handle, config->httpd); if (ESP_OK != err) { ESP_LOGE(TAG, "Error starting HTTP/S service!"); #ifdef WITH_MDNS mdns_service_remove("_esp_local_ctrl", "_tcp"); #endif return err; }{...} protocomm_httpd_config_t pc_conf = { .ext_handle_provided = true, .data = { .handle = &server_handle }{...} }{...}; return protocomm_httpd_start(pc, &pc_conf); }{ ... } static void stop_httpd_transport(protocomm_t *pc) { #ifdef WITH_MDNS mdns_service_remove("_esp_local_ctrl", "_tcp"); #endif protocomm_httpd_stop(pc); if (esp_local_ctrl_httpd_stop(server_handle) == ESP_OK) { server_handle = NULL; }{...} }{ ... } static esp_err_t copy_httpd_config(esp_local_ctrl_transport_config_t *dest_config, const esp_local_ctrl_transport_config_t *src_config) { if (!dest_config || !src_config || !src_config->httpd) { ESP_LOGE(TAG, "NULL configuration provided"); return ESP_ERR_INVALID_ARG; }{...} dest_config->httpd = calloc(1, sizeof(esp_local_ctrl_transport_config_httpd_t)); if (!dest_config->httpd) { ESP_LOGE(TAG, "Failed to allocate memory for HTTPD transport config"); return ESP_ERR_NO_MEM; }{...} memcpy(dest_config->httpd, src_config->httpd, sizeof(esp_local_ctrl_transport_config_httpd_t)); return ESP_OK; }{ ... } static void free_config(esp_local_ctrl_transport_config_t *config) { if (config && config->httpd) { free(config->httpd); config->httpd = NULL; }{...} }{ ... } const esp_local_ctrl_transport_t *esp_local_ctrl_get_transport_httpd(void) { static const esp_local_ctrl_transport_t tp = { .start_service = start_httpd_transport, .stop_service = stop_httpd_transport, .copy_config = copy_httpd_config, .declare_ep = NULL, .free_config = free_config }{...}; return &tp; }{ ... };
Details