Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mDNS support for AP interface #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion arduino/libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#include <lwip/inet_chksum.h>

#include "WiFi.h"
#include "mdns.h"

// defines required from mdns service
#define LWIP_MDNS_RESPONDER 1
#define LWIP_IGM 1
#define LWIP_IPV4 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems really strange we need these defines to be manually added ... are you sure we need them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed!! added on the kconfig


WiFiClass::WiFiClass() :
_initialized(false),
Expand Down Expand Up @@ -697,6 +703,15 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
case SYSTEM_EVENT_AP_START: {
struct netif* apNetif;

mdns_init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this mdns_init is needed? I believe without it macOS was fine in STA mode, should we also port to STA mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described by the example seems yes, its recommend by the example, i had test adding in the properly interface like how we do in STA but not works i had found an issue on the epressif repo.
This is why i suppose to test the mdns and from the result was that works for the access point.
We can try to move on other direction implement in STA mode and removing the interface management if a plus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i understand when the AP interface is used we should enable a dns local instance because we don't have a reference DNS Server like the STA (i'm testing it).
Now i'm try to correctly configure the local dns and ad the feature AS_DYNAMIC in order to be able to manage the lookup table and the new rules if this works we could leave the idea of implement the mdns.


if (strlen(_hostname) == 0) {
uint8_t mac[6];
esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
sprintf(_hostname, "arduino-%.2x%.2x", mac[4], mac[5]);
}
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, _hostname);

if (tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_AP, (void**)&apNetif) == ESP_OK) {
if (apNetif->input != WiFiClass::apNetifInputHandler) {
_apNetifInput = apNetif->input;
Expand All @@ -705,6 +720,8 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
}
}

mdns_hostname_set(_hostname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between mdns_hostname_set and tcpip_adapter_set_hostname?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mdns_hostname_set set the name on the mdns onject the other goes to set the hostname on the lwip tcpip interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the second is useless while mdns is enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in STA mode mdns not works


wifi_config_t config;

esp_wifi_get_config(ESP_IF_WIFI_AP, &config);
Expand All @@ -722,7 +739,6 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
} else {
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &_ipInfo);
}

_status = WL_AP_LISTENING;
xEventGroupSetBits(_eventGroup, BIT1);
break;
Expand All @@ -733,6 +749,7 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
memset(&_apRecord, 0x00, sizeof(_apRecord));
memset(&_ipInfo, 0x00, sizeof(_ipInfo));
xEventGroupClearBits(_eventGroup, BIT1);
mdns_free();
break;

case SYSTEM_EVENT_AP_STACONNECTED:
Expand Down
20 changes: 19 additions & 1 deletion sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ CONFIG_EFUSE_MAX_BLK_LEN=192
# ESP32-specific
#
CONFIG_IDF_TARGET_ESP32=y
CONFIG_ESP32_REV_MIN_0=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which IDF are you using? If it's an IDF update, it should be an independent commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all the default values?

Copy link
Contributor Author

@Rocketct Rocketct Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes is the one we suggest on the install on the read me, maybe i enable unvolontarly i'm work to remove it

CONFIG_ESP32_REV_MIN_1=
CONFIG_ESP32_REV_MIN_2=
CONFIG_ESP32_REV_MIN_3=
CONFIG_ESP32_REV_MIN=0
CONFIG_ESP32_DPORT_WORKAROUND=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_80=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=
Expand Down Expand Up @@ -339,6 +345,8 @@ CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
CONFIG_HTTPD_MAX_REQ_HDR_LEN=512
CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
CONFIG_HTTPD_LOG_PURGE_DATA=

#
# ESP HTTPS OTA
Expand Down Expand Up @@ -443,6 +451,8 @@ CONFIG_FREERTOS_USE_TRACE_FACILITY=
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=
CONFIG_FREERTOS_DEBUG_INTERNALS=
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=
CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE=

#
# Heap memory debugging
Expand Down Expand Up @@ -624,7 +634,7 @@ CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
#
# mDNS
#
CONFIG_MDNS_MAX_SERVICES=10
CONFIG_MDNS_MAX_SERVICES=11

#
# ESP-MQTT Configurations
Expand Down Expand Up @@ -666,6 +676,9 @@ CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread"
CONFIG_SPI_FLASH_VERIFY_WRITE=
CONFIG_SPI_FLASH_ENABLE_COUNTERS=
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y
CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS=
CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED=
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1
Expand Down Expand Up @@ -728,3 +741,8 @@ CONFIG_SUPPORT_TERMIOS=y
CONFIG_WL_SECTOR_SIZE_512=
CONFIG_WL_SECTOR_SIZE_4096=y
CONFIG_WL_SECTOR_SIZE=4096

#
# Wi-Fi Provisioning Manager
#
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16