Skip to content

Commit de6500e

Browse files
committed
fix(modem): Fix build step
1 parent fcff07e commit de6500e

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <algorithm>
78
#include <charconv>
89
#include <sys/socket.h>
910
#include "esp_vfs.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <algorithm>
78
#include <charconv>
89
#include <sys/socket.h>
910
#include "esp_vfs.h"

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
#include "tcp_transport_at.h"
2525

2626
// #define BROKER_URL "test.mosquitto.org"
27-
#define BROKER_URL "broker.emqx.io"
28-
#define BROKER_PORT 1883
27+
// #define BROKER_URL "broker.emqx.io"
28+
#define BROKER_URL "192.168.0.18"
29+
#define BROKER_PORT 8883
2930

3031

3132
static const char *TAG = "modem_client";
@@ -141,20 +142,20 @@ static void perform(void* ctx)
141142
char mqtt_client_id[] = "MQTT_CLIENT_0";
142143
static int counter = 0;
143144
const int id = counter++;
144-
mqtt_client_id[12] += id; // assumes different client id per each thread
145+
mqtt_client_id[12] += id; // assumes a different client id per each thread
145146
esp_mqtt_client_config_t mqtt_config = {};
146-
mqtt_config.broker.address.port = BROKER_PORT; // + id;
147+
mqtt_config.broker.address.port = BROKER_PORT + id;
147148
mqtt_config.session.message_retransmit_timeout = 10000;
148149
mqtt_config.credentials.client_id = mqtt_client_id;
149150
#ifndef CONFIG_EXAMPLE_CUSTOM_TCP_TRANSPORT
150-
mqtt_config.broker.address.uri = "mqtt://127.0.0.1";
151+
mqtt_config.broker.address.uri = "mqtts://127.0.0.1";
151152
dce->start_listening(BROKER_PORT + id);
152153
#else
153-
mqtt_config.broker.address.uri = "mqtt://" BROKER_URL;
154+
mqtt_config.broker.address.uri = "mqtts://" BROKER_URL;
154155
esp_transport_handle_t at = esp_transport_at_init(dce);
155-
// esp_transport_handle_t ssl = esp_transport_tls_init(at);
156+
esp_transport_handle_t ssl = esp_transport_tls_init(at);
156157

157-
mqtt_config.network.transport = at;
158+
mqtt_config.network.transport = ssl;
158159
#endif
159160
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
160161
esp_mqtt_client_register_event(mqtt_client, static_cast<esp_mqtt_event_id_t>(ESP_EVENT_ANY_ID), mqtt_event_handler, nullptr);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Responder::ret Responder::recv(uint8_t *data, size_t len)
133133
const std::string_view recv_data_view = std::string_view(recv_data, len);
134134
auto head_pos_found = recv_data_view.find(head);
135135
if (head_pos_found == std::string_view::npos) {
136-
return ret::FAIL;
136+
return ret::IN_PROGRESS;
137137
}
138138

139139
auto *head_pos = recv_data + head_pos_found;

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,13 @@ Responder::ret Responder::recv(uint8_t *data, size_t len)
200200
auto *recv_data = (char *)data;
201201

202202
if (data_to_recv == 0) {
203-
// const std::string_view error_str = "ERROR";
204-
// const std::string_view data_sv(recv_data, len);
205-
// if (data_sv.find(error_str) == std::string_view::npos) {
206-
// // no data,
207-
// return ret::OK;
208-
// }
209203
const std::string_view head = "+CIPRECVDATA:";
210-
211-
// Find the response header
212-
auto head_pos = std::search(recv_data, recv_data + len, head.data(), head.data() + head.size(), [](char a, char b) {
213-
return a == b;
214-
});
215-
216-
if (head_pos == recv_data + len) {
204+
const std::string_view recv_data_view(recv_data, len);
205+
const auto head_pos_found = recv_data_view.find(head);
206+
if (head_pos_found == std::string_view::npos) {
217207
return ret::IN_PROGRESS;
218208
}
219-
209+
const auto *head_pos = recv_data + head_pos_found;
220210
// Find the end of the length field
221211
auto next_comma = (char *)memchr(head_pos + head.size(), ',', MIN_MESSAGE);
222212
if (next_comma == nullptr) {
@@ -265,12 +255,22 @@ Responder::ret Responder::recv(uint8_t *data, size_t len)
265255
char *ok_pos = nullptr;
266256
if (actual_len + 1 + 2 /* OK */ <= len) {
267257
ok_pos = (char *)memchr(recv_data + actual_len + 1, 'O', MIN_MESSAGE);
268-
if (ok_pos == nullptr || ok_pos[1] != 'K') {
258+
if (ok_pos == nullptr) { // || ok_pos[1] != 'K') {
259+
data_to_recv = 0;
260+
return ret::FAIL;
261+
}
262+
if (ok_pos + 1 < recv_data + len && ok_pos[1] != 'K') {
263+
// we ignore the condition when receiving 'O' as the last character in the last batch,
264+
// don't wait for the 'K' in the next run, assume the data are valid and let higher layers deal with it.
269265
data_to_recv = 0;
270266
return ret::FAIL;
271267
}
272268
}
273-
269+
if (ok_pos != nullptr && (char *)data + len - ok_pos - 2 > MIN_MESSAGE) {
270+
// check for async replies after the Recv header
271+
std::string_view response((char *)ok_pos + 2 /* OK */, (char *)data + len - ok_pos);
272+
check_urc(status::RECEIVING, response);
273+
}
274274
// Reset and prepare for next receive
275275
data_to_recv = 0;
276276
return ret::OK;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,24 @@ Responder::ret Responder::connect(std::string_view response)
343343
Responder::ret Responder::check_urc(status state, std::string_view &response)
344344
{
345345
// Handle data notifications - in multiple connections mode, format is +IPD,<link ID>,<len>
346-
std::string expected_urc = "+IPD," + std::to_string(link_id);
347-
if (response.find(expected_urc) != std::string::npos) {
346+
if (response.find("+CIPRXGET: 1") != std::string::npos) {
348347
uint64_t data_ready = 1;
349348
write(data_ready_fd, &data_ready, sizeof(data_ready));
350-
ESP_LOGD(TAG, "Data available notification");
349+
ESP_LOGD(TAG, "Got data on modem!");
351350
}
352351
return ret::IN_PROGRESS;
353352
}
354353

355354
Responder::ret Responder::check_async_replies(status state, std::string_view &response)
356355
{
357-
if (response.find("+CIPRXGET: 1") != std::string::npos) {
358-
uint64_t data_ready = 1;
359-
write(data_ready_fd, &data_ready, sizeof(data_ready));
360-
ESP_LOGD(TAG, "Got data on modem!");
356+
ESP_LOGD(TAG, "response %.*s", static_cast<int>(response.size()), response.data());
357+
if (state == status::SENDING) {
358+
return send(response);
359+
} else if (state == status::CONNECTING) {
360+
return connect(response);
361361
}
362362
return ret::IN_PROGRESS;
363+
363364
}
364365

365366
Responder::ret Responder::process_data(status state, uint8_t *data, size_t len)

0 commit comments

Comments
 (0)