Page 1 of 1

OTA Example

Posted: Thu Nov 09, 2017 1:29 pm
by Fugazi
Just wondering the best way to convert the OTA example to use a url instead of just an IP.

Any ideas, examples ?

Thanks

Re: OTA Example

Posted: Thu Nov 09, 2017 2:30 pm
by loboris

Code: Select all

static bool connect_to_http_server(const char *server, const char *port)
{
    const struct addrinfo hints = {
        .ai_family = AF_INET,
        .ai_socktype = SOCK_STREAM,
    };
    struct addrinfo *res;
    int  http_connect_flag = -1;

    int err = getaddrinfo(server, port, &hints, &res);
    if(err != 0 || res == NULL) {
        ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res);
        return false;
    }

    socket_id = socket(res->ai_family, res->ai_socktype, 0);
    if (socket_id < 0) {
        ESP_LOGE(TAG, "Create socket failed!");
        freeaddrinfo(res);
        return false;
    }

    // connect to http server
    http_connect_flag =  connect(socket_id, res->ai_addr, res->ai_addrlen);
    if (http_connect_flag != 0) {
        ESP_LOGE(TAG, "Connect to server failed! errno=%d", errno);
        close(socket_id);
        socket_id = -1;
        return false;
    }
    else return true;
}

Re: OTA Example

Posted: Thu Nov 09, 2017 3:37 pm
by Fugazi
Thanks :)