Skip to content

Commit

Permalink
fix(modem): Added C-API to configure APN
Browse files Browse the repository at this point in the history
Closes #485
  • Loading branch information
david-cermak committed Jan 17, 2024
1 parent 7a2b239 commit 46d7bfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 20 additions & 1 deletion components/esp_modem/include/esp_modem_c_api_types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -119,8 +119,27 @@ esp_err_t esp_modem_set_error_cb(esp_modem_dce_t *dce, esp_modem_terminal_error_
*/
esp_err_t esp_modem_set_mode(esp_modem_dce_t *dce, esp_modem_dce_mode_t mode);

/**
* @brief Convenient function to run arbitrary commands from C-API
*
* @param dce Modem DCE handle
* @param command Command to send
* @param got_line_cb Callback function which is called whenever we receive a line
* @param timeout_ms Command timeout
* @return ESP_OK on success, ESP_FAIL on failure
*/

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);

/**
* @brief Sets the APN and configures it into the modem's PDP context
*
* @param dce Modem DCE handle
* @param apn Access Point Name
* @return ESP_OK on success
*/
esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce, const char *apn);

/**
* @}
*/
Expand Down
7 changes: 7 additions & 0 deletions components/esp_modem/src/esp_modem_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,10 @@ extern "C" esp_err_t esp_modem_set_baud(esp_modem_dce_t *dce_wrap, int baud)
{
return command_response_to_esp_err(dce_wrap->dce->set_baud(baud));
}

esp_err_t esp_modem_set_apn(esp_modem_dce_t *dce_wrap, const char *apn)
{
auto new_pdp = std::unique_ptr<PdpContext>(new PdpContext(apn));
dce_wrap->dce->get_module()->configure_pdp_context(std::move(new_pdp));
return ESP_OK;
}

0 comments on commit 46d7bfa

Please sign in to comment.