Skip to content

Commit 14d3cb6

Browse files
committed
fix(modem): Add support for ESP-AT based tcp-client example
1 parent ccdb45e commit 14d3cb6

File tree

10 files changed

+443
-11
lines changed

10 files changed

+443
-11
lines changed

components/esp_modem/examples/modem_tcp_client/main/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
set(module_dir "generic_module")
12
if (CONFIG_EXAMPLE_MODEM_DEVICE_BG96)
23
set(device_srcs sock_commands_bg96.cpp)
34
elseif(CONFIG_EXAMPLE_MODEM_DEVICE_SIM7600)
45
set(device_srcs sock_commands_sim7600.cpp)
6+
elseif(CONFIG_EXAMPLE_MODEM_DEVICE_ESPAT)
7+
set(device_srcs sock_commands_espat.cpp)
8+
set(module_dir "espat_module")
59
endif()
610

711
if(CONFIG_ESP_MODEM_ENABLE_DEVELOPMENT_MODE)
@@ -14,4 +18,4 @@ idf_component_register(SRCS "modem_client.cpp"
1418
"${command_dir}/sock_dce.cpp"
1519
"tcp_transport_at.cpp"
1620
"${device_srcs}"
17-
INCLUDE_DIRS "." "${command_dir}")
21+
INCLUDE_DIRS "." "${command_dir}" "${module_dir}")

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,26 @@ menu "Example Configuration"
1818
bool "SIM7600"
1919
help
2020
SIM7600 is Multi-Band LTE-TDD/LTE-FDD/HSPA+ and GSM/GPRS/EDGE module
21+
config EXAMPLE_MODEM_DEVICE_ESPAT
22+
bool "ESP-AT"
23+
help
24+
ESP-AT firmware for ESP32 modules with WiFi connectivity
2125
endchoice
2226

27+
if EXAMPLE_MODEM_DEVICE_ESPAT
28+
config EXAMPLE_WIFI_SSID
29+
string "WiFi SSID"
30+
default "myssid"
31+
help
32+
SSID (network name) to connect to.
33+
34+
config EXAMPLE_WIFI_PASSWORD
35+
string "WiFi Password"
36+
default "mypassword"
37+
help
38+
WiFi password (WPA or WPA2).
39+
endif
40+
2341
config EXAMPLE_MODEM_APN
2442
string "Set MODEM APN"
2543
default "internet"

components/esp_modem/examples/modem_tcp_client/main/command/sock_dce.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cxx_include/esp_modem_api.hpp"
99
#include <cxx_include/esp_modem_dce_factory.hpp>
1010
#include "sock_commands.hpp"
11+
#include "sock_module.hpp"
1112
#include <sys/socket.h>
1213

1314
#pragma once
@@ -97,8 +98,8 @@ class Responder {
9798
std::shared_ptr<esp_modem::DTE> &dte;
9899
};
99100

100-
class DCE : public ::esp_modem::GenericModule {
101-
using esp_modem::GenericModule::GenericModule;
101+
class DCE : public Module {
102+
using Module::Module;
102103
public:
103104

104105
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "esp_modem_config.h"
8+
#include "cxx_include/esp_modem_api.hpp"
9+
10+
#pragma once
11+
12+
namespace sock_dce {
13+
14+
class Module: public esp_modem::GenericModule {
15+
using esp_modem::GenericModule::GenericModule;
16+
public:
17+
18+
esp_modem::command_result sync() override;
19+
esp_modem::command_result set_echo(bool on) override;
20+
esp_modem::command_result set_pdp_context(esp_modem::PdpContext &pdp) override;
21+
22+
};
23+
24+
}

components/esp_modem/examples/modem_tcp_client/main/generate/sock_dce.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "cxx_include/esp_modem_api.hpp"
99
#include <cxx_include/esp_modem_dce_factory.hpp>
1010
#include "sock_commands.hpp"
11+
#include "sock_module.hpp"
1112
#include <sys/socket.h>
1213

1314
#pragma once
@@ -97,8 +98,8 @@ class Responder {
9798
std::shared_ptr<esp_modem::DTE> &dte;
9899
};
99100

100-
class DCE : public ::esp_modem::GenericModule {
101-
using esp_modem::GenericModule::GenericModule;
101+
class DCE : public Module {
102+
using Module::Module;
102103
public:
103104

104105
// --- ESP-MODEM command module starts here ---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "esp_modem_config.h"
8+
#include "cxx_include/esp_modem_api.hpp"
9+
10+
#pragma once
11+
12+
namespace sock_dce {
13+
14+
using Module = esp_modem::GenericModule;
15+
16+
}

components/esp_modem/examples/modem_tcp_client/main/modem_client.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -23,8 +23,8 @@
2323
#include "tcp_transport_mbedtls.h"
2424
#include "tcp_transport_at.h"
2525

26-
#define BROKER_URL "mqtt.eclipseprojects.io"
27-
#define BROKER_PORT 8883
26+
#define BROKER_URL "test.mosquitto.org"
27+
#define BROKER_PORT 1883
2828

2929

3030
static const char *TAG = "modem_client";
@@ -114,7 +114,7 @@ extern "C" void app_main(void)
114114
mqtt_config.broker.address.port = BROKER_PORT;
115115
mqtt_config.session.message_retransmit_timeout = 10000;
116116
#ifndef CONFIG_EXAMPLE_CUSTOM_TCP_TRANSPORT
117-
mqtt_config.broker.address.uri = "mqtts://127.0.0.1";
117+
mqtt_config.broker.address.uri = "mqtt://127.0.0.1";
118118
dce->start_listening(BROKER_PORT);
119119
#else
120120
mqtt_config.broker.address.uri = "mqtt://" BROKER_URL;
@@ -124,14 +124,14 @@ extern "C" void app_main(void)
124124
mqtt_config.network.transport = ssl;
125125
#endif
126126
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
127-
esp_mqtt_client_register_event(mqtt_client, static_cast<esp_mqtt_event_id_t>(ESP_EVENT_ANY_ID), mqtt_event_handler, NULL);
127+
esp_mqtt_client_register_event(mqtt_client, static_cast<esp_mqtt_event_id_t>(ESP_EVENT_ANY_ID), mqtt_event_handler, nullptr);
128128
esp_mqtt_client_start(mqtt_client);
129129
#ifndef CONFIG_EXAMPLE_CUSTOM_TCP_TRANSPORT
130130
if (!dce->connect(BROKER_URL, BROKER_PORT)) {
131131
ESP_LOGE(TAG, "Failed to start DCE");
132132
return;
133133
}
134-
while (1) {
134+
while (true) {
135135
while (dce->perform_sock()) {
136136
ESP_LOGV(TAG, "...performing");
137137
}

0 commit comments

Comments
 (0)