espressif / esp-iot-bridge

A smart bridge to make both ESP and the other MCU or smart device can access the Internet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reconnecting router modem

MiguelBailonS opened this issue · comments

Hi, @tswen,
I am having troubles when the modem reconnect in another project. I am simulating the event "LOST IP" removing the SIM CARD and then inserting it again. When the LOST IP event is called, I do this.
esp_event_handler_unregister_with(loop_handle, CELLULAR, ESP_EVENT_ANY_ID, esp_netif_action_start)
esp_event_handler_unregister_with(loop_handle, CELLULAR, ESP_EVENT_ANY_ID, esp_netif_action_stop)
esp_event_handler_unregister_with(loop_handle, CELLULAR, ESP_EVENT_ANY_ID,nic_cellular_event_handler)
esp_netif_destroy(driver->netif);
free(driver);
vEventGroupDelete(event_group)
esp_event_loop_delete(loop_handle)
vTaskDelete(xHandle)

When I tried to connect I do this:

  • send AT commands again for reconnecting and when all is ready, send Connect AT command and in the event handler for PPP connection create everything again

    esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event, NULL)
    event_group = xEventGroupCreate();
    esp_netif_config_t cfg = ESP_NETIF_DEFAULT_PPP();
    esp_netif = esp_netif_new(&cfg);
    esp_event_loop_create(&loop_args, &loop_handle);
    esp_event_loop_args_t loop_args = {
    .queue_size = 16,
    .task_name = NULL
    };
    esp_event_handler_register_with(loop_handle, EZM_NIC_CELLULAR, ESP_EVENT_ANY_ID,nic_cellular_event_handler, NULL)
    Task{
    esp_event_loop_run(loop_handle, pdMS_TO_TICKS(50))
    TaskDelay(10);
    }
    creates driver;
    register handles in loop handle for
    esp_netif_action_start
    esp_netif_action_stop
    esp_netif_action_connected
    esp_netif_action_disconnected
    esp_netif_attach(esp_netif, driver);

Please, Could you guide me if am I doing something wrong?