user1053507
user1053507

Reputation: 41

Esp32 execute AT command from User-defined AT Command

How can I execute other AT command from User-defined AT Command? For example

at_custom_cmd.c:

static uint8_t at_test_cmd_test(uint8_t *cmd_name)
{
    uint8_t buffer[64] = {0};
    snprintf((char *)buffer, 64, "test command: <AT%s=?> is executed\r\n", cmd_name);
    esp_at_port_write_data(buffer, strlen((char *)buffer));

    EXEC("AT+HTTPCGET="http://www.my.com");  // <-- How can I do it?

    return ESP_AT_RESULT_CODE_OK;
}

I tried to search exec command in offical site, but didn't find.

Upvotes: 1

Views: 93

Answers (2)

user1053507
user1053507

Reputation: 41

The current version does not allow implementing the example. I am providing the answer from the official forum.

Sorry that it’s an unsupported usage. because both at_test_cmd_test() and AT+HTTPCGET=params are executed in at_process_task(), however, in the current design, command processing is linear, and you cannot execute another command before one command is completed. in you case, you can create another task, and in your task, to execute some command like AT+HTTPCGET=. and at_test_cmd_test() to get the status of your task.

Upvotes: 0

hlovdal
hlovdal

Reputation: 28248

Looking in the https://github.com/espressif/esp-at/ repository there is an at_exe_cmd function in components/at/src/at_self_cmd.c however do not use it as is, its signature and code prevents handling errors. Instead use it as a template to writing your own exec function.

The fundamentally flawed property is the const char *expected_response argument. You absolutely cannot just wait for an "OK" response, you must be able to accept all possible final result codes. So using strstr is wrong, and the response lines needs to be properly parsed. I have covered this aspect in this answer for a similar scenario.

Also using a global variable like at_self_cmd_t *s_self_cmd is too spaghetti, you can do better than that.

Upvotes: 0

Related Questions