pppos_client example hangs when I loop it

hans-jorgen
Posts: 3
Joined: Thu Apr 23, 2020 12:51 pm

pppos_client example hangs when I loop it

Postby hans-jorgen » Thu Apr 23, 2020 1:40 pm

I am trying to use a sim800 circuit and am fooling around with the pppos example. I am using esp-idf 4.0.

The example works fine, but when I add a loop to take down and up the PPP connection it freezes waiting for a semaphore in tcpip.c.

What I've done:

Started a new project with the visualgdb wizard in Visual Studio
Setup correct APN, TXD and RXD pin in example configuration.
Tested the base project without any changes, works fine.

Modified app_main() in pppos_client_main.c thusly:
  1.     ESP_ERROR_CHECK(esp_modem_add_event_handler(dte, modem_event_handler, NULL));
  2.     /* create dce object */
  3. #if CONFIG_EXAMPLE_MODEM_DEVICE_SIM800
  4.     modem_dce_t *dce = sim800_init(dte);
  5. #elif CONFIG_EXAMPLE_MODEM_DEVICE_BG96
  6.     modem_dce_t *dce = bg96_init(dte);
  7. #else
  8. #error "Unsupported DCE"
  9. #endif
  10.     ESP_ERROR_CHECK(dce->set_flow_ctrl(dce, MODEM_FLOW_CONTROL_NONE));
  11.     ESP_ERROR_CHECK(dce->store_profile(dce));
  12.     while (1)
  13.     {
  14.         /* Print Module ID, Operator, IMEI, IMSI */
  15.         ESP_LOGI(TAG, "Module: %s", dce->name);
  16.         ESP_LOGI(TAG, "Operator: %s", dce->oper);
  17.         ESP_LOGI(TAG, "IMEI: %s", dce->imei);
  18.         ESP_LOGI(TAG, "IMSI: %s", dce->imsi);
  19.         /* Get signal quality */
  20.         uint32_t rssi = 0, ber = 0;
  21.         ESP_ERROR_CHECK(dce->get_signal_quality(dce, &rssi, &ber));
  22.         ESP_LOGI(TAG, "rssi: %d, ber: %d", rssi, ber);
  23.         /* Get battery voltage */
  24.         uint32_t voltage = 0, bcs = 0, bcl = 0;
  25.         ESP_ERROR_CHECK(dce->get_battery_status(dce, &bcs, &bcl, &voltage));
  26.         ESP_LOGI(TAG, "Battery voltage: %d mV", voltage);
  27.         /* Setup PPP environment */
  28.         esp_modem_setup_ppp(dte);
  29.         /* Wait for IP address */
  30.         xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
  31.         /* Config MQTT */
  32.         esp_mqtt_client_config_t mqtt_config = {
  33.             .uri = BROKER_URL,
  34.             .event_handle = mqtt_event_handler,
  35.         };
  36.         esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
  37.         esp_mqtt_client_start(mqtt_client);
  38.         xEventGroupWaitBits(event_group, GOT_DATA_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
  39.         esp_mqtt_client_destroy(mqtt_client);
  40.         /* Exit PPP mode */
  41.         ESP_ERROR_CHECK(esp_modem_exit_ppp(dte));
  42.         xEventGroupWaitBits(event_group, STOP_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
  43.         #if CONFIG_EXAMPLE_SEND_MSG
  44.         const char *message = "Welcome to ESP32!";
  45.         ESP_ERROR_CHECK(example_send_message_text(dce, CONFIG_EXAMPLE_SEND_MSG_PEER_PHONE_NUMBER, message));
  46.         ESP_LOGI(TAG, "Send send message [%s] ok", message);
  47.         #endif
  48.     }
  49.     /* Power down module */
  50.     ESP_ERROR_CHECK(dce->power_down(dce));
This ought to init ppp, do stuff, close ppp again and again.

On the second loop it freezes waitning for a semaphore in tcpip_api_call(), this specific line:

Code: Select all

  sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0);
If I modify the timeout 0 to 10000 it timeouts and continues and on every following loop the code works as I envisioned it would, it does not get stuck on that semaphore on laps 1 and 3-eternity.

This seems to be because the TCP/IP stack is not in the expected location on the second lap. It is itself already stuck on that semaphore. Stepping through the code it seems like the TCP/IP stack normally waits for an mbox, sent by tcpip_api_call I presume, but somehow it gets "out of sync" on lap 2 in the loop.

It seems to get out of sync in esp_modem_exit_ppp() inbetween the following two lines:

Code: Select all

    MODEM_CHECK(dte->change_mode(dte, MODEM_COMMAND_MODE) == ESP_OK, "enter command mode failed", err);
    /* Hang up */
    MODEM_CHECK(dce->hang_up(dce) == ESP_OK, "hang up failed", err);
I've tried all my 1337 ninja skills on finding clues as to why, but I have been unsuccessful. Anyone else recognize this?

sumesh
Posts: 16
Joined: Fri Dec 22, 2017 12:11 am

Re: pppos_client example hangs when I loop it

Postby sumesh » Thu Oct 22, 2020 6:14 am

did u manage to fix this issue?
i am also having the same issue.. cant change mode back to cmd before hanging up

Who is online

Users browsing this forum: VinayDand and 420 guests