Skip to content

Commit 3225f40

Browse files
authored
Merge pull request #491 from david-cermak/feat/modem_set_apn
fix(modem): Added C-API to configure APN
2 parents d63f831 + 68ce794 commit 3225f40

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
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+
}

components/esp_modem/test/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ESP-Modem Testing
2+
3+
This folder contains automated and manual tests for esp-modem component. Beside these tests, some jobs are executed in CI to exercise standard examples (please refer to the CI definition and CI related sdkconfigs in examples).
4+
5+
List of test projects:
6+
7+
* `host_test` -- esp_modem is build on host (linux), modem's terminal in mocked using Loobpack class which creates simple responders to AT and CMUX mode. This test is executed in CI.
8+
* `target` -- test executed on target with no modem device, just a pppd running on the test runner. This test is executed in CI.
9+
* `target_ota` -- Manual test which perform OTA over PPP.
10+
* `target_iperf` -- Manual test to measure data throughput via PPP.
11+
12+
## Manual testing
13+
14+
Prior to every `esp_modem` release, these manual tests must be executed and pass
15+
(IDF-9074 to move the manual tests to CI)
16+
17+
### `target_ota`
18+
19+
Make sure that the UART ISR is not in IRAM, so the error messages are expected in the log, but the ESP32 should recover and continue with downloading the image.
20+
21+
Perform the test for these devices
22+
* SIM7600 (CMUX mode)
23+
* BG96 (CMUX mode)
24+
* SIM7000 (PPP mode)
25+
* A7672 (CMUX mode -- the only device with 2 byte CMUX payload), so the test is expected to fail more often if (`CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD=y` && `CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED=n` && dte_buffer < device max payload)
26+
* NetworkDCE -- no modem device, pppd (PPP mode)
27+
28+
Perform the test with these configurations:
29+
* CONFIG_TEST_USE_VFS_TERM (y/n)
30+
* CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT (y/n)
31+
* CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD (y/n)
32+
* CONFIG_ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED (y/n)
33+
34+
**Criteria for passing the test**
35+
36+
The test should complete the download with maximum 1 retry (50% of OTA failure)
37+
In case of CMUX mode, we're trying to exit CMUX at the end of the test. This step might also fail for some devices, as the CMUX-exit is not supported on certain devices (when the final error message appears that the device failed to exit CMUX, we just verify the new image by reseting the ESP32)
38+
39+
### `target_iperf`
40+
41+
Run these 4 `iperf` configurations (either manually or using `pytest`):
42+
* tcp_tx_throughput
43+
* tcp_rx_throughput
44+
* udp_tx_throughput
45+
* udp_rx_throughput
46+
47+
And verify in all four cases the value is about 0.70 Mbps

components/esp_modem/test/target_ota/components/manual_ota/manual_ota.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ bool manual_ota::begin()
3535
esp_transport_handle_t tcp = esp_transport_tcp_init();
3636
ssl_ = esp_transport_batch_tls_init(tcp, max_buffer_size_);
3737
http_.config_.transport = ssl_;
38+
if (http_.config_.cert_pem == nullptr || common_name_ == nullptr) {
39+
ESP_LOGE(TAG, "TLS with no verification is not supported");
40+
return fail();
41+
}
3842
if (!esp_transport_batch_set_ca_cert(ssl_, http_.config_.cert_pem, 0)) {
3943
return fail();
4044
}

components/esp_modem/test/target_ota/components/manual_ota/manual_ota.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class manual_ota {
4040
/**
4141
* @brief Set common name of the server to verify
4242
*/
43-
const char *common_name_;
43+
const char *common_name_{};
4444
/**
4545
* @brief Wrapper around the http client -- Please set the http config
4646
*/

0 commit comments

Comments
 (0)