19
19
#include "esp_http_server.h"
20
20
#include "esp_timer.h"
21
21
22
- extern uint8_t g_at_cmd_port ;
23
-
24
22
static uint8_t at_test_cmd_test (uint8_t * cmd_name )
25
23
{
26
24
uint8_t buffer [64 ] = {0 };
@@ -102,18 +100,32 @@ static void on_ip_event(void *arg, esp_event_base_t base, int32_t event_id, void
102
100
static SemaphoreHandle_t at_sync_sema = NULL ;
103
101
static void wait_data_callback (void )
104
102
{
105
- static uint8_t buffer [1024 ] = {0 };
106
- // xSemaphoreGive(at_sync_sema);
103
+ static uint8_t buffer [1500 ] = {0 };
107
104
int len = esp_at_port_read_data (buffer , sizeof (buffer ) - 1 );
108
- ESP_LOG_BUFFER_HEXDUMP ("ppp_uart_recv" , buffer , len , ESP_LOG_VERBOSE );
105
+
106
+ // Check for the escape sequence "+++" in the received data
107
+ const uint8_t escape_seq [] = "+++" ;
108
+ uint8_t * escape_ptr = memmem (buffer , len , escape_seq , 3 );
109
+
110
+ if (escape_ptr != NULL ) {
111
+ printf ("Found +++ sequence, signal to the command processing thread\n" );
112
+
113
+ int data_before_escape = escape_ptr - buffer ;
114
+ if (data_before_escape > 0 ) {
115
+ esp_netif_receive (s_netif , buffer , data_before_escape , NULL );
116
+ }
117
+
118
+ if (at_sync_sema ) {
119
+ xSemaphoreGive (at_sync_sema );
120
+ }
121
+ return ;
122
+ }
109
123
esp_netif_receive (s_netif , buffer , len , NULL );
110
124
}
111
125
112
126
static esp_err_t transmit (void * h , void * buffer , size_t len )
113
127
{
114
- // struct eppp_handle *handle = h;
115
128
printf ("transmit: %d bytes\n" , len );
116
- // ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_INFO);
117
129
esp_at_port_write_data (buffer , len );
118
130
return ESP_OK ;
119
131
}
@@ -123,7 +135,7 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
123
135
uint8_t buffer [64 ] = {0 };
124
136
snprintf ((char * )buffer , 64 , "execute command: <AT%s> is executed\r\n" , cmd_name );
125
137
esp_at_port_write_data (buffer , strlen ((char * )buffer ));
126
- printf ("YYYEEES Command <AT%s> executed successfully\r\n" , cmd_name );
138
+ printf ("Command <AT%s> executed successfully\r\n" , cmd_name );
127
139
if (!at_sync_sema ) {
128
140
at_sync_sema = xSemaphoreCreateBinary ();
129
141
assert (at_sync_sema != NULL );
@@ -162,22 +174,8 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
162
174
esp_netif_action_start (s_netif , 0 , 0 , 0 );
163
175
esp_netif_action_connected (s_netif , 0 , 0 , 0 );
164
176
165
- // receive input data
166
- // while(xSemaphoreTake(at_sync_sema, portMAX_DELAY)) {
167
- // int len = esp_at_port_read_data(buffer, sizeof(buffer) - 1);
168
- // if (len > 0) {
169
- // buffer[len] = '\0'; // null-terminate the string
170
- // printf("Received data: %s\n", buffer);
171
- // } else {
172
- // printf("No data received or error occurred.\n");
173
- // continue;
174
- // }
175
- // }
176
-
177
- // uart_write_bytes(g_at_cmd_port, "CONNECT\r\n", strlen("CONNECT\r\n"));
178
- while (1 ) {
179
- vTaskDelay (pdMS_TO_TICKS (1000 ));
180
- printf ("-" );
177
+ while (xSemaphoreTake (at_sync_sema , pdMS_TO_TICKS (1000 )) == pdFALSE ) {
178
+ printf ("." );
181
179
}
182
180
return ESP_AT_RESULT_CODE_OK ;
183
181
}
@@ -191,7 +189,6 @@ static uint8_t at_test_cereg(uint8_t *cmd_name)
191
189
static uint8_t at_query_cereg (uint8_t * cmd_name )
192
190
{
193
191
printf ("%s: AT command <AT%s> is executed\r\n" , __func__ , cmd_name );
194
- // static uint8_t buffer[] = "+CEREG: 0,1,2,3,4,5\r\n";
195
192
static uint8_t buffer [] = "+CEREG: 7,8\r\n" ;
196
193
esp_at_port_write_data (buffer , sizeof (buffer ));
197
194
return ESP_AT_RESULT_CODE_OK ;
@@ -209,7 +206,6 @@ static uint8_t at_exe_cereg(uint8_t *cmd_name)
209
206
return ESP_AT_RESULT_CODE_OK ;
210
207
}
211
208
212
- /* HTTP Server handlers */
213
209
static esp_err_t hello_get_handler (httpd_req_t * req )
214
210
{
215
211
const char * resp_str = "Hello from ESP-AT HTTP Server!" ;
@@ -405,9 +401,6 @@ static const esp_at_cmd_struct at_custom_cmd[] = {
405
401
{"+PPPD" , at_test_cmd_test , at_query_cmd_test , at_setup_cmd_test , at_exe_cmd_test },
406
402
{"+CEREG" , at_test_cereg , at_query_cereg , at_setup_cereg , at_exe_cereg },
407
403
{"+HTTPD" , at_test_httpd , at_query_httpd , at_setup_httpd , at_exe_httpd },
408
- /**
409
- * @brief You can define your own AT commands here.
410
- */
411
404
};
412
405
413
406
bool esp_at_custom_cmd_register (void )
0 commit comments