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);
|
||||
|
|
|
@ -167,7 +167,7 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
|
|||
}
|
||||
|
||||
static void on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
ESP_LOGI(TAG, "PPP state changed event %d", event_id);
|
||||
if (event_id == NETIF_PPP_ERRORUSER) {
|
||||
|
@ -179,7 +179,7 @@ static void on_ppp_changed(void *arg, esp_event_base_t event_base,
|
|||
|
||||
|
||||
static void on_ip_event(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
ESP_LOGD(TAG, "IP event! %d", event_id);
|
||||
if (event_id == IP_EVENT_PPP_GOT_IP) {
|
||||
|
@ -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,67 +240,85 @@ 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));
|
||||
/* create dce object */
|
||||
|
||||
// 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
|
||||
assert(dce != NULL);
|
||||
ESP_ERROR_CHECK(dce->set_flow_ctrl(dce, MODEM_FLOW_CONTROL_NONE));
|
||||
ESP_ERROR_CHECK(dce->store_profile(dce));
|
||||
/* Print Module ID, Operator, IMEI, IMSI */
|
||||
ESP_LOGI(TAG, "Module: %s", dce->name);
|
||||
ESP_LOGI(TAG, "Operator: %s", dce->oper);
|
||||
ESP_LOGI(TAG, "IMEI: %s", dce->imei);
|
||||
ESP_LOGI(TAG, "IMSI: %s", dce->imsi);
|
||||
/* Get signal quality */
|
||||
uint32_t rssi = 0, ber = 0;
|
||||
ESP_ERROR_CHECK(dce->get_signal_quality(dce, &rssi, &ber));
|
||||
ESP_LOGI(TAG, "rssi: %d, ber: %d", rssi, ber);
|
||||
/* Get battery voltage */
|
||||
uint32_t voltage = 0, bcs = 0, bcl = 0;
|
||||
ESP_ERROR_CHECK(dce->get_battery_status(dce, &bcs, &bcl, &voltage));
|
||||
ESP_LOGI(TAG, "Battery voltage: %d mV", voltage);
|
||||
/* setup PPPoS network parameters */
|
||||
assert(dce != NULL);
|
||||
ESP_ERROR_CHECK(dce->set_flow_ctrl(dce, MODEM_FLOW_CONTROL_NONE));
|
||||
ESP_ERROR_CHECK(dce->store_profile(dce));
|
||||
/* Print Module ID, Operator, IMEI, IMSI */
|
||||
ESP_LOGI(TAG, "Module: %s", dce->name);
|
||||
ESP_LOGI(TAG, "Operator: %s", dce->oper);
|
||||
ESP_LOGI(TAG, "IMEI: %s", dce->imei);
|
||||
ESP_LOGI(TAG, "IMSI: %s", dce->imsi);
|
||||
/* Get signal quality */
|
||||
uint32_t rssi = 0, ber = 0;
|
||||
ESP_ERROR_CHECK(dce->get_signal_quality(dce, &rssi, &ber));
|
||||
ESP_LOGI(TAG, "rssi: %d, ber: %d", rssi, ber);
|
||||
/* Get battery voltage */
|
||||
uint32_t voltage = 0, bcs = 0, bcl = 0;
|
||||
ESP_ERROR_CHECK(dce->get_battery_status(dce, &bcs, &bcl, &voltage));
|
||||
ESP_LOGI(TAG, "Battery voltage: %d mV", voltage);
|
||||
/* setup PPPoS network parameters */
|
||||
#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);
|
||||
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,
|
||||
.event_handle = mqtt_event_handler,
|
||||
};
|
||||
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
|
||||
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));
|
||||
/* 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,
|
||||
.event_handle = mqtt_event_handler,
|
||||
};
|
||||
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
|
||||
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));
|
||||
|
||||
xEventGroupWaitBits(event_group, STOP_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
#if CONFIG_EXAMPLE_SEND_MSG
|
||||
const char *message = "Welcome to ESP32!";
|
||||
ESP_ERROR_CHECK(example_send_message_text(dce, CONFIG_EXAMPLE_SEND_MSG_PEER_PHONE_NUMBER, message));
|
||||
ESP_LOGI(TAG, "Send send message [%s] ok", message);
|
||||
#endif
|
||||
/* Power down module */
|
||||
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);
|
||||
xEventGroupWaitBits(event_group, STOP_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
#if CONFIG_EXAMPLE_SEND_MSG
|
||||
const char *message = "Welcome to ESP32!";
|
||||
ESP_ERROR_CHECK(example_send_message_text(dce, CONFIG_EXAMPLE_SEND_MSG_PEER_PHONE_NUMBER, message));
|
||||
ESP_LOGI(TAG, "Send send message [%s] ok", message);
|
||||
#endif
|
||||
/* Power down module */
|
||||
ESP_ERROR_CHECK(dce->power_down(dce));
|
||||
ESP_LOGI(TAG, "Power down");
|
||||
ESP_ERROR_CHECK(dce->deinit(dce));
|
||||
ESP_ERROR_CHECK(dte->deinit(dte));
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue