Skip to content

Commit 1db83cd

Browse files
committed
feat(modem): Support for pausing network in C-API
also adds a demo of this feature to pppos client example
1 parent 247f168 commit 1db83cd

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

components/esp_modem/examples/pppos_client/main/Kconfig.projbuild

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,14 @@ menu "Example Configuration"
201201
help
202202
MQTT data message, which we publish and expect to receive.
203203

204+
config EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL
205+
bool "Demonstrate netif pause"
206+
default n
207+
help
208+
Set this to true to demonstrate network pausing.
209+
If enabled, the example waits for an MQTT data, then temporarily
210+
drops network to check signal quality, resumes networking and
211+
publishes another MQTT message.
212+
Connection to the MQTT broker should be kept.
213+
204214
endmenu

components/esp_modem/examples/pppos_client/main/pppos_client_main.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -317,6 +317,20 @@ void app_main(void)
317317
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
318318
esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
319319
esp_mqtt_client_start(mqtt_client);
320+
321+
#if CONFIG_EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL
322+
xEventGroupWaitBits(event_group, GOT_DATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY);
323+
esp_modem_pause_net(dce, true);
324+
err = esp_modem_get_signal_quality(dce, &rssi, &ber);
325+
if (err != ESP_OK) {
326+
ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with %d", err);
327+
return;
328+
}
329+
ESP_LOGI(TAG, "Signal quality: rssi=%d, ber=%d", rssi, ber);
330+
esp_modem_pause_net(dce, false);
331+
esp_mqtt_client_publish(mqtt_client, CONFIG_EXAMPLE_MQTT_TEST_TOPIC, CONFIG_EXAMPLE_MQTT_TEST_DATA, 0, 0, 0);
332+
#endif
333+
320334
ESP_LOGI(TAG, "Waiting for MQTT data");
321335
xEventGroupWaitBits(event_group, GOT_DATA_BIT | USB_DISCONNECTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
322336
CHECK_USB_DISCONNECTION(event_group);

components/esp_modem/examples/pppos_client/sdkconfig.ci.sim800_c3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ CONFIG_EXAMPLE_MODEM_DEVICE_SIM800=y
1111
CONFIG_EXAMPLE_MODEM_DEVICE_BG96=n
1212
CONFIG_EXAMPLE_MODEM_PPP_APN="lpwa.vodafone.com"
1313
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
14+
CONFIG_EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL=y
1415
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
1516
CONFIG_ESP32_PANIC_PRINT_HALT=y

components/esp_modem/include/esp_modem_c_api_types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn);
160160
esp_err_t esp_modem_set_urc(esp_modem_dce_t *dce, esp_err_t(*got_line_cb)(uint8_t *data, size_t len));
161161
#endif
162162

163+
/**
164+
* @brief This API provides support for temporarily pausing networking in order
165+
* to send/receive AT commands and resume networking afterwards.
166+
* @note This function does not switch modes, the modem is still in data mode.
167+
*
168+
* @param dce Modem DCE handle
169+
* @param pause true to pause the network interface, false to resume networking
170+
* @return ESP_OK on success
171+
*/
172+
esp_err_t esp_modem_pause_net(esp_modem_dce_t *dce, bool pause);
173+
163174
/**
164175
* @}
165176
*/

components/esp_modem/src/esp_modem_c_api.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,11 @@ extern "C" esp_err_t esp_modem_set_urc(esp_modem_dce_t *dce_wrap, esp_err_t(*got
475475
return ESP_OK;
476476
}
477477
#endif
478+
479+
extern "C" esp_err_t esp_modem_pause_net(esp_modem_dce_t *dce_wrap, bool pause)
480+
{
481+
if (dce_wrap == nullptr || dce_wrap->dce == nullptr) {
482+
return ESP_ERR_INVALID_ARG;
483+
}
484+
return command_response_to_esp_err(dce_wrap->dce->pause_netif(pause));
485+
}

0 commit comments

Comments
 (0)