OTA Example

Fugazi
Posts: 40
Joined: Wed Apr 26, 2017 9:05 pm

OTA Example

Postby Fugazi » Thu Nov 09, 2017 1:29 pm

Just wondering the best way to convert the OTA example to use a url instead of just an IP.

Any ideas, examples ?

Thanks

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: OTA Example

Postby loboris » Thu Nov 09, 2017 2:30 pm

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;
}

Fugazi
Posts: 40
Joined: Wed Apr 26, 2017 9:05 pm

Re: OTA Example

Postby Fugazi » Thu Nov 09, 2017 3:37 pm

Thanks :)

Who is online

Users browsing this forum: MSN [Bot] and 21 guests