Code: Select all
dependencies:
espressif/mdns: ^1.8.2So, The error is that mdns will stop working randomly after a long period (hours or sometimes days). Enabling logging and adding a raw socket to look for incoming udp, I have verified
1)the mdns requests to come int
2)the mdns library recognizes the request
3)the mdns library calls
Code: Select all
_mdns_udp_pcb_write(p->tcpip_if, p->ip_protocol, &p->dst, p->port, packet, index);4)no packet recieved by other devices on the network (verified by wireshark seeing the outgoing question packets but not receiving the esp's answer packets despite the logging saying packets were sent)
5)this is inconsistent (sometimes works fine days where 'TX' means packet gets out) and on some router fails immediately
6)TCP packets still send (so at least it is not a full lwip failure as httpd still works by using ip address instead of the .local)
for reference, here is the mdns init/reinit code
Code: Select all
#define TAG "MDNS"
static int mdns_state=0;
void stop_mdns(void){
if(mdns_state==0)return;
mdns_free();
mdns_state=0;
}
//just help with logging
#define WK_ERROR_CHECK(x) do { \
esp_err_t err_rc_ = (x); \
if (unlikely(err_rc_ != ESP_OK)) { \
ESP_LOGE("WK", "%d, %s, %d,%s ,%s", (int)err_rc_, __FILE__, (int)__LINE__, \
__func__, #x); \
} \
} while(0)
//from example, small tweaks (just note that hostname is const truely, not stack bound though I don't think it should matter)
void initialise_mdns(const char * hostname)
{
if(mdns_state==1)return;//prevent double init
// initialize mDNS
WK_ERROR_CHECK(mdns_init());
mdns_state=1;
// set mDNS hostname (required if you want to advertise services)
WK_ERROR_CHECK(mdns_hostname_set(hostname));
ESP_LOGI(TAG, "mdns hostname set to: [%s]", hostname);
// set default mDNS instance name
WK_ERROR_CHECK(mdns_instance_name_set(hostname));
// structure with TXT records
//next escalation
//mdns_register_netif(x);
// initialize service
WK_ERROR_CHECK(mdns_service_add(hostname, "_http", "_tcp", 80,NULL,0)); // serviceTxtData, 2));
WK_ERROR_CHECK(mdns_service_subtype_add_for_host(hostname, "_http", "_tcp", NULL, "_server"));
// #if CONFIG_MDNS_MULTIPLE_INSTANCE
// WK_ERROR_CHECK(mdns_service_add("ESP32-WebServer1", "_http", "_tcp", 80, NULL, 0));
// #endif
// add another TXT item
//WK_ERROR_CHECK(mdns_service_txt_item_set("_http", "_tcp", "path", "/"));
// change TXT item value
// WK_ERROR_CHECK(mdns_service_txt_item_set_with_explicit_value_len("_http", "_tcp", "u", "admin", strlen("admin")));
mdns_state=1;
}
//reinit on new IP prevents long wait times when connecting new network
void lazy_restart_mdns(const char* hostname){
if(mdns_state){stop_mdns();vTaskDelay(100/portTICK_PERIOD_MS);}
initialise_mdns(hostname);
}