EC800M module optimization supports server IP and server port parameter transmission when establishing TCP.

This commit is contained in:
aixiao 2024-04-14 22:41:42 +08:00
parent 436bd377f9
commit d5748a02c1
3 changed files with 15 additions and 7 deletions

View File

@ -85,7 +85,7 @@ int _4G_uart_read_string_until_response(char *DATA, int *DATA_LEN, const char *e
} }
} }
int EC800M_4G_INIT() int EC800M_4G_INIT(char *IP, int PORT)
{ {
// AT+CFUN=1,1 // AT+CFUN=1,1
//uart_send_string("AT+CFUN=1,1\r\n"); //uart_send_string("AT+CFUN=1,1\r\n");
@ -151,9 +151,11 @@ int EC800M_4G_INIT()
printf("%s %d\n", _4G_DATA, _4G_DATA_LEN); printf("%s %d\n", _4G_DATA, _4G_DATA_LEN);
// AT+QIOPEN=1,0,"TCP","47.240.75.93",8009,0,1 // AT+QIOPEN=1,0,"TCP","47.240.75.93",8009,0,1
uart_send_string("AT+QIOPEN=1,0,\"TCP\",\"123.60.29.178\",8009,0,1\r\n"); char QIOPEN[270] = { 0 };
sprintf(QIOPEN, _QIOPEN, IP, PORT);
uart_send_string(QIOPEN);
if (-1 == _4G_uart_read_string_until_response(_4G_DATA, &_4G_DATA_LEN, "0,0")) { if (-1 == _4G_uart_read_string_until_response(_4G_DATA, &_4G_DATA_LEN, "0,0")) {
printf("EC800M Module 4G \"AT+QIOPEN=1,0,\"TCP\",\"123.60.29.178\",8009,0,1\r\n\" Timeout!\n"); printf("EC800M Module 4G AT+QIOPEN Timeout!\n");
return -1; return -1;
} }
printf("%s %d\n", _4G_DATA, _4G_DATA_LEN); printf("%s %d\n", _4G_DATA, _4G_DATA_LEN);
@ -297,12 +299,12 @@ int establish_tcp_connection()
return 0; return 0;
} }
int _r = EC800M_4G_INIT(); // 第一次建立TCP int _r = EC800M_4G_INIT(SERVER_HOST, SERVER_POER); // 第一次建立TCP
int retry_count = 0; // 重试计数器 int retry_count = 0; // 重试计数器
while (_r == -1 && retry_count < TCP_MAX_RETRY) { while (_r == -1 && retry_count < TCP_MAX_RETRY) {
printf("TCP establishment failed! Retrying...\n"); printf("TCP establishment failed! Retrying...\n");
_r = EC800M_4G_INIT(); // 重新建立TCP连接 _r = EC800M_4G_INIT(SERVER_HOST, SERVER_POER); // 重新建立TCP连接
retry_count++; retry_count++;
sleep_ms(9000); // 等待一段时间后重试 sleep_ms(9000); // 等待一段时间后重试
} }
@ -370,7 +372,7 @@ void EC800M_4G(void *p)
EC800M_4G_RECV("aixiao.me\r\n"); EC800M_4G_RECV("aixiao.me\r\n");
// GPS Module
EC800M_GPS(NULL); EC800M_GPS(NULL);
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时 vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时

View File

@ -33,7 +33,12 @@
#define EC800M_4G_UART_BAUD_RATE 115200 #define EC800M_4G_UART_BAUD_RATE 115200
#define TCP_MAX_RETRY 3 // TCP建立最大重试次数 #define TCP_MAX_RETRY 3 // TCP建立最大重试次数
#define _4G_DATA_LENGTH 8192 #define _4G_DATA_LENGTH 8192 // 数组最大长度
#define SERVER_HOST "123.60.29.178" // TCP服务器IP
#define SERVER_POER 8009 // TCP服务器端口
#define _QIOPEN "AT+QIOPEN=1,0,\"TCP\",\"%s\",%d,0,1\r\n"
extern void EC800M_4G(void *p); extern void EC800M_4G(void *p);

View File

@ -29,6 +29,7 @@ void Led_Blinky(void *pvParameters)
while (1) { while (1) {
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 1); gpio_put(LED_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(500)); vTaskDelay(pdMS_TO_TICKS(500));
gpio_put(LED_PIN, 0); gpio_put(LED_PIN, 0);
} }