ESP32_curl_example icon indicating copy to clipboard operation
ESP32_curl_example copied to clipboard

http get failed out of memory for small file get.

Open snahmad opened this issue 6 years ago • 5 comments

This is my code

static char Get_bigfile_testURL[] = "http://192.168.2.101:50153/alarm.json";
static uint8_t print_header = 0;
static uint8_t print_body = 0;
static int last_error = 0;
static int num_errors = 0;
std::string test_file = "simulate";

static void print_response(char *hd, char * bdy, int res) {
	if (res) {
		printf("     ERROR: %d [%s]\r\n", res, bdy);
	}
	else {
		if (print_header) {
			printf("\r\n____________ Response HEADER: ____________\r\n%s\r\n^^^^^^^^^^^^ Response HEADER: ^^^^^^^^^^^^\r\n", hd);
		}
		if (print_body) {
			printf("\r\n____________ Response BODY: ____________\r\n%s\r\n^^^^^^^^^^^^ Response BODY: ^^^^^^^^^^^^\r\n", bdy);
		}
		if ((!print_header) && (!print_body)) printf("     OK.");
	}
	last_error = res;
	if (res) num_errors++;
	else num_errors = 0;
}

static void testGET()
{
	int res = 0;
    char *hdrbuf = (char*)calloc(1024, 1);
    assert(hdrbuf);
    char *bodybuf = (char*)calloc(4096, 1);
    assert(bodybuf);


	printf("\r\n\r\n#### HTTP GET BIG FILE\r\n");

	curl_timeout = 90;
	curl_maxbytes = 3000000;
	res = ::Curl_GET(Get_bigfile_testURL, (char*)"/sdcard/alarm.json", hdrbuf, bodybuf, 1024, 4096);
	print_response(hdrbuf, bodybuf,res);

	
     free(bodybuf);
    free(hdrbuf);

    vTaskDelay(1000 / portTICK_RATE_MS);
}

HTTP GET BIG FILE

D (11059) Socket: >> setSSL: No V (11063) vfs_fat: vfs_fat_open: path="/alarm.json", flags=601, mode=1b6 D (11065) Socket: >> listen: port: 80, isDatagram: 0 V (11072) sdmmc_cmd: sending cmd slot=1 op=17 arg=4000 flags=1c50 data=0x3ffbe 13c blklen=512 datalen=512 timeout=1000 D (11077) Socket: >> createSocket: isDatagram: 0 V (11089) sdspi_host: sdspi_host_start_command: slot=1, CMD17, arg=0x00004000 flags=0x5, data=0x3ffbe13c, data_size=512 crc=0x47 D (11094) Socket: << createSocket: sockFd: 8196 D (11106) Socket: >> setReuseAddress: 1 V (11110) sdspi_transaction: r1 = 0x00 hw_cmd.r[0]=0x49002042 D (11114) Socket: << setReuseAddress V (11117) sdmmc_cmd: cmd response 00000000 00000000 00000000 00000000 err=0x0 state=0 D (11122) Socket: >> bind: port=80, address=0x0 curl_easy_perform failed: Out of memory D (11136) Socket: << bind V (11138) sdmmc_cmd: sending cmd slot=1 op=24 arg=4000 flags=1c10 data=0x3ffbe 13c blklen=512 datalen=512 timeout=5000 D (11143) Socket: << listen V (11150) sdspi_host: sdspi_host_start_command: slot=1, CMD24, arg=0x00004000 flags=0x7, data=0x3ffbe13c, data_size=512 crc=0x5a D (11153) HttpServerTask: Listening on port 80 D (11168) HttpServerTask: Waiting for new peer client V (11172) sdspi_transaction: r1 = 0x00 hw_cmd.r[0]=0xffffffff D (11178) Socket: >> accept: Accepting on 0.0.0.0 [80]; sockFd: 8196, using SS L: 0 V (11181) sdmmc_cmd: cmd response 00000000 00000000 00000000 00000000 err=0x0 state=0 ERROR: -7 [Out of memory] D (12197) Task: << runTask: taskName=Task I (12963) wifi: pm start, type:0

snahmad avatar May 14 '18 15:05 snahmad