|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本文转载于欧时电子
分享一下AT指令控制SIM868模块实现往服务器上传数据:
发送:AT+CIPSTART="TCP","xxx.xxx.xxx","N"\r\n
返回:OK
这里的xxx.xxx.xxx代表要连接的服务器地址
N代表服务器端的TCP端口号
发送:AT+CIPSTATUS\r\n
返回:CONNECT OK
发送:AT+CIPSTATUS\r\n
返回:>
发送:Hello
返回:Hello
发送:0x1A
返回:SEND OK
发送:AT+CIPCLOSE\r\n
返回:CLOSE OK
发送:AT+CIPSHUT\r\n
返回:SHUT OK
代码实现如下:
uint8_t sendCommand(char *Command, char *Response, unsigned long Timeout, unsigned char Retry)
{
uint8_t i;
uint16_t Time_Cont = 0;
USART1_CLR_Buf();
for(i = 0; i < Retry; i++){
UART1_SendStr((u8 *)Command);
Time_Cont = 0;
while (Time_Cont < Timeout){
delay_ms(100);
Time_Cont += 100;
if (strstr((char *)USART1_RX_BUF, Response) != NULL){
USART1_CLR_Buf();
return Success;
}
}
USART1_CLR_Buf();
}
USART1_CLR_Buf();
return Failure;
}
void GPRS_support_Initialization(void)
{
if(sendCommand("AT\r\n", "OK\r\n", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CGCLASS=\"B\"\r\n", "OK\r\n", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
// TCP/IP协议 net 接入点
if(sendCommand("AT+CGDCONT=1,\"IP\",\"CMNET\"\r\n", "OK", 3000, 2) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CGATT=1\r\n", "OK\r\n", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
}
void connect_TCP_server_by_GPRS(void)
{
char sendCom[2] = {0x1A};
// if(sendCommand("AT+CGACT=1,1\r\n", "OK\r\n", 3000, 10) == Success){
// asm("nop");
// asm("nop");
// }else{
// errorLog();
// }
// delay_ms(100);
if(sendCommand("AT+CIPSTART=\"TCP\",\"xxx.xx.xx\",\"N\"\r\n", "OK\r\n", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CIPSTATUS\r\n", "CONNECT OK", 3000, 20) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CIPSEND\r\n", ">", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("Hello\r\n", "Hello", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand(sendCom, "SEND OK", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CIPCLOSE\r\n", "CLOSE OK", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
if(sendCommand("AT+CIPSHUT\r\n", "SHUT OK", 3000, 10) == Success){
asm("nop");
asm("nop");
}else{
errorLog();
}
delay_ms(100);
} |
|