Page 1 of 1

ESP32 STA mode latency problems

Posted: Mon Nov 27, 2023 3:50 pm
by endi83
Hi,

I have made a program so that the ESP32 module connects in STA mode to form a wireless “lan cable”.

I see that the device that is connected to the module via Ethernet responds to the ping when the PC is connected to the same Wi-Fi network as said module. But although the connection is stable, the latency is very poor (900ms +-).

I have read that the latency improved considerably if the esp_wifi_set_ps (WIFI_PS_NONE) power saving mode was eliminated, but the result is still disastrous.

Any idea what could be happening?
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "sdkconfig.h"
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/task.h"
  6. #include "freertos/queue.h"
  7. #include "esp_event.h"
  8. #include "esp_log.h"
  9. #include "esp_eth_driver.h"
  10. #include "esp_wifi.h"
  11. #include "nvs_flash.h"
  12. #include "esp_private/wifi.h"
  13. #include "ethernet_init.h"
  14. #include "esp_netif_br_glue.h"
  15. #include "esp_eth.h"
  16. #include "esp_mac.h"
  17. #include "esp_system.h"
  18. #include "esp_netif.h"
  19. #include "lwip/ip4_addr.h"
  20. #include "lwip/netif.h"
  21. #include "freertos/event_groups.h"
  22. #include "lwip/err.h"
  23. #include "lwip/sys.h"
  24.  
  25. //
  26. #define STA_MODE 1
  27. //
  28. static const char *TAG = "eth2ap_example";
  29. static esp_eth_handle_t s_eth_handle[2] = {NULL};
  30. static QueueHandle_t flow_control_queue = NULL;
  31. static bool s_sta_is_connected = false;
  32. static bool s_ethernet_is_connected = false;
  33. #if STA_MODE
  34. static int s_retry_num = 0;
  35. /* FreeRTOS event group to signal when we are connected*/
  36. static EventGroupHandle_t s_wifi_event_group;
  37. /* The event group allows multiple bits for each event, but we only care about two events:
  38.  * - we are connected to the AP with an IP
  39.  * - we failed to connect after the maximum amount of retries */
  40. #define WIFI_CONNECTED_BIT BIT0
  41. #define WIFI_FAIL_BIT      BIT1
  42. #endif
  43.  
  44. #define FLOW_CONTROL_QUEUE_TIMEOUT_MS (100) //100
  45. #define FLOW_CONTROL_QUEUE_LENGTH (60) //60
  46. #define FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS (100) //100
  47. #if STA_MODE
  48. #define EXAMPLE_ESP_WIFI_SSID      "Serie500"
  49. #define EXAMPLE_ESP_WIFI_PASS      "BalanzaUniversal0"
  50. #define EXAMPLE_ESP_MAXIMUM_RETRY  5
  51.  
  52. #if STA_MODE
  53. #define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
  54. #define EXAMPLE_H2E_IDENTIFIER ""
  55. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
  56. #endif
  57.  
  58. #if CONFIG_ESP_WPA3_SAE_PWE_HUNT_AND_PECK
  59. #define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HUNT_AND_PECK
  60. #define EXAMPLE_H2E_IDENTIFIER ""
  61. #elif CONFIG_ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
  62. #define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HASH_TO_ELEMENT
  63. #define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
  64. #elif CONFIG_ESP_WPA3_SAE_PWE_BOTH
  65. #define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
  66. #define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
  67. #endif
  68. #if CONFIG_ESP_WIFI_AUTH_OPEN
  69. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
  70. #elif CONFIG_ESP_WIFI_AUTH_WEP
  71. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
  72. #elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
  73. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
  74. #elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
  75. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
  76. #elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
  77. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
  78. #elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
  79. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
  80. #elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
  81. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
  82. #elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
  83. #define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
  84. #endif
  85. #endif
  86.  
  87. typedef struct {
  88.     void *packet;
  89.     uint16_t length;
  90.     esp_eth_handle_t eth_handle;
  91. } flow_control_msg_t;
  92.  
  93. #if STA_MODE
  94. // Forward packets from Wi-Fi to Ethernet
  95. static esp_err_t tcpip_adapter_sta_input_eth_output(void *buffer, uint16_t len, void *eb)
  96. {
  97.     if (s_ethernet_is_connected) {
  98.         if (esp_eth_transmit(s_eth_handle[0], buffer, len) != ESP_OK) {
  99.             ESP_LOGE(TAG, "Ethernet send packet 1 failed");
  100.         }
  101.         else{
  102.             ESP_LOGI(TAG, "Envío paquete internamente wifi STA/ethernet OK");
  103.         }
  104.     }
  105.     esp_wifi_internal_free_rx_buffer(eb);
  106.  
  107.     return ESP_OK;
  108. }
  109. #endif
  110.  
  111. // Forward packets from Wi-Fi to Ethernet
  112. static esp_err_t tcpip_adapter_ap_input_eth_output(void *buffer, uint16_t len, void *eb)
  113. {
  114.     if (s_ethernet_is_connected) {
  115.     //if (s_eth_handle[0] == eth_handle){
  116.         if (esp_eth_transmit(s_eth_handle[0], buffer, len) != ESP_OK) {
  117.             ESP_LOGE(TAG, "Ethernet send packet 1 failed");
  118.         }else{
  119.             ESP_LOGI(TAG, "Envío paquete internamente wifi AP/ethernet OK");
  120.         }
  121.     } //else {
  122.         //if (esp_eth_transmit(s_eth_handle[1], buffer, len) != ESP_OK) {
  123.         //    ESP_LOGE(TAG, "Ethernet send packet 2 failedbbb");
  124.        // }
  125.     //}
  126.     esp_wifi_internal_free_rx_buffer(eb);
  127.     return ESP_OK;
  128. }
  129.  
  130. // Forward packets from Ethernet to Wi-Fi
  131. // Note that, Ethernet works faster than Wi-Fi on ESP32,
  132. // so we need to add an extra queue to balance their speed difference.
  133. static esp_err_t pkt_eth2wifi(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t len, void *priv)
  134. {
  135.     esp_err_t ret = ESP_OK;
  136.     flow_control_msg_t msg = {
  137.         .packet = buffer,
  138.         .length = len,
  139.         .eth_handle = eth_handle
  140.     };
  141.  
  142.     if (xQueueSend(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) != pdTRUE) {
  143.         ESP_LOGI(TAG, "Envio de mensaje Flow control fallido o timeout");
  144.         ESP_LOGE(TAG, "send flow control message failed or timeout");
  145.         free(buffer);
  146.         ret = ESP_FAIL;
  147.     }
  148.     else{
  149.         ESP_LOGI(TAG, "Envio de mensaje al flow control OK");        
  150.     }
  151.  
  152.     return ret;
  153. }
  154.  
  155.  
  156. // This task will fetch the packet from the queue, and then send out through Wi-Fi.
  157. // Wi-Fi handles packets slower than Ethernet, we might add some delay between each transmitting.
  158. static void eth2wifi_flow_control_task(void *args)
  159. {
  160.    flow_control_msg_t msg;
  161.     int res = 0;
  162.     uint32_t timeout = 0;
  163.  
  164.     while (1) {
  165.         if (xQueueReceive(flow_control_queue, &msg, pdMS_TO_TICKS(FLOW_CONTROL_QUEUE_TIMEOUT_MS)) == pdTRUE) {
  166.             timeout = 0;
  167.             if (s_sta_is_connected && msg.length) {
  168.                 do {
  169.                     vTaskDelay(pdMS_TO_TICKS(timeout));
  170.                     timeout += 2;
  171. #if STA_MODE
  172.                     res = esp_wifi_internal_tx(WIFI_IF_STA, msg.packet, msg.length);
  173. #else
  174.                     res = esp_wifi_internal_tx(WIFI_IF_AP, msg.packet, msg.length);
  175. #endif
  176.                 } while (res && timeout < FLOW_CONTROL_WIFI_SEND_TIMEOUT_MS);
  177.                 if (res != ESP_OK) {
  178.                     ESP_LOGE(TAG, "WiFi send packet failed: %d", res);
  179.                 }
  180.                 else{
  181.                     ESP_LOGI(TAG, "Envio de mensaje wifi OK");    
  182.                 }
  183.             }
  184.             free(msg.packet);
  185.         }
  186.     }
  187.     vTaskDelete(NULL);
  188. }
  189.  
  190. // Event handler for Ethernet
  191. static void eth_event_handler(void *arg, esp_event_base_t event_base,
  192.                               int32_t event_id, void *event_data)
  193. {
  194.     uint8_t mac_addr[6] = {0};
  195.     // Set your new MAC Address
  196.     uint8_t wifiMACAddress[6] = {0x00, 0x08, 0xEF, 0x00, 0x01, 0x37}; //MAC
  197.     /* we can get the ethernet driver handle from event data */
  198.     esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
  199.  
  200.     switch (event_id) {
  201.         case ETHERNET_EVENT_CONNECTED:
  202. //            if (eth_handle == s_eth_handle[0]){
  203.                 s_ethernet_is_connected = true;
  204.                 esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
  205. #if STA_MODE
  206.                 esp_wifi_set_mac(WIFI_IF_STA, wifiMACAddress);
  207.                 esp_wifi_set_ps (WIFI_PS_NONE);
  208. #else
  209.                 esp_wifi_set_mac(WIFI_IF_AP, mac_addr);
  210.                 esp_wifi_set_mac(WIFI_IF_STA, mac_addr);
  211. #endif
  212.                 //esp_wifi_connect();
  213.                 ESP_ERROR_CHECK(esp_wifi_start());
  214. //            }
  215.             ESP_LOGI(TAG, "Ethernet (%p) Link Up", eth_handle);
  216.             ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
  217.                     mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  218.             ESP_LOGI(TAG, "WIFI MAC Addr %02x:%02x:%02x:%02x:%02x:%02x",
  219.                     wifiMACAddress[0], wifiMACAddress[1], wifiMACAddress[2], wifiMACAddress[3], wifiMACAddress[4], wifiMACAddress[5]);
  220.             break;
  221. //
  222.         case ETHERNET_EVENT_DISCONNECTED:
  223. //          s_ethernet_is_connected = false;
  224. //          ESP_ERROR_CHECK(esp_wifi_stop());
  225.             ESP_LOGI(TAG, "Ethernet (%p) Link Down", eth_handle);
  226.             break;
  227. //
  228.         case ETHERNET_EVENT_START:
  229.             ESP_LOGI(TAG, "Ethernet (%p) Started", eth_handle);
  230.             break;
  231. //
  232.         case ETHERNET_EVENT_STOP:
  233.             ESP_LOGI(TAG, "Ethernet (%p) Stopped", eth_handle);
  234.             break;
  235. //
  236.         default:
  237.             break;
  238.     }
  239. }
  240.  
  241. // Event handler for Wi-Fi
  242. static void wifi_event_handler(void *arg, esp_event_base_t event_base,
  243.                                int32_t event_id, void *event_data)
  244. {
  245.     static uint8_t s_con_cnt = 0;
  246.     switch (event_id) {
  247.     case WIFI_EVENT_AP_STACONNECTED:
  248.         ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
  249.         if (!s_con_cnt) {
  250.             s_sta_is_connected = true;
  251.             esp_wifi_internal_reg_rxcb(WIFI_IF_AP, tcpip_adapter_ap_input_eth_output);
  252.         }
  253.         s_con_cnt++;
  254.         break;
  255.     case WIFI_EVENT_AP_STADISCONNECTED:
  256.         ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
  257.         s_con_cnt--;
  258.         if (!s_con_cnt) {
  259.             s_sta_is_connected = false;
  260.             esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL);
  261.         }
  262.         break;
  263. #if STA_MODE
  264.     case WIFI_EVENT_STA_START:
  265.         esp_wifi_connect();
  266.         break;
  267.     case WIFI_EVENT_STA_DISCONNECTED:
  268.         s_sta_is_connected = false;
  269.         esp_wifi_internal_reg_rxcb(WIFI_IF_STA, NULL);
  270.         if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
  271.             esp_wifi_connect();
  272.             s_retry_num++;
  273.             ESP_LOGI(TAG, "retry to connect to the AP");
  274.         }
  275.         //if (s_retry_num == EXAMPLE_ESP_MAXIMUM_RETRY)
  276.         //    esp_wifi_disconnect();
  277.         ESP_LOGI(TAG,"connect to the AP fail");
  278.         break;
  279.     case IP_EVENT_STA_GOT_IP:
  280.         ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
  281.         ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
  282.         s_retry_num = 0;
  283.         break;
  284.     case WIFI_EVENT_STA_CONNECTED:
  285.         s_retry_num = 0;
  286.         s_sta_is_connected = true;
  287.         esp_wifi_internal_reg_rxcb(WIFI_IF_STA, tcpip_adapter_sta_input_eth_output);
  288.         //esp_wifi_internal_reg_rxcb(WIFI_IF_STA, (wifi_rxcb_t)tcpip_adapter_sta_input_eth_output);
  289.         xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
  290.         break;
  291. #endif    
  292.     default:
  293.         break;
  294.     }
  295. }
  296.  
  297. static void initialize_ethernet(void)
  298. {
  299.     uint8_t eth_port_cnt = 0;
  300.     esp_eth_handle_t *eth_handles;
  301.     ESP_ERROR_CHECK(example_eth_init(&eth_handles, &eth_port_cnt));
  302.     for (uint8_t i = 0; i < eth_port_cnt; i++)
  303.     {
  304.         s_eth_handle[i] = eth_handles[i];
  305.         ESP_ERROR_CHECK(esp_eth_update_input_path(eth_handles[i], pkt_eth2wifi, NULL));
  306.         bool eth_promiscuous = true;
  307.         ESP_ERROR_CHECK(esp_eth_ioctl(eth_handles[i], ETH_CMD_S_PROMISCUOUS, &eth_promiscuous));
  308.         ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, NULL));
  309.         ESP_ERROR_CHECK(esp_eth_start(eth_handles[i]));
  310.     }
  311.     free(eth_handles);
  312. }
  313.  
  314. static void initialize_wifi(void)
  315. {
  316.     ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));
  317.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  318.     ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  319.     ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
  320.  
  321. #if STA_MODE
  322.     s_wifi_event_group = xEventGroupCreate();
  323.  
  324.     ESP_ERROR_CHECK(esp_netif_init());
  325.  
  326.     esp_netif_create_default_wifi_sta();
  327. #endif
  328.  
  329. #if STA_MODE  
  330.     esp_event_handler_instance_t instance_any_id;
  331.     esp_event_handler_instance_t instance_got_ip;
  332.     ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
  333.                                                         ESP_EVENT_ANY_ID,
  334.                                                         &wifi_event_handler,
  335.                                                         NULL,
  336.                                                         &instance_any_id));
  337.     ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
  338.                                                         IP_EVENT_STA_GOT_IP,
  339.                                                         &wifi_event_handler,
  340.                                                         NULL,
  341.                                                         &instance_got_ip));
  342. #endif
  343.  
  344. #if STA_MODE  
  345.     wifi_config_t wifi_config = {
  346.         .sta = {
  347.             .ssid = EXAMPLE_ESP_WIFI_SSID,
  348.             .password = EXAMPLE_ESP_WIFI_PASS,
  349.             /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (pasword len => 8).
  350.              * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
  351.              * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
  352.              * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
  353.              */
  354.             .channel = 1,
  355.             .threshold.authmode = WIFI_AUTH_WPA2_PSK,
  356.             .sae_pwe_h2e = ESP_WIFI_SAE_MODE,
  357.             .sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER,
  358.         },
  359.     };
  360.     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
  361.     esp_wifi_set_ps (WIFI_PS_NONE);
  362.     ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
  363.     ESP_ERROR_CHECK(esp_wifi_start() );
  364.  
  365.     ESP_LOGI(TAG, "wifi_init_sta finished.");
  366.  
  367.     /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
  368.      * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
  369.     EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
  370.            WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
  371.             pdFALSE,
  372.             pdFALSE,
  373.             portMAX_DELAY);
  374.  
  375.     /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
  376.      * happened. */
  377.     if (bits & WIFI_CONNECTED_BIT) {
  378.         ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
  379.                  EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
  380.     } else if (bits & WIFI_FAIL_BIT) {
  381.         ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
  382.                 EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
  383.     } else {
  384.         ESP_LOGE(TAG, "UNEXPECTED EVENT");
  385.     }
  386. #else
  387.     wifi_config_t wifi_config = {
  388.         .ap = {
  389.             .ssid = CONFIG_EXAMPLE_WIFI_SSID,
  390.             .ssid_len = strlen(CONFIG_EXAMPLE_WIFI_SSID),
  391.             .password = CONFIG_EXAMPLE_WIFI_PASSWORD,
  392.             .max_connection = CONFIG_EXAMPLE_MAX_STA_CONN,
  393.             .authmode = WIFI_AUTH_WPA_WPA2_PSK,
  394.             .channel = CONFIG_EXAMPLE_WIFI_CHANNEL // default: channel 1
  395.         },
  396.     };
  397.     if (strlen(CONFIG_EXAMPLE_WIFI_PASSWORD) == 0) {
  398.         wifi_config.ap.authmode = WIFI_AUTH_OPEN;
  399.     }
  400.     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
  401.     ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
  402. #endif
  403. }
  404.  
  405. static esp_err_t initialize_flow_control(void)
  406. {
  407.     flow_control_queue = xQueueCreate(FLOW_CONTROL_QUEUE_LENGTH, sizeof(flow_control_msg_t));
  408.     if (!flow_control_queue) {
  409.         ESP_LOGE(TAG, "create flow control queue failed");
  410.         return ESP_FAIL;
  411.     }
  412.     BaseType_t ret = xTaskCreate(eth2wifi_flow_control_task, "flow_ctl", 2048, NULL, (tskIDLE_PRIORITY + 2), NULL);
  413.     if (ret != pdTRUE) {
  414.         ESP_LOGE(TAG, "create flow control task failed");
  415.         return ESP_FAIL;
  416.     }
  417.  
  418.     ESP_LOGI(TAG, "Flow control bien");
  419.     return ESP_OK;
  420. }
  421.  
  422. void app_main(void)
  423. {
  424.     esp_err_t ret = nvs_flash_init();
  425.     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  426.         ESP_ERROR_CHECK(nvs_flash_erase());
  427.         ret = nvs_flash_init();
  428.     }
  429.     ESP_ERROR_CHECK(ret);
  430.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  431.     ESP_ERROR_CHECK(initialize_flow_control());
  432.  
  433.     initialize_wifi();
  434.     initialize_ethernet();
  435. }

Re: ESP32 STA mode latency problems

Posted: Tue Nov 28, 2023 3:02 pm
by endi83
I could see that the problem was in the ethernet speed. In the device I had it at 10 Mbps and in ESP32 at 100 Mbps. I've been looking for a parameter in sdkconfig to change the ethernet speed. I haven't found it, does it exist?
Is there any function to change the value by software?

Re: ESP32 STA mode latency problems

Posted: Thu Aug 01, 2024 7:49 am
by nayuta666
Hello, can you send me your example code in the above? I copied your code, but it didn't print got ip:.... And the computer can not ping esp32 successfully, I want to connect the MCU and esp32 through the network cable. esp32 is connected to wifi as STA, and the computer is also connected to wifi, and the MCU communicates with the mqtt server on the computer. But my computer can't connect to esp32