Skip to content

Commit

Permalink
Merge pull request #78 from ezloteam/mdns_implementation
Browse files Browse the repository at this point in the history
Mdns implementation
  • Loading branch information
lomasSE89 authored Feb 28, 2024
2 parents 5bb9ff8 + f3833b0 commit 280278d
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ foreach(component ${external_components_list})
LIST(APPEND ALL_COMPONENTS ${SUBDIRS})
endforeach()

LIST(APPEND ALL_COMPONENTS ezlopi-user-config main)
LIST(APPEND ALL_COMPONENTS ezlopi-user-config ezlopi-main)

set(EXTRA_COMPONENT_DIRS ${ALL_COMPONENTS} ) # add the list of directories 'SUBDIRS' to 'EXTRA_COMPONENT_DIRS'(ESP32 VARIABLES), links the external components
message(STATUS "EXTRA_COMPONENTS_DIRS: ${EXTRA_COMPONENT_DIRS}\r\n")
Expand Down
6 changes: 3 additions & 3 deletions ezlopi-core/ezlopi-core-ble/ezlopi_core_ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static char* esp_auth_req_to_str(esp_ble_auth_req_t auth_req);
static char* ezlopi_ble_gap_event_to_str(esp_gap_ble_cb_event_t event);
// static void ezlopi_ble_setup_adv_config(void);

#if (1 == EZLOPI_BLE_ENALBE_PASSKEY)
#if (1 == CONFIG_EZLOPI_BLE_ENALBE_PASSKEY)
void ezlopi_ble_gap_set_passkey(uint32_t passkey)
{
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
Expand Down Expand Up @@ -218,7 +218,7 @@ void ezlopi_ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
break;
}

#if (1 == EZLOPI_BLE_ENALBE_PAIRING)
#if (1 == CONFIG_EZLOPI_BLE_ENALBE_PAIRING)
case ESP_GAP_BLE_PASSKEY_REQ_EVT: // 12
{
break;
Expand Down Expand Up @@ -304,7 +304,7 @@ void ezlopi_ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
ezlopi_ble_setup_adv_config();
break;
}
#if (1 == EZLOPI_BLE_ENALBE_PAIRING)
#if (1 == CONFIG_EZLOPI_BLE_ENALBE_PAIRING)
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT: // 22
{
ezlopi_ble_setup_adv_config();
Expand Down
2 changes: 1 addition & 1 deletion ezlopi-core/ezlopi-core-ble/ezlopi_core_ble_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void ezlopi_ble_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t ga
ezlopi_ble_gatt_call_write_exec_by_handle(gatts_if, param);
break;
}
#if (1 == EZLOPI_BLE_ENALBE_PAIRING)
#if (1 == CONFIG_EZLOPI_BLE_ENALBE_PAIRING)
case ESP_GATTS_CONNECT_EVT:
{
TRACE_S("ESP_GATTS_CONNECT_EVT");
Expand Down
4 changes: 4 additions & 0 deletions ezlopi-core/ezlopi-core-ezlopi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ set(EZLOPI_CORE_COMPONENTS
ezlopi-core-wifi
ezlopi-core-modes
ezlopi-core-sntp
ezlopi-core-ble
ezlopi-core-scenes
ezlopi-util-trace
ezlopi-core-mdns

)

set(EZLOPI_CLOUD_COMPONENTS
Expand Down
28 changes: 9 additions & 19 deletions ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
#include "ezlopi_core_devices_list.h"
#include "ezlopi_core_scenes_scripts.h"
#include "ezlopi_core_scenes_expressions.h"
#include "ezlopi_core_mdns.h"

#ifdef EZPI_CORE_ENABLE_ETH
#ifdef CONFIG_EZPI_CORE_ENABLE_ETH
#include "ezlopi_core_ethernet.h"
#endif // EZPI_CORE_ENABLE_ETH

// #include "ezlopi_service_uart.h"
// #include "ezlopi_service_timer.h"
// #include "ezlopi_service_webprov.h"
// #include "ezlopi_service_gpioisr.h"
// #include "ezlopi_service_ble.h"
// #include "ezlopi_service_meshbot.h"
// #include "ezlopi_service_modes.h"
#endif // CONFIG_EZPI_CORE_ENABLE_ETH

#include "ezlopi_hal_system_info.h"

Expand All @@ -35,10 +28,6 @@ static void ezlopi_initialize_devices_v3(void);
void ezlopi_init(void)
{

gpio_install_isr_service(0);

// EZPI_SERVICE_uart_init();
// gpio_isr_service_init();

// Init memories
ezlopi_nvs_init();
Expand All @@ -62,20 +51,21 @@ void ezlopi_init(void)
ezlopi_core_modes_init();
ezlopi_room_init();

// ezlopi_ble_service_init();

#ifdef EZPI_SERV_ENABLE_MESHBOTS
#ifdef CONFIG_EZPI_SERV_ENABLE_MESHBOTS
ezlopi_scenes_scripts_init();
ezlopi_scenes_expressions_init();
ezlopi_scenes_init_v2();
#endif // EZPI_SERV_ENABLE_MESHBOTS
#endif // CONFIG_EZPI_SERV_ENABLE_MESHBOTS

#ifdef EZPI_CORE_ENABLE_ETH
#ifdef CONFIG_EZPI_CORE_ENABLE_ETH
ezlopi_ethernet_init();
#endif // EZPI_CORE_ENABLE_ETH
#endif // CONFIG_EZPI_CORE_ENABLE_ETH

uint32_t boot_count = ezlopi_system_info_get_boot_count();

ezlopi_core_initialize_mdns();

ezlopi_wifi_connect_from_id_bin();
ezlopi_nvs_set_boot_count(boot_count + 1);

Expand Down
9 changes: 9 additions & 0 deletions ezlopi-core/ezlopi-core-mdns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


idf_component_register(SRCS "ezlopi_core_mdns.c"
INCLUDE_DIRS .
REQUIRES mdns
ezlopi-core-factory-info
ezlopi-util-trace)


110 changes: 110 additions & 0 deletions ezlopi-core/ezlopi-core-mdns/ezlopi_core_mdns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_netif_ip_addr.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "mdns.h"
#include "driver/gpio.h"
#include "netdb.h"

#include "ezlopi_core_factory_info.h"

#include "ezlopi_util_trace.h"

#include "ezlopi_core_mdns.h"


static char* generate_hostname(void);

static void initialise_mdns(void)
{
char* hostname = generate_hostname();

// initialize mDNS
ESP_ERROR_CHECK(mdns_init());
// set mDNS hostname (required if you want to advertise services)
ESP_ERROR_CHECK(mdns_hostname_set(hostname));
TRACE_D("mdns hostname set to: [%s]", hostname);
// set default mDNS instance name
ESP_ERROR_CHECK(mdns_instance_name_set(CONFIG_EZPI_MDNS_INSTANCE_NAME));

uint64_t id_val = ezlopi_factory_info_v3_get_id();
char* id_val_str = malloc(10 * sizeof(char));
memset(id_val_str, 0, (10 * sizeof(char)));
snprintf(id_val_str, 10, "%lld", id_val);

uint16_t firmware_version_val = ezlopi_factory_info_v3_get_version();
char* firmware_version_val_str = malloc(10 * sizeof(char));
memset(firmware_version_val_str, 0, 10 * sizeof(char));
snprintf(firmware_version_val_str, 10, "%d", firmware_version_val);

// Define mdns serive context
mdns_txt_item_t service_context_item[8] =
{
{
.key = "ID",
.value = id_val_str,
},
{
.key = "name",
.value = (NULL == ezlopi_factory_info_v3_get_name() ? "null" : ezlopi_factory_info_v3_get_name()),
},
{
.key = "manufacturer",
.value = (NULL == ezlopi_factory_info_v3_get_manufacturer() ? "null" : ezlopi_factory_info_v3_get_manufacturer()),
},
{
.key = "brand",
.value = (NULL == ezlopi_factory_info_v3_get_brand() ? "null" : ezlopi_factory_info_v3_get_brand())
},
{
.key = "Model",
.value = (NULL == ezlopi_factory_info_v3_get_model() ? "null" : ezlopi_factory_info_v3_get_model()),
},
{
.key = "ezlopi_device_type",
.value = (NULL == ezlopi_factory_info_v3_get_device_type() ? "null" : ezlopi_factory_info_v3_get_device_type()),
},
{
.key = "ezlopi_firmware_version",
.value = firmware_version_val_str,
},
{
.key = "ezlopi_firmware_build",
.value = "1.8.2",
},
};

ESP_ERROR_CHECK(mdns_service_add(CONFIG_EZPI_MDNS_INSTANCE_NAME, "_http", "_tcp", 80, service_context_item, 8));
free(hostname);
}

int ezlopi_core_initialize_mdns(void)
{
int ret = 0;
initialise_mdns();
return ret;
}

/** Generate host name based on sdkconfig, optionally adding a portion of MAC address to it.
* @return host name string allocated from the heap
*/
static char* generate_hostname(void)
{
#ifndef CONFIG_MDNS_ADD_MAC_TO_HOSTNAME
return strdup(CONFIG_EZPI_MDNS_INSTANCE_NAME);
#else
uint8_t mac[6];
char* hostname;
esp_read_mac(mac, ESP_MAC_WIFI_STA);
if (-1 == asprintf(&hostname, "%s-%02X%02X%02X", CONFIG_EZPI_MDNS_INSTANCE_NAME, mac[3], mac[4], mac[5]))
{
abort();
}
return hostname;
#endif
}
9 changes: 9 additions & 0 deletions ezlopi-core/ezlopi-core-mdns/ezlopi_core_mdns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#ifndef __EZLOPI_CORE_MDNS_H_
#define __EZLOPI_CORE_MDNS_H_

int ezlopi_core_initialize_mdns();

#endif // __EZLOPI_CORE_MDNS_H_


File renamed without changes.
49 changes: 49 additions & 0 deletions ezlopi-main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

menu "EzloPi User Config"

config EZPI_UTIL_ENABLE_TRACE
bool "Enable trace component for logging"
default y
help
ezlopi-util-trace component is enabled to log the outputs to the serial monitor

config EZPI_CORE_ENABLE_ETH
bool "Enable ethernet component"
depends on ETH_USE_SPI_ETHERNET
default n
help
ezlopi-core-ethernet component is enabled

config EZPI_SERV_ENABLE_MESHBOTS
bool "Enable meshbot service"
default y
help
Enable meshbot services for scenes

config EZLOPI_BLE_ENALBE_PASSKEY
bool "Enable BLE pass key"
default n
help
Enable BLE pass key

config EZLOPI_BLE_ENALBE_PAIRING
bool "Enable BLE pairing"
default y
help
Enable BLE pairing

config EZPI_MDNS_HOSTNAME
string "mDNS hostname"
default "ezlopi_device"
help
Set mDNS hostname

config EZPI_MDNS_INSTANCE_NAME
string "mDNS instance name"
default "ezlopi_serial"
help
Set mDNS instance name

endmenu


File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 280278d

Please sign in to comment.