espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.48k stars 7.26k forks source link

MQTT does not work on WiFi if OpenThread DNS64 client is compiled in. (IDFGH-13030) #13976

Open Marttico opened 3 months ago

Marttico commented 3 months ago

Answers checklist.

General issue report

Summary:

When enabling CONFIG_OPENTHREAD_DNS64_CLIENT in sdkconfig, WiFi fails to connect to the MQTT broker. Disabling this option resolves the WiFi connection issue but causes the Thread connection to the MQTT broker to fail, likely due to the absence of DNS64 functionality.

Steps to Reproduce:

  1. Configure the project to enable CONFIG_OPENTHREAD_DNS64_CLIENT in sdkconfig.
  2. Attempt to establish an MQTT connection over WiFi.
  3. Observe that WiFi fails to connect to the MQTT broker.
  4. Disable CONFIG_OPENTHREAD_DNS64_CLIENT in sdkconfig.
  5. Attempt to establish an MQTT connection over WiFi again.
  6. Observe that WiFi successfully connects to the MQTT broker.
  7. Attempt to connect to the MQTT broker through Thread.
  8. Note the failure to connect, likely due to DNS64 being disabled.

Expected Behavior:

Both WiFi and Thread should be able to connect to the MQTT broker when CONFIG_OPENTHREAD_DNS64_CLIENT is enabled.

Actual Behavior:

Additional Observations:

System Information:

Suggested Fix:

Investigate the interaction between MQTT and DNS64 client settings to ensure compatibility across both WiFi and Thread connections.

zwx1995esp commented 3 months ago

Hi, @Marttico For the thread running on esp32C6, what device role of openthread? Is it an border router or just a normal thread router device? Could you please share the topology of your test env? That might be helpful to us to understand what happens. Thanks.

Marttico commented 3 months ago

Hey @zwx1995esp,

My setup in step 7 is specifically that my Thread device is a child. It's connected to an OpenThread border router hosted on a Raspberry Pi 4 connected to an nrf52840 as an RCP.

Do note that the issue I'm experiencing is specifically that an MQTT connection does not work while having compiled OpenThread DNS64 into my project but not initializing OpenThread. The way I'm expecting to connect to the MQTT broker is through a Wi-Fi connection, which usually works, but not when CONFIG_OPENTHREAD_DNS64_CLIENT is enabled in sdkconfig.

Connectivity through OpenThread seems to work fine with the CONFIG_OPENTHREAD_DNS64_CLIENT enabled in sdkconfig.

Thanks in advance for any help or suggestions you can offer!

zwx1995esp commented 2 months ago

Hi, @Marttico Sorry for the delay. So your project is running Thread and Wi-Fi together in one APP and you want both Thread and Wi-Fi can connect MQTT server at same time, right? Or you just want to run them separated and you want to run Wi-Fi or Thread MQTT client with the same configuration?

Marttico commented 1 week ago

Hi, @zwx1995esp I'd want them to work seperately. I currently have a project set up that I can switch between Thread and WiFi. To fix my issue I currently use a different library (mongoose) to connect to an MQTT server. I haven't tested whether my problem is resolved with an esp-idf, since I was out of office for the past two months. Before this, I found out that the DNS client seems broken for WiFi, when Thread is compiled in.

zwx1995esp commented 1 week ago

@Marttico Ok, for supporting OT device DNS feature, we add a hook to lwip_hook_netconn_external_resolve to send the resolve and get the result manually. When using wifi, this hook should not be processed. So you can define a global flag to distinguish when wifi or thread are active. Return 0 in the function lwip_hook_netconn_external_resolve when using wifi, and process this logic when using thread. Please have a try.

zwx1995esp commented 1 week ago

FYI: lwip_hook_netconn_external_resolve and CONFIG_OPENTHREAD_DNS64_CLIENT should be enabled.

Marttico commented 1 week ago

@zwx1995esp When replacing the logic in esp_openthread_dns64.c to just return 0, it seems to work with WiFi again! I haven't added any global flags yet though. This may be a little off topic for this issue, but would the best course of action currently just be to modify the OpenThread component and use a custom component for this?

int lwip_hook_netconn_external_resolve(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err)
{
    return 0;
}