SIM900 HTTP GET联通卡卡正常,换移动卡就通讯不成功
本帖最后由 gadio 于 2014-1-12 11:43 编辑int8_t GPRS_BearerProfile(uint8_t *buf,uint8_t *apn)
{
uint8_t ret,ch,i;
delay_ms(100);
UART3_BufferClear();
USART3_PutString("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r\n");
GPRS_WaitFor("OK\r\n",1000);
delay_ms(500);
USART3_PutString("AT+SAPBR=3,1,\"APN\",\"");
USART3_PutString((char*)apn);
USART3_PutString("\"\r\n");
GPRS_WaitFor("OK\r\n",2000);
delay_ms(500);
USART3_PutString("AT+SAPBR=1,1\r\n");
GPRS_WaitFor("OK\r\n",10000);
delay_ms(500);
USART3_PutString("AT+SAPBR=2,1\r\n");
UART3_BufferClear();
delay_ms(500);
ret = GPRS_WaitFor("+SAPBR:",3000);
if(ret)
{
GPRS_Response(24);
if(res_string_index < 8)
return 0;
if(res_string_index >22)
res_string_index = 22;
for(ch=0;ch<res_string_index;ch++)
if(res_string=='\"')
break;
ch++;
i=0;
for(;ch<res_string_index;ch++)
{
if(res_string!='\"')
buf = res_string;
else
{
buf='\0';
res_string_index=i;
break;
}
i++;
}
}
return res_string_index;
}
int8_t GPRS_ContextClose(void)
{
UART3_BufferClear();
delay_ms(100);
USART3_PutString("AT+SAPBR=0,1\r\n");
return GPRS_WaitFor("OK\r\n",1000);
}
uint16_t GPRS_HTTP_GET(uint8_t *dns, uint8_t *buf)
{
uint8_t ret,ch,ResultCode;
uint16_t length,index;
uint8_t timeout = 50;
uint8_t tmp_buf;
delay_ms(100);
UART3_BufferClear();
USART3_PutString("AT+HTTPINIT\r\n");
GPRS_WaitFor("OK\r\n",1000);
UART3_BufferClear();
delay_ms(100);
USART3_PutString("AT+HTTPPARA=\"CID\",1\r\n");
GPRS_WaitFor("OK\r\n",1000);
UART3_BufferClear();
delay_ms(100);
USART3_PutString("AT+HTTPPARA=\"URL\",\"");
USART3_PutString((char *)dns);
USART3_PutString("\"\r\n");
GPRS_WaitFor("OK\r\n",1000);
delay_ms(100);
UART3_BufferClear();
USART3_PutString("AT+HTTPACTION=0\r\n");
GPRS_WaitFor("OK\r\n",1000);
while(timeout--)
{
delay_ms(100);
ret = GPRS_WaitFor("+HTTPACTION:0,",1000);
if(ret)
break;
}
delay_ms(10);
tmp_buf = USART3_GetChar();
tmp_buf = USART3_GetChar();
tmp_buf = USART3_GetChar();
tmp_buf = '\0';
ResultCode = memcmp(tmp_buf,"200",3);
printf("ResultCode=%d,%s\r\n",ResultCode,tmp_buf);
if(ret && (ResultCode == 0))
{
delay_ms(100);
memset((char*)tmp_buf,'\0',4);
UART3_BufferClear();
USART3_PutString("AT+HTTPREAD\r\n");
ret = GPRS_WaitFor("+HTTPREAD:",8000);
//printf("ret = %d\r\n",ret);
if(ret)
{
//delay_ms(10);
GPRS_WaitForNotRoll("\r\n",500);
GPRS_ResponseNotLength();
memcpy(tmp_buf,res_string,res_string_index);
length = atoi((char*)tmp_buf);
//printf("buf = %s ,length = %d\r\n",tmp_buf,length);
if(GPRS_WaitForNotRoll("OK\r\n",10000))
{
index = 0;
do
{
ch = USART3_GetChar();
if(ch != '\r' && ch != '\n')buf = ch;
}while(ch);
}
}
}
delay_ms(100);
UART3_BufferClear();
USART3_PutString("AT+HTTPTERM\r\n");
GPRS_WaitFor("OK\r\n",1000);
delay_ms(100);
return length;
}
串口通讯记录:
AT+SAPBR=3,1,"Contype","GPRS"
OK
AT+SAPBR=3,1,"APN","CMNET"
OK
AT+SAPBR=1,1
OK
AT+SAPBR=2,1
+SAPBR: 1,1,"10.149.77.103"
OK
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","http://m.weather.com.cn/data/101280601.html"
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,601,0 // 这里返回601 ,正常为200,以及收到的json格式数据
AT+HTTPTERM
OK
AT+SAPBR=0,1
页:
[1]