AT+SAPBR=3,1,"APN","UNINET" //CMNET移动 CNNET电信 UNINET联通 |
AT+SAPBR=1,1 //激活网络 一定要等到ok返回,否则出错 |
AT+HTTPINIT //初始化http网络 |
AT+HTTPPARA="CID",1 //设置回话参数 |
//设置域名给让模块解析 AT+HTTPPARA="URL","www.xiongyuchun.xyz:9999/Api/addDreamValueAPI.aspx?id=1&lng=115.40&lat=27.08" |
AT+HTTPACTION=0 //开始发送请求并等待服务器响应 最后程序最后确认响应内容是否正确 |
参考文章:http://www.openedv.com/forum.php?mod=viewthread&tid=232045&page=1
AT+CLBS=1,1
+CLBS: 0,113.333941,23.308106,550
+CLBS: 0,113.333941,23.308106,550 //这就得到了想要的定位数据,这里直接输出的是经纬度。其中113.333941是经度,23.308106是纬度,
//SIM800C主测试程序
void sim800c_test(void)
{
u8 key=0;
u8 timex=0;
u8 sim_ready=0;
// u8 start_flag = 0;
POINT_COLOR=RED;
Show_Str_Mid(0,30,"ATK-SIM800C 测试程序",16,240); //LCD显示
while(sim800c_send_cmd("AT","OK",100))//检测是否应答AT指令
{
Show_Str(40,55,200,16,"未检测到模块!!!",16,0);
delay_ms(800);
LCD_Fill(40,55,200,55+16,WHITE);
Show_Str(40,55,200,16,"尝试连接模块...",16,0);
delay_ms(400);
}
LCD_Fill(40,55,200,55+16,WHITE);
key+=sim800c_send_cmd("ATE0","OK",200);//不回显
sim800c_mtest_ui(40,20);
ntp_update();//网络更新
while(1)
{
delay_ms(10);
sim_at_response(1);//检查GSM模块发送过来的数据,及时上传给电脑
if(sim_ready)//SIM卡就绪.
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
// start_flag =!start_flag;
// if(start_flag)
// {
GPS_Location(); //定位测试
// }
sim800c_mtest_ui(40,30);
timex=0;
}
}
if(timex==0) //2.5秒左右更新一次
{
if(sim800c_gsminfo_show(40,225)==0)sim_ready=1;
else sim_ready=0;
}
if((timex%20)==0)LED0=!LED0;//200ms闪烁
timex++;
}
}
void GPS_Location()
{
char *buf;
char *p,*p1,*p2;
char longitude[10],latitude[10];
buf=mymalloc(SRAMIN,80);//申请80个字节的内存
p=mymalloc(SRAMIN,50);//申请50个字节的内存
if(buf==NULL||p==NULL)
{
printf("buf=mymalloc 失败!!!!!!!!!!\r\n");
}
//查询经纬度信息
while(sim800c_send_cmd("AT+CLBS=1,1","+CLBS",200))
{
printf("查询经纬度失败\r\n");
}
//+CLBS
p1=(u8*)strstr((const char*)USART3_RX_BUF,","); //第一个逗号开始
p2=(u8*)strstr((const char*)(p1+1),","); //第二个逗号开始
p2[0]=0;
sprintf((char*)longitude,"%s",p1+1); //经度
p1=(u8*)strstr((const char*)(p2+1),","); //第三个逗号开始
p1[0]=0;
sprintf((char*)latitude,"%s",p2+1); //纬度
USART3_RX_STA=0;
sprintf((char*)buf,"AT+HTTPPARA=\"URL\",\"www.xiongyuchun.xyz:9999/Api/addDreamValueAPI.aspx?id=1&lng=%s&lat=%s\"",longitude,latitude); //经纬度作为http请求参数
sim800c_send_cmd(buf,"OK",200);
sim800c_send_cmd("AT+HTTPACTION=0","OK",200);
printf("%s\r\n",buf); //显示域名
myfree(SRAMIN,buf);
myfree(SRAMIN,p);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000); //延时4s
}
//gprs网络初始化
void ntp_update(void)
{
u8 ;
while(sim800c_send_cmd("AT+SAPBR=3,1,\"Contype\",\"GPRS\"","OK",200))//配置承载场景1
{
printf("配置承载场景1失败\r\n");
}
while(sim800c_send_cmd("AT+SAPBR=3,1,\"APN\",\"CMNET\"","OK",200))//设置为中国联通网络
{
printf("设置为中国联通网络失败\r\n");
}
while(sim800c_send_cmd("AT+SAPBR=1,1",0,200))//激活一个GPRS上下文
{
printf("激活一个GPRS上下文失败\r\n");
}
sim800c_send_cmd("AT+HTTPINIT","OK",200); //http初始化
sim800c_send_cmd("AT+HTTPPARA=\"CID\",1","OK",200); //设置http回话参数
}
https://download.csdn.net/download/shenlong1356/12453371