This is the function i use to read the feedback from UART once i sent an AT command request,
Code: Select all
char* get_at_response(uart_port_t uart_num) {
char* result = NULL;
while (1) {
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
xEventGroupSetBits(gsm_event_group, GSM_0_DONE_BIT | GSM_1_DONE_BIT);//This works
int len = uart_read_bytes(uart_num, data, BUF_SIZE,
20 / portTICK_RATE_MS);
xEventGroupSetBits(gsm_event_group, GSM_0_DONE_BIT | GSM_1_DONE_BIT);//This does not work
char payloadChr[len];
if (len > 1) {
for (int i = 0; i < len; i++) {
char c = (char) data[i];
payloadChr[i] = c;
}
result = (char*) malloc(sizeof(payloadChr) + 1);
strncpy(result, payloadChr, sizeof(payloadChr) + 1);
}
break;
}
return result;
}
Code: Select all
void app_main() {
gsm_event_group = xEventGroupCreate();
xReturned = xTaskCreate(init_task, "init_task", 2048, GSM_0, 3, &xHandle);
EventBits_t uxBits;
while (1) {
ESP_LOGI(TAG, "WAITING...");
uxBits = xEventGroupWaitBits(gsm_event_group,
GSM_0_DONE_BIT | GSM_1_DONE_BIT, true, false, portMAX_DELAY);
if (uxBits & GSM_0_DONE_BIT) {
vTaskDelete(xHandle);
xReturned = xTaskCreate(init_task, "init_task", 2048, GSM_1, 3,
&xHandle);
}
if (uxBits & GSM_1_DONE_BIT) {
vTaskDelete(xHandle);
}
}
}