User defined AT Command makes the module rest

my_abousamra
Posts: 8
Joined: Mon Feb 06, 2017 9:54 am

User defined AT Command makes the module rest

Postby my_abousamra » Tue Feb 14, 2017 2:34 pm

I'm implementing a user defined AT command but it makes the module reset

In at_task.c

Code: Select all


static uint8_t at_exeCmdTest(uint8_t para_num)
{
	 int32_t cnt = 0;
	 uint8_t *str;
	 uint8_t *str2;

	if (para_num != 1) {
		return ESP_AT_RESULT_CODE_ERROR;
	}

	 str = (uint8_t *)malloc(32);
	 if (!str) {
		return ESP_AT_RESULT_CODE_ERROR;
	 }

	 str2 = (uint8_t *)malloc(10);
	 if (!str2) {
		free (str);
		return ESP_AT_RESULT_CODE_ERROR;
	 }

	if (esp_at_get_para_as_str (cnt++,&str2) != ESP_AT_PARA_PARSE_RESULT_OK) {
		free(str);
		free(str2);
		return ESP_AT_RESULT_CODE_ERROR;
	}

	sprintf((char*)str, "You've entered \"%s\"\r\n", str2);
	esp_at_port_write_data((uint8_t *)str, strlen( (char*)str));
	
	free(str);
	free(str2);

	esp_at_response_result(ESP_AT_RESULT_CODE_OK);

	return ESP_AT_RESULT_CODE_PROCESS_DONE;
}


static esp_at_cmd_struct at_custom_cmd[] = {
    {"+UART", NULL, NULL, at_setupCmdUart, NULL},
    {"+UART_CUR", NULL, NULL, at_setupCmdUart, NULL},
    {"+UART_DEF", NULL, NULL, at_setupCmdUartDef, NULL},
    {"+CIUPDATE", NULL, NULL, NULL, at_exeCmdCipupdate},
	{"+CITEST", NULL, NULL, at_exeCmdTest, NULL},
};
When I test it

Code: Select all

at+citest="123"<\r><\n>
You've entered "123"<\r><\n>
<\r><\n>
ready<\r><\n>
Why that happens? when I wrote other user defined AT commands with integer parameters or no parameters, this problem doesn't occur

epooch
Posts: 2
Joined: Wed Feb 28, 2018 11:20 pm

Re: User defined AT Command makes the module rest

Postby epooch » Sun Mar 04, 2018 8:19 pm

Yet appears that you may be freeing esp_at lib's internal parameter buffer when you do:

Code: Select all

free(str2);
after:

Code: Select all

if (esp_at_get_para_as_str (cnt++,&str2) != ESP_AT_PARA_PARSE_RESULT_OK) {
Just get rid of all the malloc and free'ing for your str2. You could probably make some minor changes to not use sprintf, and get rid of all of the malloc() and free() calls in your example.

Who is online

Users browsing this forum: Google [Bot] and 17 guests