From faefa979dd37cf8fa5f3d97f3f15cfd7d7876128 Mon Sep 17 00:00:00 2001 From: windowsair Date: Sun, 16 Jan 2022 20:12:42 +0800 Subject: [PATCH] feat(mDNS): Add mDNS server --- .gitignore | 3 ++- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ ESP8266_RTOS_SDK | 2 +- README.md | 7 +++++++ components/corsacOTA | 1 + main/main.c | 33 +++++++++++++++++++++++++++++++++ main/uart_bridge.c | 0 main/wifi_configuration.h | 5 +++++ sdkconfig | 4 +++- 10 files changed, 57 insertions(+), 3 deletions(-) create mode 160000 components/corsacOTA create mode 100644 main/uart_bridge.c diff --git a/.gitignore b/.gitignore index 33904f1..036d287 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ build/ tmp/ -.history/ \ No newline at end of file +.history/ +sdkconfig.old \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 8950d78..073401e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "ESP8266_RTOS_SDK"] path = ESP8266_RTOS_SDK url = https://github.com/espressif/ESP8266_RTOS_SDK +[submodule "components/corsacOTA"] + path = components/corsacOTA + url = https://github.com/windowsair/corsacOTA.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ee5b850..750902c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.5) +# Colored Compiler Output with ninja +add_compile_options (-fdiagnostics-color=always) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/ESP8266_RTOS_SDK b/ESP8266_RTOS_SDK index 1be2289..a7677d6 160000 --- a/ESP8266_RTOS_SDK +++ b/ESP8266_RTOS_SDK @@ -1 +1 @@ -Subproject commit 1be2289fcd68672f5d6bf6aafa4f4b57b20527a4 +Subproject commit a7677d6d678dcbb74f4f9162123fe4462676b590 diff --git a/README.md b/README.md index cdd37cb..913e896 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,13 @@ You can also specify your IP in the above file (We recommend using the static ad ![WIFI](https://user-images.githubusercontent.com/17078589/118365659-517e7880-b5d0-11eb-9a5b-afe43348c2ba.png) + +There is built-in ipv4 only mDNS server. You can access the device using `dap.local` . + +![mDNS](https://user-images.githubusercontent.com/17078589/149659052-7b29533f-9660-4811-8125-f8f50490d762.png) + + + ### Debugger diff --git a/components/corsacOTA b/components/corsacOTA new file mode 160000 index 0000000..98e9ffe --- /dev/null +++ b/components/corsacOTA @@ -0,0 +1 @@ +Subproject commit 98e9ffeb3b08e91743b147cf292dfd76259fc380 diff --git a/main/main.c b/main/main.c index 0d723e5..9943934 100644 --- a/main/main.c +++ b/main/main.c @@ -31,6 +31,7 @@ #include "lwip/sys.h" #include +#include "mdns.h" extern void DAP_Setup(void); extern void DAP_Thread(void *argument); @@ -149,6 +150,35 @@ static void wait_for_ip() } +static const char *MDNS_TAG = "server_common"; + +void mdns_setup() { + // initialize mDNS + int ret; + ret = mdns_init(); + if (ret != ESP_OK) { + ESP_LOGW(MDNS_TAG, "mDNS initialize failed:%d", ret); + return; + } + + // set mDNS hostname + ret = mdns_hostname_set(MDNS_HOSTNAME); + if (ret != ESP_OK) { + ESP_LOGW(MDNS_TAG, "mDNS set hostname failed:%d", ret); + return; + } + ESP_LOGI(MDNS_TAG, "mDNS hostname set to: [%s]", MDNS_HOSTNAME); + + // set default mDNS instance name + ret = mdns_instance_name_set(MDNS_INSTANCE); + if (ret != ESP_OK) { + ESP_LOGW(MDNS_TAG, "mDNS set instance name failed:%d", ret); + return; + } + ESP_LOGI(MDNS_TAG, "mDNS instance name set to: [%s]", MDNS_INSTANCE); +} + + void app_main() { // struct rst_info *rtc_info = system_get_rst_info(); @@ -174,6 +204,9 @@ void app_main() DAP_Setup(); timer_init(); +#if (USE_MDNS == 1) + mdns_setup(); +#endif // Specify the usbip server task #if (USE_KCP == 1) xTaskCreate(kcp_server_task, "kcp_server", 4096, NULL, 7, NULL); diff --git a/main/uart_bridge.c b/main/uart_bridge.c new file mode 100644 index 0000000..e69de29 diff --git a/main/wifi_configuration.h b/main/wifi_configuration.h index c1a0f5b..0eccb9b 100644 --- a/main/wifi_configuration.h +++ b/main/wifi_configuration.h @@ -14,6 +14,11 @@ #define WIFI_PASS "12345678" +#define USE_MDNS 1 +// Use the address "dap.local" to access the device +#define MDNS_HOSTNAME "dap" +#define MDNS_INSTANCE "DAP mDNS" + #define USE_STATIC_IP 1 // If you don't want to specify the ip configuration, then ignore the following items. #define DAP_IP_ADDRESS 192, 168, 137, 123 diff --git a/sdkconfig b/sdkconfig index b52f54b..1145d7d 100644 --- a/sdkconfig +++ b/sdkconfig @@ -384,7 +384,9 @@ CONFIG_ESP_SHA=y CONFIG_ESP_AES=y CONFIG_ESP_MD5=y CONFIG_ESP_ARC4=y -# CONFIG_ENABLE_MDNS is not set +CONFIG_ENABLE_MDNS=y +# CONFIG_ENABLE_MDNS_CONSOLE is not set +CONFIG_MDNS_MAX_SERVICES=1 CONFIG_MQTT_PROTOCOL_311=y CONFIG_MQTT_TRANSPORT_SSL=y CONFIG_MQTT_TRANSPORT_WEBSOCKET=y