ESP_YJM wrote: ↑Fri Dec 23, 2022 3:47 am
Could you please enable DNS_DEBUG and TCP_DEBUG in lwip to check. Or could you please capture the air packet to see the DNS flow and TCP flow.
Code: Select all
static esp_err_t esp_tcp_connect(const char *host, int hostlen, int port, int *sockfd, const esp_tls_t *tls, const esp_tls_cfg_t *cfg)
{
esp_err_t ret;
struct addrinfo *addrinfo;
if ((ret = resolve_host_name(host, hostlen, &addrinfo)) != ESP_OK) {
return ret;
}
int fd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol);
if (fd < 0) {
ESP_LOGE(TAG, "Failed to create socket (family %d socktype %d protocol %d)", addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol);
ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_SYSTEM, errno);
ret = ESP_ERR_ESP_TLS_CANNOT_CREATE_SOCKET;
goto err_freeaddr;
}
void *addr_ptr;
if (addrinfo->ai_family == AF_INET) {
ESP_LOGW(TAG, "addrinfo->ai_family == AF_INET");
struct sockaddr_in *p = (struct sockaddr_in *)addrinfo->ai_addr;
p->sin_port = htons(port);
addr_ptr = p;
}
#if CONFIG_LWIP_IPV6
else if (addrinfo->ai_family == AF_INET6) {
ESP_LOGW(TAG, "addrinfo->ai_family == AF_INET6");
struct sockaddr_in6 *p = (struct sockaddr_in6 *)addrinfo->ai_addr;
p->sin6_port = htons(port);
p->sin6_family = AF_INET6;
ESP_LOGW(TAG, "p->sin6_port %d, p->sin6_family %d", p->sin6_port, p->sin6_family);
addr_ptr = p;
}
#endif
else {
ESP_LOGE(TAG, "Unsupported protocol family %d", addrinfo->ai_family);
ret = ESP_ERR_ESP_TLS_UNSUPPORTED_PROTOCOL_FAMILY;
goto err_freesocket;
}
if (cfg) {
if (cfg->timeout_ms >= 0) {
struct timeval tv;
ms_to_timeval(cfg->timeout_ms, &tv);
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
if (cfg->keep_alive_cfg && cfg->keep_alive_cfg->keep_alive_enable) {
if (esp_tls_tcp_enable_keep_alive(fd, cfg->keep_alive_cfg) < 0) {
ESP_LOGE(TAG, "Error setting keep-alive");
goto err_freesocket;
}
}
}
if (cfg->non_block) {
int flags = fcntl(fd, F_GETFL, 0);
ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
if (ret < 0) {
ESP_LOGE(TAG, "Failed to configure the socket as non-blocking (errno %d)", errno);
goto err_freesocket;
}
}
}
ESP_LOGW(TAG, "[%s]fd %d addrinfo->ai_addrlen %d", __func__, fd, addrinfo->ai_addrlen);
ret = connect(fd, addr_ptr, addrinfo->ai_addrlen);
if (ret < 0 && !(errno == EINPROGRESS && cfg && cfg->non_block)) {
ESP_LOGE(TAG, "[%s]Failed to connnect to host (errno %d) (ret %d)", __func__, errno, ret);
ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_SYSTEM, errno);
ret = ESP_ERR_ESP_TLS_FAILED_CONNECT_TO_HOST;
goto err_freesocket;
}
*sockfd = fd;
freeaddrinfo(addrinfo);
return ESP_OK;
err_freesocket:
close(fd);
err_freeaddr:
freeaddrinfo(addrinfo);
return ret;
}
I setting like this(show attach file)
and my error log is this
I (59411) BF_WIFI*: esp_netif_create_default_wifi_sta
I (59421) BF_WIFI*: wifi_init_config_t
I (59421) BF_WIFI*: esp_wifi_init
I (59441) wifi:wifi driver task: 3ffe3580, prio:23, stack:6656, core=0
I (59441) wifi:wifi firmware version: eb52264
I (59451) wifi:wifi certification version: v7.0
I (59451) wifi:config NVS flash: enabled
I (59451) wifi:config nano formating: disabled
I (59451) wifi:Init data frame dynamic rx buffer num: 32
I (59461) wifi:Init management frame dynamic rx buffer num: 32
I (59461) wifi:Init management short buffer num: 32
I (59471) wifi:Init static tx buffer num: 16
I (59471) wifi:Init tx cache buffer num: 32
I (59471) wifi:Init static rx buffer size: 1600
I (59481) wifi:Init static rx buffer num: 10
I (59481) wifi:Init dynamic rx buffer num: 32
I (59491) wifi_init: rx ba win: 16
I (59491) wifi_init: tcpip mbox: 32
I (59491) wifi_init: udp mbox: 6
I (59501) wifi_init: tcp mbox: 6
I (59501) wifi_init: tcp tx win: 5744
I (59511) wifi_init: tcp rx win: 5744
I (59511) wifi_init: tcp mss: 1436
I (59511) wifi_init: WiFi/LWIP prefer SPIRAM
I (59521) BF_WIFI*: esp_wifi_set_mode result: 0
I (59551) BF_WIFI*: esp_wifi_set_config result: 0
I (59551) wifi:mode : sta (c4:dd:57:6a:a0:0c)
I (59551) wifi:enable tsf
I (59551) BF_WIFI*: esp_wifi_start result: 0
I (59551) BF_WIFI*: Start wifi connect
I (59571) wifi
<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (59581) wifi:state: init -> auth (b0)
I (59591) wifi:state: auth -> assoc (0)
I (59601) wifi:state: assoc -> run (10)
I (59921) wifi:connected with LuisIphone, aid = 1, channel 6, BW20, bssid = 0a:3d:e5:52:3c:89
I (59921) wifi:security: WPA2-PSK, phy: bgn, rssi: -44
I (59941) wifi:pm start, type: 1
I (60011) wifi:AP's beacon interval = 102400 us, DTIM period = 1
W (60011) wifi:<ba-add>idx:0 (ifx:0, 0a:3d:e5:52:3c:89), tid:0, ssn:2, winSize:64
I (60961) esp_netif_handlers: sta ip: 172.20.10.2, mask: 255.255.255.240, gw: 172.20.10.1
I (60961) BF_WIFI*: got ip:172.20.10.2
I (60961) BF_WIFI*: WI-FI connect bit result: 0x1
I (60971) BF_WIFI*: connected to ap SSID:LuisIphone password:11112222
I (61171) APP_MAIN: WIFI_Total_SendJson
I (61171) APP_MAIN: [WIFI_Total_Http_Send]WIFI_Total_client isn't NULL
I (61171) APP_MAIN: [WIFI_Total_Http_Send]esp_http_client_set_method error code: 0
I (61171) APP_MAIN: [WIFI_Total_Http_Send]esp_http_client_set_header Content-Type error code: 0
W (61181) HTTP_CLIENT: Begin connect to:
https://log.bodyfriend.co.kr:443
W (61191) HTTP_CLIENT: Show again.Begin connect to:
https://log.bodyfriend.co.kr:443, timeout: 2147483647
W (61201) TRANSPORT: client->transport->_connect is found
W (61211) esp-tls: host:log.bodyfriend.co.kr: strlen 20
W (61211) esp-tls: addrinfo->ai_family == AF_INET
W (61221) esp-tls: [esp_tcp_connect]fd 54 addrinfo->ai_addrlen 28
E (70481) esp-tls: [esp_tcp_connect]Failed to connnect to host (errno 113) (ret -1)
E (70481) esp-tls: [esp_tls_low_level_conn] Fail esp_tcp_connect
E (70481) esp-tls: Failed to open new connection
E (70491) TRANS_SSL: Failed to open a new connection
E (70491) HTTP_CLIENT: Connection failed, sock < 0
E (70501) APP_MAIN: Failed to open HTTP connection: ESP_ERR_HTTP_CONNECT
I (70501) BF_WIFI*: bf_wifi_connect.c
-http_event_handler():
-HTTP_EVENT_DISCONNECTED:
I (70511) BF_WIFI*: Last esp error code: 0x8004
I (70521) BF_WIFI*: Last mbedtls failure: 0x0
I (70521) APP_MAIN: [WIFI_Total_Http_Send]esp_http_client_cleanup error code: 0
I (70531) APP_MAIN: Fail to send testdata
I (70541) APP_MAIN: [BleWifiConnTask]Fail to send json
I (70561) APP_MAIN: [WIFI_Total_Stop]Disconnect esp_wifi
I (70561) wifi:state: run -> init (0)
I (70561) wifi:pm stop, total sleep time: 7699794 us / 10621401 us