1919#include "esp_http_server.h"
2020#include "esp_timer.h"
2121
22- extern uint8_t g_at_cmd_port ;
23-
2422static uint8_t at_test_cmd_test (uint8_t * cmd_name )
2523{
2624 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
102100static SemaphoreHandle_t at_sync_sema = NULL ;
103101static void wait_data_callback (void )
104102{
105- static uint8_t buffer [1024 ] = {0 };
106- // xSemaphoreGive(at_sync_sema);
103+ static uint8_t buffer [1500 ] = {0 };
107104 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+ }
109123 esp_netif_receive (s_netif , buffer , len , NULL );
110124}
111125
112126static esp_err_t transmit (void * h , void * buffer , size_t len )
113127{
114- // struct eppp_handle *handle = h;
115128 printf ("transmit: %d bytes\n" , len );
116- // ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_INFO);
117129 esp_at_port_write_data (buffer , len );
118130 return ESP_OK ;
119131}
@@ -123,7 +135,7 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
123135 uint8_t buffer [64 ] = {0 };
124136 snprintf ((char * )buffer , 64 , "execute command: <AT%s> is executed\r\n" , cmd_name );
125137 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 );
127139 if (!at_sync_sema ) {
128140 at_sync_sema = xSemaphoreCreateBinary ();
129141 assert (at_sync_sema != NULL );
@@ -162,22 +174,8 @@ static uint8_t at_exe_cmd_test(uint8_t *cmd_name)
162174 esp_netif_action_start (s_netif , 0 , 0 , 0 );
163175 esp_netif_action_connected (s_netif , 0 , 0 , 0 );
164176
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 ("." );
181179 }
182180 return ESP_AT_RESULT_CODE_OK ;
183181}
@@ -191,7 +189,6 @@ static uint8_t at_test_cereg(uint8_t *cmd_name)
191189static uint8_t at_query_cereg (uint8_t * cmd_name )
192190{
193191 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";
195192 static uint8_t buffer [] = "+CEREG: 7,8\r\n" ;
196193 esp_at_port_write_data (buffer , sizeof (buffer ));
197194 return ESP_AT_RESULT_CODE_OK ;
@@ -209,7 +206,6 @@ static uint8_t at_exe_cereg(uint8_t *cmd_name)
209206 return ESP_AT_RESULT_CODE_OK ;
210207}
211208
212- /* HTTP Server handlers */
213209static esp_err_t hello_get_handler (httpd_req_t * req )
214210{
215211 const char * resp_str = "Hello from ESP-AT HTTP Server!" ;
@@ -405,9 +401,6 @@ static const esp_at_cmd_struct at_custom_cmd[] = {
405401 {"+PPPD" , at_test_cmd_test , at_query_cmd_test , at_setup_cmd_test , at_exe_cmd_test },
406402 {"+CEREG" , at_test_cereg , at_query_cereg , at_setup_cereg , at_exe_cereg },
407403 {"+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- */
411404};
412405
413406bool esp_at_custom_cmd_register (void )
0 commit comments