mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-30 11:33:44 +02:00
Add MDNS Manager
This commit is contained in:
4
components/MDNSManager/CMakeLists.txt
Normal file
4
components/MDNSManager/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
idf_component_register(SRCS "MDNSManager/MDNSManager.cpp"
|
||||||
|
INCLUDE_DIRS "MDNSManager"
|
||||||
|
REQUIRES mdns ProjectConfig StateManager
|
||||||
|
)
|
||||||
47
components/MDNSManager/MDNSManager/MDNSManager.cpp
Normal file
47
components/MDNSManager/MDNSManager/MDNSManager.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include "MDNSManager.hpp"
|
||||||
|
|
||||||
|
static const char *MDNS_MANAGER_TAG = "[MDNS MANAGER]";
|
||||||
|
|
||||||
|
MDNSManager::MDNSManager(ProjectConfig &projectConfig) : projectConfig(projectConfig) {}
|
||||||
|
|
||||||
|
esp_err_t MDNSManager::start()
|
||||||
|
{
|
||||||
|
const std::string &mdnsName = "_openiristracker";
|
||||||
|
|
||||||
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Starting);
|
||||||
|
esp_err_t result = mdns_init();
|
||||||
|
if (result != ESP_OK)
|
||||||
|
{
|
||||||
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
|
||||||
|
ESP_LOGE(MDNS_MANAGER_TAG, "Failed to initialize mDNS server: %s", esp_err_to_name(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto mdnsConfig = projectConfig.getMDNSConfig();
|
||||||
|
result = mdns_hostname_set(mdnsConfig.hostname.c_str());
|
||||||
|
if (result != ESP_OK)
|
||||||
|
{
|
||||||
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
|
||||||
|
ESP_LOGE(MDNS_MANAGER_TAG, "Failed to set hostname: %s", esp_err_to_name(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
mdns_txt_item_t serviceTxtData[3] = {
|
||||||
|
{"stream_port", "80"},
|
||||||
|
{"api_port", "81"},
|
||||||
|
};
|
||||||
|
|
||||||
|
result = mdns_service_add(nullptr, mdnsName.c_str(), "_tcp", 80, serviceTxtData, 2);
|
||||||
|
|
||||||
|
result = mdns_service_instance_name_set(mdnsName.c_str(), "_tcp", mdnsName.c_str());
|
||||||
|
if (result != ESP_OK)
|
||||||
|
{
|
||||||
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Error);
|
||||||
|
ESP_LOGE(MDNS_MANAGER_TAG, "Failed to set mDNS instance name: %s", esp_err_to_name(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
mdnsStateManager.setState(MDNSState_e::MDNSState_Started);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
21
components/MDNSManager/MDNSManager/MDNSManager.hpp
Normal file
21
components/MDNSManager/MDNSManager/MDNSManager.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef MDNSMANAGER_HPP
|
||||||
|
#define MDNSMANAGER_HPP
|
||||||
|
#include <string>
|
||||||
|
#include <ProjectConfig.hpp>
|
||||||
|
#include <StateManager.hpp>
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "mdns.h"
|
||||||
|
|
||||||
|
// TODO add observer pattern here
|
||||||
|
class MDNSManager
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ProjectConfig &projectConfig;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MDNSManager(ProjectConfig &projectConfig);
|
||||||
|
esp_err_t start();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MDNSMANAGER_HPP
|
||||||
@@ -26,6 +26,16 @@ dependencies:
|
|||||||
registry_url: https://components.espressif.com/
|
registry_url: https://components.espressif.com/
|
||||||
type: service
|
type: service
|
||||||
version: 2.5.5
|
version: 2.5.5
|
||||||
|
espressif/mdns:
|
||||||
|
component_hash: af6306fe65d637a3683d1cf671508fcedd6b05f9ca029a8815abeab64001fb8d
|
||||||
|
dependencies:
|
||||||
|
- name: idf
|
||||||
|
require: private
|
||||||
|
version: '>=5.0'
|
||||||
|
source:
|
||||||
|
registry_url: https://components.espressif.com/
|
||||||
|
type: service
|
||||||
|
version: 1.4.0
|
||||||
espressif/tinyusb:
|
espressif/tinyusb:
|
||||||
component_hash: 214989d502fc168241a4a4f83b097d8ac44a93cd6f1787b4ac10069a8b3bebd3
|
component_hash: 214989d502fc168241a4a4f83b097d8ac44a93cd6f1787b4ac10069a8b3bebd3
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -69,8 +79,9 @@ dependencies:
|
|||||||
direct_dependencies:
|
direct_dependencies:
|
||||||
- espressif/esp32-camera
|
- espressif/esp32-camera
|
||||||
- espressif/led_strip
|
- espressif/led_strip
|
||||||
|
- espressif/mdns
|
||||||
- espressif/usb_device_uvc
|
- espressif/usb_device_uvc
|
||||||
- idf
|
- idf
|
||||||
manifest_hash: 10ae06dee995e9f5b117c494c0d7becd586027c7109cd05681c7e469c643dd90
|
manifest_hash: dfe29d524d2f5acb426e21118042ac1c021e44e8e7072b700d872ac75499cd6c
|
||||||
target: esp32s3
|
target: esp32s3
|
||||||
version: 2.0.0
|
version: 2.0.0
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
|
espressif/mdns: "*"
|
||||||
espressif/led_strip: "^2.4.1"
|
espressif/led_strip: "^2.4.1"
|
||||||
idf: "^5.0"
|
idf: "^5.0"
|
||||||
espressif/esp32-camera: "^2.0.0"
|
espressif/esp32-camera: "^2.0.0"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <wifiManager.hpp>
|
#include <wifiManager.hpp>
|
||||||
#include <ProjectConfig.hpp>
|
#include <ProjectConfig.hpp>
|
||||||
#include <LEDManager.hpp>
|
#include <LEDManager.hpp>
|
||||||
|
#include <MDNSManager.hpp>
|
||||||
|
|
||||||
#define BLINK_GPIO (gpio_num_t) CONFIG_BLINK_GPIO
|
#define BLINK_GPIO (gpio_num_t) CONFIG_BLINK_GPIO
|
||||||
|
|
||||||
@@ -47,19 +48,20 @@ extern "C" void app_main(void)
|
|||||||
// port preferences lib - DONE; prolly temporary
|
// port preferences lib - DONE; prolly temporary
|
||||||
// then port the config - done, needs todos done
|
// then port the config - done, needs todos done
|
||||||
// State Management - done
|
// State Management - done
|
||||||
// then port the led manager as this will be fairly easy - in progress
|
// then port the led manager as this will be fairly easy - done
|
||||||
|
// then port the mdns stuff - done
|
||||||
// then add ADHOC and support for more networks in wifi manager
|
// then add ADHOC and support for more networks in wifi manager
|
||||||
// then port the serial manager
|
|
||||||
// then port the camera manager
|
// then port the camera manager
|
||||||
// then port the streaming stuff (web and uvc)
|
// then port the streaming stuff (web and uvc)
|
||||||
// then port the async web server
|
// then port the async web server
|
||||||
// then port the Elegant OTA stuff
|
// then port the Elegant OTA stuff
|
||||||
// then port the mdns stuff
|
// then port the serial manager
|
||||||
|
|
||||||
// TODO add this option
|
// TODO add this option
|
||||||
// ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
// ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME);
|
||||||
ProjectConfig deviceConfig("openiris", "openiristracker");
|
ProjectConfig deviceConfig("openiris", "openiristracker");
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
|
MDNSManager mdnsManager(deviceConfig);
|
||||||
|
|
||||||
#ifdef USE_ILLUMNATIOR_PIN
|
#ifdef USE_ILLUMNATIOR_PIN
|
||||||
// LEDManager ledManager(BLINK_GPIO, ILLUMINATOR_PIN);
|
// LEDManager ledManager(BLINK_GPIO, ILLUMINATOR_PIN);
|
||||||
@@ -74,6 +76,7 @@ extern "C" void app_main(void)
|
|||||||
ledManager.setup();
|
ledManager.setup();
|
||||||
deviceConfig.load();
|
deviceConfig.load();
|
||||||
wifiManager.Begin();
|
wifiManager.Begin();
|
||||||
|
mdnsManager.start();
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
7
min_spiffs.csv
Normal file
7
min_spiffs.csv
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
nvs, data, nvs, 0x9000, 0x5000,
|
||||||
|
otadata, data, ota, 0xe000, 0x2000,
|
||||||
|
app0, app, ota_0, 0x10000, 0x1E0000,
|
||||||
|
app1, app, ota_1, 0x1F0000,0x1E0000,
|
||||||
|
spiffs, data, spiffs, 0x3D0000,0x20000,
|
||||||
|
coredump, data, coredump,0x3F0000,0x10000,
|
||||||
|
38
sdkconfig
38
sdkconfig
@@ -518,12 +518,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
|||||||
#
|
#
|
||||||
# Partition Table
|
# Partition Table
|
||||||
#
|
#
|
||||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
||||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="min_spiffs.csv"
|
||||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
CONFIG_PARTITION_TABLE_FILENAME="min_spiffs.csv"
|
||||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||||
CONFIG_PARTITION_TABLE_MD5=y
|
CONFIG_PARTITION_TABLE_MD5=y
|
||||||
# end of Partition Table
|
# end of Partition Table
|
||||||
@@ -2075,6 +2075,36 @@ CONFIG_CAMERA_JPEG_MODE_FRAME_SIZE_AUTO=y
|
|||||||
# CONFIG_LCD_CAM_ISR_IRAM_SAFE is not set
|
# CONFIG_LCD_CAM_ISR_IRAM_SAFE is not set
|
||||||
# end of Camera configuration
|
# end of Camera configuration
|
||||||
|
|
||||||
|
#
|
||||||
|
# mDNS
|
||||||
|
#
|
||||||
|
CONFIG_MDNS_MAX_INTERFACES=3
|
||||||
|
CONFIG_MDNS_MAX_SERVICES=10
|
||||||
|
CONFIG_MDNS_TASK_PRIORITY=1
|
||||||
|
CONFIG_MDNS_ACTION_QUEUE_LEN=16
|
||||||
|
CONFIG_MDNS_TASK_STACK_SIZE=4096
|
||||||
|
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
|
||||||
|
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
|
||||||
|
# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set
|
||||||
|
CONFIG_MDNS_TASK_AFFINITY=0x0
|
||||||
|
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
|
||||||
|
CONFIG_MDNS_TIMER_PERIOD_MS=100
|
||||||
|
# CONFIG_MDNS_NETWORKING_SOCKET is not set
|
||||||
|
# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set
|
||||||
|
# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set
|
||||||
|
CONFIG_MDNS_ENABLE_CONSOLE_CLI=y
|
||||||
|
# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set
|
||||||
|
CONFIG_MDNS_MULTIPLE_INSTANCE=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# MDNS Predefined interfaces
|
||||||
|
#
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_STA=y
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_AP=y
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_ETH=y
|
||||||
|
# end of MDNS Predefined interfaces
|
||||||
|
# end of mDNS
|
||||||
|
|
||||||
#
|
#
|
||||||
# USB Device UVC
|
# USB Device UVC
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -518,12 +518,12 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
|||||||
#
|
#
|
||||||
# Partition Table
|
# Partition Table
|
||||||
#
|
#
|
||||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
||||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
CONFIG_PARTITION_TABLE_TWO_OTA=y
|
||||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
CONFIG_PARTITION_TABLE_FILENAME="partitions_two_ota.csv"
|
||||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||||
CONFIG_PARTITION_TABLE_MD5=y
|
CONFIG_PARTITION_TABLE_MD5=y
|
||||||
# end of Partition Table
|
# end of Partition Table
|
||||||
@@ -539,8 +539,8 @@ CONFIG_BLINK_LED_GPIO=y
|
|||||||
# CONFIG_BLINK_LED_STRIP is not set
|
# CONFIG_BLINK_LED_STRIP is not set
|
||||||
CONFIG_BLINK_GPIO=21
|
CONFIG_BLINK_GPIO=21
|
||||||
CONFIG_BLINK_PERIOD=1000
|
CONFIG_BLINK_PERIOD=1000
|
||||||
CONFIG_WIFI_SSID=""
|
CONFIG_WIFI_SSID="UPC7878684"
|
||||||
CONFIG_WIFI_PASSOWRD=""
|
CONFIG_WIFI_PASSOWRD="j3ttQPpfvhep"
|
||||||
# end of Example Configuration
|
# end of Example Configuration
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -1413,14 +1413,13 @@ CONFIG_HEAP_TRACING_OFF=y
|
|||||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
||||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
||||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
CONFIG_LOG_DEFAULT_LEVEL=4
|
||||||
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y
|
# CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT is not set
|
||||||
# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set
|
CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y
|
||||||
# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set
|
CONFIG_LOG_MAXIMUM_LEVEL=5
|
||||||
CONFIG_LOG_MAXIMUM_LEVEL=3
|
|
||||||
# CONFIG_LOG_MASTER_LEVEL is not set
|
# CONFIG_LOG_MASTER_LEVEL is not set
|
||||||
CONFIG_LOG_COLORS=y
|
CONFIG_LOG_COLORS=y
|
||||||
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
||||||
@@ -2076,6 +2075,36 @@ CONFIG_CAMERA_JPEG_MODE_FRAME_SIZE_AUTO=y
|
|||||||
# CONFIG_LCD_CAM_ISR_IRAM_SAFE is not set
|
# CONFIG_LCD_CAM_ISR_IRAM_SAFE is not set
|
||||||
# end of Camera configuration
|
# end of Camera configuration
|
||||||
|
|
||||||
|
#
|
||||||
|
# mDNS
|
||||||
|
#
|
||||||
|
CONFIG_MDNS_MAX_INTERFACES=3
|
||||||
|
CONFIG_MDNS_MAX_SERVICES=10
|
||||||
|
CONFIG_MDNS_TASK_PRIORITY=1
|
||||||
|
CONFIG_MDNS_ACTION_QUEUE_LEN=16
|
||||||
|
CONFIG_MDNS_TASK_STACK_SIZE=4096
|
||||||
|
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
|
||||||
|
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
|
||||||
|
# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set
|
||||||
|
CONFIG_MDNS_TASK_AFFINITY=0x0
|
||||||
|
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
|
||||||
|
CONFIG_MDNS_TIMER_PERIOD_MS=100
|
||||||
|
# CONFIG_MDNS_NETWORKING_SOCKET is not set
|
||||||
|
# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set
|
||||||
|
# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set
|
||||||
|
CONFIG_MDNS_ENABLE_CONSOLE_CLI=y
|
||||||
|
# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set
|
||||||
|
CONFIG_MDNS_MULTIPLE_INSTANCE=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# MDNS Predefined interfaces
|
||||||
|
#
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_STA=y
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_AP=y
|
||||||
|
CONFIG_MDNS_PREDEF_NETIF_ETH=y
|
||||||
|
# end of MDNS Predefined interfaces
|
||||||
|
# end of mDNS
|
||||||
|
|
||||||
#
|
#
|
||||||
# USB Device UVC
|
# USB Device UVC
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user