mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
add pppos client restart in example
Closes https://github.com/espressif/esp-idf/issues/4268
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user