Skip to content

Commit

Permalink
feat(modem): Support for pausing network in C-API
Browse files Browse the repository at this point in the history
also adds a demo of this feature to pppos client example
  • Loading branch information
david-cermak committed Dec 5, 2024
1 parent 247f168 commit 1db83cd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions components/esp_modem/examples/pppos_client/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,14 @@ menu "Example Configuration"
help
MQTT data message, which we publish and expect to receive.

config EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL
bool "Demonstrate netif pause"
default n
help
Set this to true to demonstrate network pausing.
If enabled, the example waits for an MQTT data, then temporarily
drops network to check signal quality, resumes networking and
publishes another MQTT message.
Connection to the MQTT broker should be kept.

endmenu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand Down Expand Up @@ -317,6 +317,20 @@ void app_main(void)
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
esp_mqtt_client_start(mqtt_client);

#if CONFIG_EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL
xEventGroupWaitBits(event_group, GOT_DATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY);
esp_modem_pause_net(dce, true);
err = esp_modem_get_signal_quality(dce, &rssi, &ber);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with %d", err);
return;
}
ESP_LOGI(TAG, "Signal quality: rssi=%d, ber=%d", rssi, ber);
esp_modem_pause_net(dce, false);
esp_mqtt_client_publish(mqtt_client, CONFIG_EXAMPLE_MQTT_TEST_TOPIC, CONFIG_EXAMPLE_MQTT_TEST_DATA, 0, 0, 0);
#endif

ESP_LOGI(TAG, "Waiting for MQTT data");
xEventGroupWaitBits(event_group, GOT_DATA_BIT | USB_DISCONNECTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
CHECK_USB_DISCONNECTION(event_group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ CONFIG_EXAMPLE_MODEM_DEVICE_SIM800=y
CONFIG_EXAMPLE_MODEM_DEVICE_BG96=n
CONFIG_EXAMPLE_MODEM_PPP_APN="lpwa.vodafone.com"
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
CONFIG_EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL=y
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
CONFIG_ESP32_PANIC_PRINT_HALT=y
11 changes: 11 additions & 0 deletions components/esp_modem/include/esp_modem_c_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn);
esp_err_t esp_modem_set_urc(esp_modem_dce_t *dce, esp_err_t(*got_line_cb)(uint8_t *data, size_t len));
#endif

/**
* @brief This API provides support for temporarily pausing networking in order
* to send/receive AT commands and resume networking afterwards.
* @note This function does not switch modes, the modem is still in data mode.
*
* @param dce Modem DCE handle
* @param pause true to pause the network interface, false to resume networking
* @return ESP_OK on success
*/
esp_err_t esp_modem_pause_net(esp_modem_dce_t *dce, bool pause);

/**
* @}
*/
Expand Down
8 changes: 8 additions & 0 deletions components/esp_modem/src/esp_modem_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,11 @@ extern "C" esp_err_t esp_modem_set_urc(esp_modem_dce_t *dce_wrap, esp_err_t(*got
return ESP_OK;
}
#endif

extern "C" esp_err_t esp_modem_pause_net(esp_modem_dce_t *dce_wrap, bool pause)
{
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
return ESP_ERR_INVALID_ARG;
}
return command_response_to_esp_err(dce_wrap->dce->pause_netif(pause));
}

0 comments on commit 1db83cd

Please sign in to comment.