Skip to content

Commit ce7dadd

Browse files
committed
fix(modem): Added C-API to configure APN
Closes #485
1 parent 7a2b239 commit ce7dadd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

components/esp_modem/include/esp_modem_c_api_types.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -119,8 +119,27 @@ esp_err_t esp_modem_set_error_cb(esp_modem_dce_t *dce, esp_modem_terminal_error_
119119
*/
120120
esp_err_t esp_modem_set_mode(esp_modem_dce_t *dce, esp_modem_dce_mode_t mode);
121121

122+
/**
123+
* @brief Convenient function to run arbitrary commands from C-API
124+
*
125+
* @param dce Modem DCE handle
126+
* @param command Command to send
127+
* @param got_line_cb Callback function which is called whenever we receive a line
128+
* @param timeout_ms Command timeout
129+
* @return ESP_OK on success, ESP_FAIL on failure
130+
*/
131+
122132
esp_err_t esp_modem_command(esp_modem_dce_t *dce, const char *command, esp_err_t(*got_line_cb)(uint8_t *data, size_t len), uint32_t timeout_ms);
123133

134+
/**
135+
* @brief Sets the APN and configures it into the modem's PDP context
136+
*
137+
* @param dce Modem DCE handle
138+
* @param apn Access Point Name
139+
* @return ESP_OK on success
140+
*/
141+
esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn);
142+
124143
/**
125144
* @}
126145
*/

components/esp_modem/src/esp_modem_c_api.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,10 @@ extern "C" esp_err_t esp_modem_set_baud(esp_modem_dce_t *dce_wrap, int baud)
448448
{
449449
return command_response_to_esp_err(dce_wrap->dce->set_baud(baud));
450450
}
451+
452+
extern "C" esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce_wrap, const char *apn)
453+
{
454+
auto new_pdp = std::unique_ptr<PdpContext>(new PdpContext(apn));
455+
dce_wrap->dce->get_module()->configure_pdp_context(std::move(new_pdp));
456+
return ESP_OK;
457+
}

0 commit comments

Comments
 (0)