maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.1k stars 169 forks source link

Are there recommended settings? #74

Closed kosukekurimoto closed 5 years ago

kosukekurimoto commented 5 years ago

Currently I am advancing esp-homekit project to operate Nature Remo from Apple Homekit. https://github.com/kosukekurimoto/esp32-homekit-natureremo

There is a problem with this source that it is not possible to create a new socket several hours after startup.

TRANS_TCP: Error create socket
HTTP_CLIENT: Connection failed, sock < 0

The length of time this problem occurs depends on the LWIP setting.

make menuconfig -> Component config -> LWIP -> Max number of open sockets

Are there recommended settings?

maximkulkin commented 5 years ago

In all of my projects I'm OK with default value (10).

It makes sense to see what sock value (error code) we are looking at.

kosukekurimoto commented 5 years ago

I examined the procedure where an error occurred. https://github.com/kosukekurimoto/esp32-homekit-natureremo/blob/master/main/natureremo.c

esp_http_client_perform(client);

https://github.com/espressif/esp-idf/blob/master/components/esp_http_client/esp_http_client.c

if ((err = esp_http_client_connect(client)) != ESP_OK) {
    if (client->is_async && err == ESP_ERR_HTTP_CONNECTING) {
        return ESP_ERR_HTTP_EAGAIN;
    }
    return err;
}

https://github.com/espressif/esp-idf/blob/master/components/esp_http_client/esp_http_client.c

if (esp_transport_connect(client->transport, client->connection_info.host, client->connection_info.port, client->timeout_ms) < 0) {
    ESP_LOGE(TAG, "Connection failed, sock < 0");
    return ESP_ERR_HTTP_CONNECT;
}

https://github.com/espressif/esp-idf/blob/master/components/tcp_transport/transport_tcp.c

if (tcp->sock < 0) {
    ESP_LOGE(TAG, "Error create socket");
    return -1;
}
maximkulkin commented 5 years ago

Well, my idea was to check the sock value which in case of error will be an error code. That way you can make sure that it is the error you think it is (which is socket leak).

kosukekurimoto commented 5 years ago

Thank you very much. I appreciate the advice you gave me.