For my ESP32 Project it serves as a server for a LIDAR simulation; meaning that it hosts a server that's open to HTTP requests that contain a param specifying a certain array of scan points it wants. HTTP request
to a server containing a database of Lidar Scan points and receives about 13000 bytes worth of scan-points stores as a JSON response from the serve; which it must then forward to the original client.
So far I have been trying to use the ESP library to processe the data and send it through but it keeps giving me errors and saying that there's no data in the response from the serve(which is incorrect as I have confirmed by manual curl responses from the command line). Is there a better way to acomplish this task ?
[Codebox]static esp_err_t root_get_handler(httpd_req_t *req)
{
static char buf[18000] = {0};
size_t buf_len = sizeof(buf);
char param_value[5];
int content_length = 0;
// Get the value of the 'param' query parameter
if (httpd_query_key_value(req->uri, "param", param_value, sizeof(param_value)) == ESP_OK) {
ESP_LOGI(TAG, "Received param value: %s", param_value);
// Create an HTTP client to send a request to the destination server
esp_http_client_config_t config = {
.url = "http://192.168.97.37:8080",
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_http_client_set_method(client, HTTP_METHOD_GET);
// Add the 'param' query parameter to the request
char dest_url[100];
snprintf(dest_url, sizeof(dest_url), "%s?param=%s", "http://192.168.97.37:8080", param_value);
esp_http_client_set_url(client, dest_url);
esp_err_t err = esp_http_client_perform(client);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
// Get the response from the destination server
} else {
content_length = esp_http_client_fetch_headers(client);
if (content_length < 0) {
ESP_LOGE(TAG, "HTTP client fetch headers failed");
}
else {
int data_read = esp_http_client_read_response(client, buf, MAX_HTTP_OUTPUT_BUFFER);
if (data_read >= 0) {
ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %"PRId64,
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
ESP_LOG_BUFFER_HEX(TAG, buf, data_read);
}
else {
ESP_LOGE(TAG, "Failed to read response");
}
}
}
// Cleanup
esp_http_client_cleanup(client);
}
else {
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Missing 'param' query parameter");
}
return ESP_OK;
}[/Codebox]
ESP-32: HTTP Data Fowarding
-
- Posts: 2
- Joined: Mon Jan 08, 2024 2:38 pm
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Baidu [Spider] and 86 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.