static esp_err_t https_telegram_sendPicture_perform_post()
{
ESP_LOGI(TAG3, "Starting Taking Picture!");
camera_fb_t *pic = esp_camera_fb_get();
if (!pic)
{
ESP_LOGE(TAG3, "Camera capture failed");
return ESP_FAIL;
}
else
{
ESP_LOGI(TAG3, "pic->len=%d", pic->len);
}
char url[512] = "";
char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request
// char output_buffer[1024*10] = {0}; // Buffer to store response of http request
esp_http_client_config_t config =
{
.url = "https://api.telegram.org",
.transport_type = HTTP_TRANSPORT_OVER_SSL,
.event_handler = _http_event_handler,
.cert_pem = telegram_certificate_pem_start,
.user_data = output_buffer,
};
//POST
ESP_LOGW(TAG3, "Iniciare");
esp_http_client_handle_t client = esp_http_client_init(&config)
//Copy the url+TOKEN
strcat(url, url_string);
//Passing the method
strcat(url, "/sendPhoto");
esp_http_client_set_url(client, url);
ESP_LOGW(TAG3, "Enviare POST");
char post_data[1024*10] = "";
sprintf(post_data,"{\"chat_id\":%s,\"photo\":%s}", chat_ID2, (const char *) pic->buf);
esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_header(client, "Content-Type", "image/jpeg");
esp_http_client_set_post_field(client, (const char*) post_data, strlen(post_data));
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK)
{
ESP_LOGI(TAG3, "HTTP POST Status = %ld, content_length = %ld",
(long)esp_http_client_get_status_code(client),
(long)esp_http_client_get_content_length(client));
ESP_LOGW(TAG3, "Desde Perform el output es: %s",output_buffer);
}
else
{
ESP_LOGE(TAG3, "HTTP POST request failed: %s", esp_err_to_name(err));
}
ESP_LOGW(TAG, "Limpiare");
esp_http_client_close(client);
esp_http_client_cleanup(client);
ESP_LOGI(TAG3, "esp_get_free_heap_size: %lu", esp_get_free_heap_size ());
esp_camera_fb_return(pic);
return ESP_OK;
}