Hi,
I'm working on a ESP32 esp-idf project that integrates with a SIM7600 modem. I need to be able to send and receive SMS text messages and I have setup CMUX based on examples. However, there is one concept I have not been able to figure out--how can I get notified of late AT command responses, e.g. followup response to sending SMS text. The modem takes time to respond or I want to know when a SMS text is received.
I've searched far and wide for the right terminology but think it's related to URC, but have not found anything clear and helpful. I've read through esp protocol github issues and now believe that "URC" is what I need but I can't find any documentation.
Questions:
- is there a way to receive asynchronous notification (e.g. via callback) for any or specific unsolicited, i.e. async, events from AT commands?
- Is URC the answer and if so how can I use them--where's the documentation for URC use?
Thank you for your help in advance.
esp_modem: unsolicited response, URC
Re: esp_modem: unsolicited response, URC
A bit late but today I was wondering the same. It looks like it is possible but not trivial, it involves creating a custom DCE, here is a patch that incorporates it to the console example: https://github.com/espressif/esp-protoc ... 660991194c
Re: esp_modem: unsolicited response, URC
A possible solution could be to setup a self managed uart port
As long as you don't use the DATA mode, it is possible to add a second serial port (UART_NUM_2) to the same pins, and only use them for reading AT response data and URCs.
Example code
[Codebox]
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#define UART_TX_PIN GPIO_NUM_27
#define UART_RX_PIN GPIO_NUM_26
#define BUF_SIZE (1024)
static const char *TAG = "UART_TEST";
void uart_init() {
uart_config_t uart_config = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
// Configure UART parameters
uart_param_config(UART_NUM_2, &uart_config);
// Set UART pins (TX: GPIO_NUM_27, RX: GPIO_NUM_26)
uart_set_pin(UART_NUM_2, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// Install UART driver using an event queue
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
}
void uart_task(void *pvParameters) {
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
while (1) {
// Read data from UART
int len = uart_read_bytes(UART_NUM_2, data, BUF_SIZE, 1000 / portTICK_PERIOD_MS);
if (len > 0) {
data[len] = '\0';
ESP_LOGI(TAG, "Received: %s", data);
} else {
ESP_LOGI(TAG, "No data...");
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
free(data);
}
void test_uart() {
// Initialize UART
ESP_LOGI(TAG, "Reading modem serial data...");
uart_init();
ESP_LOGI(TAG, "Creating uart task...");
// Create UART task
xTaskCreate(uart_task, "uart_task", 2048, NULL, 10, NULL);
}
[/Codebox]
The uart_task will let you parse the received serial data. Allowing to filter out URC messages (starting with only +) and trigger a necessary action.
As long as you don't use the DATA mode, it is possible to add a second serial port (UART_NUM_2) to the same pins, and only use them for reading AT response data and URCs.
Example code
[Codebox]
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#define UART_TX_PIN GPIO_NUM_27
#define UART_RX_PIN GPIO_NUM_26
#define BUF_SIZE (1024)
static const char *TAG = "UART_TEST";
void uart_init() {
uart_config_t uart_config = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
// Configure UART parameters
uart_param_config(UART_NUM_2, &uart_config);
// Set UART pins (TX: GPIO_NUM_27, RX: GPIO_NUM_26)
uart_set_pin(UART_NUM_2, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
// Install UART driver using an event queue
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
}
void uart_task(void *pvParameters) {
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
while (1) {
// Read data from UART
int len = uart_read_bytes(UART_NUM_2, data, BUF_SIZE, 1000 / portTICK_PERIOD_MS);
if (len > 0) {
data[len] = '\0';
ESP_LOGI(TAG, "Received: %s", data);
} else {
ESP_LOGI(TAG, "No data...");
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
free(data);
}
void test_uart() {
// Initialize UART
ESP_LOGI(TAG, "Reading modem serial data...");
uart_init();
ESP_LOGI(TAG, "Creating uart task...");
// Create UART task
xTaskCreate(uart_task, "uart_task", 2048, NULL, 10, NULL);
}
[/Codebox]
The uart_task will let you parse the received serial data. Allowing to filter out URC messages (starting with only +) and trigger a necessary action.
Who is online
Users browsing this forum: No registered users and 17 guests