- ***ERROR*** A stack overflow in task httpd has been detected.
- abort() was called at PC 0x40087e4c on core 0
- 0x40087e4c: vApplicationStackOverflowHook at /home/niko/esp/esp-idf/components/esp32/panic.c:716
- ELF file SHA256: 440ac70c88f935f625f5a612dda1df6f7698a6ba9d730597e52b392de6b9b17e
- Backtrace: 0x40087be8:0x3ffc3ed0 0x40087e35:0x3ffc3ef0 0x40087e4c:0x3ffc3f10 0x4008c944:0x3ffc3f30 0x4008e3e8:0x3ffc3f50 0x4008e39e:0x4e45454b
- 0x40087be8: invoke_abort at /home/niko/esp/esp-idf/components/esp32/panic.c:716
- 0x40087e35: abort at /home/niko/esp/esp-idf/components/esp32/panic.c:716
- 0x40087e4c: vApplicationStackOverflowHook at /home/niko/esp/esp-idf/components/esp32/panic.c:716
- 0x4008c944: vTaskSwitchContext at /home/niko/esp/esp-idf/components/freertos/tasks.c:3538
- 0x4008e3e8: _frxt_dispatch at /home/niko/esp/esp-idf/components/freertos/portasm.S:406
- 0x4008e39e: _frxt_int_exit at /home/niko/esp/esp-idf/components/freertos/portasm.S:206
Can't send massive data from http server
Can't send massive data from http server
I want to send 5000 byte data as response for GET request. When I send small respond all goes right but once I increase sending data it crashes. How to fix it?
Re: Can't send massive data from http server
Sorry we are not psychic you have to post your code and crash/backtrace output.
Re: Can't send massive data from http server
The main task is to get 5000 kilobytes every 0.1 seconds from esp32. Is there better way to make it ?
- #include <esp_wifi.h>
- #include <esp_event_loop.h>
- #include <esp_log.h>
- #include <esp_system.h>
- #include <nvs_flash.h>
- #include <sys/param.h>
- #include <esp_http_server.h>
- #include <stdio.h>
- #include <string.h>
- #include "driver/gpio.h"
- #include "freertos/FreeRTOS.h"
- #define LED1 12
- static const char *TAG="APP";
- esp_err_t data_get_handler(httpd_req_t *req)
- {
- // example of big data
- char tmp_buff[10000] = "";
- for (int i = 0; i < 9000; i++) {
- tmp_buff[i] = 'a';
- }
- httpd_resp_send(req, tmp_buff, strlen(tmp_buff));
- if (httpd_req_get_hdr_value_len(req, "Host") == 0) {
- ESP_LOGI(TAG, "Request headers lost");
- }
- return ESP_OK;
- }
- httpd_uri_t data = {
- .uri = "/data",
- .method = HTTP_GET,
- .handler = data_get_handler,
- .user_ctx = "ESP32 data"
- };
- httpd_handle_t start_webserver(void)
- {
- httpd_handle_t server = NULL;
- httpd_config_t config = HTTPD_DEFAULT_CONFIG();
- ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
- if (httpd_start(&server, &config) == ESP_OK) {
- ESP_LOGI(TAG, "Registering URI handlers");
- httpd_register_uri_handler(server, &data);
- return server;
- }
- ESP_LOGI(TAG, "Error starting server!");
- return NULL;
- }
- void stop_webserver(httpd_handle_t server)
- {
- httpd_stop(server);
- }
- static esp_err_t event_handler(void *ctx, system_event_t *event)
- {
- httpd_handle_t *server = (httpd_handle_t *) ctx;
- switch(event->event_id) {
- case SYSTEM_EVENT_STA_START:
- ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
- ESP_ERROR_CHECK(esp_wifi_connect());
- break;
- case SYSTEM_EVENT_STA_GOT_IP:
- ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
- ESP_LOGI(TAG, "Got IP: '%s'", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
- if (*server == NULL) {
- *server = start_webserver();
- }
- break;
- case SYSTEM_EVENT_STA_DISCONNECTED:
- ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
- ESP_ERROR_CHECK(esp_wifi_connect());
- if (*server) {
- stop_webserver(*server);
- *server = NULL;
- }
- break;
- default:
- break;
- }
- return ESP_OK;
- }
- static void initialize_wifi(void *arg)
- {
- tcpip_adapter_init();
- ESP_ERROR_CHECK(esp_event_loop_init(event_handler, arg));
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK(esp_wifi_init(&cfg));
- ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
- wifi_config_t wifi_config = {
- .sta = {
- .ssid = "ZyXEL_KEENETIC_LITE_3EC257",
- .password = "zyxel-009-tqt",
- },
- };
- ESP_LOGI(TAG, "Setting WiFi configuration SSID %s PASSWORD %s", wifi_config.sta.ssid, wifi_config.sta.password);
- ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
- ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
- ESP_ERROR_CHECK(esp_wifi_start());
- }
- static void initialize_gpio(){
- gpio_pad_select_gpio(LED1);
- gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
- }
- void app_main()
- {
- static httpd_handle_t server = NULL;
- ESP_ERROR_CHECK(nvs_flash_init());
- initialize_gpio();
- initialize_wifi(&server);
- }
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Can't send massive data from http server
Line 22 allocates an 10K buffer on the stack. The default esp-http-server stack size is only 4K, so that leads to a stack overflow, as you've seen. The easy way would be to increase the webservers stack; you could e.g. add 'config.stack_size=20480' to line 47.
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 165 guests