diff --git a/components/coap/CMakeLists.txt b/components/coap/CMakeLists.txt index aef9d316..925ed75e 100644 --- a/components/coap/CMakeLists.txt +++ b/components/coap/CMakeLists.txt @@ -1,37 +1,41 @@ -set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2) +if(CONFIG_ENABLE_COAP) + set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2) -set(srcs - "libcoap/src/address.c" - "libcoap/src/async.c" - "libcoap/src/block.c" - "libcoap/src/coap_event.c" - "libcoap/src/coap_hashkey.c" - "libcoap/src/coap_session.c" - "libcoap/src/coap_time.c" - "libcoap/src/coap_debug.c" - "libcoap/src/encode.c" - "libcoap/src/mem.c" - "libcoap/src/net.c" - "libcoap/src/option.c" - "libcoap/src/pdu.c" - "libcoap/src/resource.c" - "libcoap/src/str.c" - "libcoap/src/subscribe.c" - "libcoap/src/uri.c" - "libcoap/src/coap_notls.c" - "port/coap_io.c") + set(srcs + "libcoap/src/address.c" + "libcoap/src/async.c" + "libcoap/src/block.c" + "libcoap/src/coap_event.c" + "libcoap/src/coap_hashkey.c" + "libcoap/src/coap_session.c" + "libcoap/src/coap_time.c" + "libcoap/src/coap_debug.c" + "libcoap/src/encode.c" + "libcoap/src/mem.c" + "libcoap/src/net.c" + "libcoap/src/option.c" + "libcoap/src/pdu.c" + "libcoap/src/resource.c" + "libcoap/src/str.c" + "libcoap/src/subscribe.c" + "libcoap/src/uri.c" + "libcoap/src/coap_notls.c" + "port/coap_io.c") -set(COMPONENT_REQUIRES lwip) + set(COMPONENT_REQUIRES lwip) -idf_component_register(SRCS "${srcs}" + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" REQUIRES lwip) -# Silence format truncation warning, until it is fixed upstream -set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation) + # Silence format truncation warning, until it is fixed upstream + set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation) -# Needed for coap headers in public builds, also. -# -# TODO: find a way to move this to a port header -target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX) + # Needed for coap headers in public builds, also. + # + # TODO: find a way to move this to a port header + target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX) +else() + register_component() +endif() diff --git a/components/coap/Kconfig b/components/coap/Kconfig new file mode 100644 index 00000000..825b8dea --- /dev/null +++ b/components/coap/Kconfig @@ -0,0 +1,10 @@ +menu "COAP" + +config ENABLE_COAP + bool "Enable coap" + default n + select LWIP_IPV6 + help + Enable this option and coap is to be used, IPv6 is to be Enable. +endmenu + diff --git a/components/coap/component.mk b/components/coap/component.mk index 2eb07afd..a656dbc2 100644 --- a/components/coap/component.mk +++ b/components/coap/component.mk @@ -2,6 +2,7 @@ # Component Makefile # +ifdef CONFIG_ENABLE_COAP COMPONENT_ADD_INCLUDEDIRS := port/include port/include/coap libcoap/include libcoap/include/coap2 COMPONENT_OBJS = libcoap/src/address.o libcoap/src/async.o libcoap/src/block.o libcoap/src/coap_event.o libcoap/src/coap_hashkey.o libcoap/src/coap_session.o libcoap/src/coap_time.o libcoap/src/coap_debug.o libcoap/src/encode.o libcoap/src/mem.o libcoap/src/net.o libcoap/src/option.o libcoap/src/pdu.o libcoap/src/resource.o libcoap/src/str.o libcoap/src/subscribe.o libcoap/src/uri.o libcoap/src/coap_notls.o port/coap_io.o @@ -12,3 +13,4 @@ COMPONENT_SUBMODULES += libcoap # Silence format truncation warning, until it is fixed upstream libcoap/src/coap_debug.o: CFLAGS += -Wno-format-truncation +endif diff --git a/examples/protocols/coap_client/main/coap_client_example_main.c b/examples/protocols/coap_client/main/coap_client_example_main.c index 921541ae..3d4f9f4c 100644 --- a/examples/protocols/coap_client/main/coap_client_example_main.c +++ b/examples/protocols/coap_client/main/coap_client_example_main.c @@ -18,7 +18,7 @@ #include "esp_log.h" #include "esp_wifi.h" #include "esp_event.h" - +#include "esp_netif.h" #include "nvs_flash.h" #include "protocol_examples_common.h" @@ -282,7 +282,7 @@ clean_up: void app_main(void) { ESP_ERROR_CHECK( nvs_flash_init() ); - tcpip_adapter_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. diff --git a/examples/protocols/coap_client/sdkconfig.defaults b/examples/protocols/coap_client/sdkconfig.defaults new file mode 100644 index 00000000..ce4e909c --- /dev/null +++ b/examples/protocols/coap_client/sdkconfig.defaults @@ -0,0 +1 @@ +CONFIG_ENABLE_COAP=y diff --git a/examples/protocols/coap_server/main/coap_server_example_main.c b/examples/protocols/coap_server/main/coap_server_example_main.c index eb5e131b..a7b6f085 100644 --- a/examples/protocols/coap_server/main/coap_server_example_main.c +++ b/examples/protocols/coap_server/main/coap_server_example_main.c @@ -17,7 +17,7 @@ #include "esp_log.h" #include "esp_wifi.h" #include "esp_event.h" - +#include "esp_netif.h" #include "nvs_flash.h" #include "protocol_examples_common.h" @@ -162,7 +162,7 @@ clean_up: void app_main(void) { ESP_ERROR_CHECK( nvs_flash_init() ); - tcpip_adapter_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. diff --git a/examples/protocols/coap_server/sdkconfig.defaults b/examples/protocols/coap_server/sdkconfig.defaults new file mode 100644 index 00000000..ce4e909c --- /dev/null +++ b/examples/protocols/coap_server/sdkconfig.defaults @@ -0,0 +1 @@ +CONFIG_ENABLE_COAP=y