kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/fix_esp_modem_mode_switch_timeout' into 'master'
fix esp_modem switch mode timeout Closes FCS-412, IDFGH-2106, IDFGH-2170, and IDFGH-1201 See merge request espressif/esp-idf!8913pull/5452/head
commit
738e9f76fd
|
@ -52,7 +52,7 @@ See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/l
|
|||
|
||||
## Example Output
|
||||
|
||||
The example will get module and operator's information after start up, and then go into PPP mode to start mqtt client operations. This example will also send a short message to someone's phone if you have enabled this feature in menuconfig.
|
||||
The example will get module and operator's information after start up, and then go into PPP mode to start mqtt client operations. This example will also send a short message to someone's phone if you have enabled this feature in menuconfig. The PPP connection will get restarted after 60 seconds.
|
||||
|
||||
### BG96 Output
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef struct modem_dte modem_dte_t;
|
|||
*/
|
||||
#define MODEM_COMMAND_TIMEOUT_DEFAULT (500) /*!< Default timeout value for most commands */
|
||||
#define MODEM_COMMAND_TIMEOUT_OPERATOR (75000) /*!< Timeout value for getting operator status */
|
||||
#define MODEM_COMMAND_TIMEOUT_MODE_CHANGE (3000) /*!< Timeout value for changing working mode */
|
||||
#define MODEM_COMMAND_TIMEOUT_MODE_CHANGE (5000) /*!< Timeout value for changing working mode */
|
||||
#define MODEM_COMMAND_TIMEOUT_HANG_UP (90000) /*!< Timeout value for hang up */
|
||||
#define MODEM_COMMAND_TIMEOUT_POWEROFF (1000) /*!< Timeout value for power down */
|
||||
|
||||
|
|
|
@ -412,6 +412,8 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config)
|
|||
res = uart_driver_install(esp_dte->uart_port, config->rx_buffer_size, config->tx_buffer_size,
|
||||
config->event_queue_size, &(esp_dte->event_queue), 0);
|
||||
MODEM_CHECK(res == ESP_OK, "install uart driver failed", err_uart_config);
|
||||
res = uart_set_rx_timeout(esp_dte->uart_port, 1);
|
||||
MODEM_CHECK(res == ESP_OK, "set rx timeout failed", err_uart_config);
|
||||
|
||||
/* Set pattern interrupt, used to detect the end of a line. */
|
||||
res = uart_enable_pattern_det_baud_intr(esp_dte->uart_port, '\n', 1, MIN_PATTERN_INTERVAL, MIN_POST_IDLE, MIN_PRE_IDLE);
|
||||
|
|
|
@ -227,11 +227,6 @@ void app_main(void)
|
|||
|
||||
event_group = xEventGroupCreate();
|
||||
|
||||
// Init netif object
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_PPP();
|
||||
esp_netif_t *esp_netif = esp_netif_new(&cfg);
|
||||
assert(esp_netif);
|
||||
|
||||
/* create dte object */
|
||||
esp_modem_dte_config_t config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
/* setup UART specific configuration based on kconfig options */
|
||||
|
@ -245,15 +240,27 @@ void app_main(void)
|
|||
config.event_queue_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE;
|
||||
config.event_task_stack_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE;
|
||||
config.event_task_priority = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY;
|
||||
config.line_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE/2;
|
||||
config.line_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE / 2;
|
||||
|
||||
modem_dte_t *dte = esp_modem_dte_init(&config);
|
||||
/* Register event handler */
|
||||
ESP_ERROR_CHECK(esp_modem_set_event_handler(dte, modem_event_handler, ESP_EVENT_ANY_ID, NULL));
|
||||
|
||||
// Init netif object
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_PPP();
|
||||
esp_netif_t *esp_netif = esp_netif_new(&cfg);
|
||||
assert(esp_netif);
|
||||
|
||||
void *modem_netif_adapter = esp_modem_netif_setup(dte);
|
||||
esp_modem_netif_set_default_handlers(modem_netif_adapter, esp_netif);
|
||||
|
||||
while (1) {
|
||||
modem_dce_t *dce = NULL;
|
||||
/* create dce object */
|
||||
#if CONFIG_EXAMPLE_MODEM_DEVICE_SIM800
|
||||
modem_dce_t *dce = sim800_init(dte);
|
||||
dce = sim800_init(dte);
|
||||
#elif CONFIG_EXAMPLE_MODEM_DEVICE_BG96
|
||||
modem_dce_t *dce = bg96_init(dte);
|
||||
dce = bg96_init(dte);
|
||||
#else
|
||||
#error "Unsupported DCE"
|
||||
#endif
|
||||
|
@ -277,12 +284,11 @@ void app_main(void)
|
|||
#if !defined(CONFIG_EXAMPLE_MODEM_PPP_AUTH_NONE) && (defined(CONFIG_LWIP_PPP_PAP_SUPPORT) || defined(CONFIG_LWIP_PPP_CHAP_SUPPORT))
|
||||
esp_netif_ppp_set_auth(esp_netif, auth_type, CONFIG_EXAMPLE_MODEM_PPP_AUTH_USERNAME, CONFIG_EXAMPLE_MODEM_PPP_AUTH_PASSWORD);
|
||||
#endif
|
||||
void *modem_netif_adapter = esp_modem_netif_setup(dte);
|
||||
esp_modem_netif_set_default_handlers(modem_netif_adapter, esp_netif);
|
||||
/* attach the modem to the network interface */
|
||||
esp_netif_attach(esp_netif, modem_netif_adapter);
|
||||
/* Wait for IP address */
|
||||
xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
|
||||
/* Config MQTT */
|
||||
esp_mqtt_client_config_t mqtt_config = {
|
||||
.uri = BROKER_URL,
|
||||
|
@ -292,11 +298,10 @@ void app_main(void)
|
|||
esp_mqtt_client_start(mqtt_client);
|
||||
xEventGroupWaitBits(event_group, GOT_DATA_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
esp_mqtt_client_destroy(mqtt_client);
|
||||
|
||||
/* Exit PPP mode */
|
||||
ESP_ERROR_CHECK(esp_modem_stop_ppp(dte));
|
||||
/* Destroy the netif adapter withe events, which internally frees also the esp-netif instance */
|
||||
esp_modem_netif_clear_default_handlers(modem_netif_adapter);
|
||||
esp_modem_netif_teardown(modem_netif_adapter);
|
||||
|
||||
xEventGroupWaitBits(event_group, STOP_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
#if CONFIG_EXAMPLE_SEND_MSG
|
||||
const char *message = "Welcome to ESP32!";
|
||||
|
@ -307,5 +312,13 @@ void app_main(void)
|
|||
ESP_ERROR_CHECK(dce->power_down(dce));
|
||||
ESP_LOGI(TAG, "Power down");
|
||||
ESP_ERROR_CHECK(dce->deinit(dce));
|
||||
|
||||
ESP_LOGI(TAG, "Restart after 60 seconds");
|
||||
vTaskDelay(pdMS_TO_TICKS(60000));
|
||||
}
|
||||
|
||||
/* Destroy the netif adapter withe events, which internally frees also the esp-netif instance */
|
||||
esp_modem_netif_clear_default_handlers(modem_netif_adapter);
|
||||
esp_modem_netif_teardown(modem_netif_adapter);
|
||||
ESP_ERROR_CHECK(dte->deinit(dte));
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue