通过sim900短信收发控制stm32设备
2013-10-12 16:01
555 查看
通过sim900短信收发控制stm32设备或者自动发送数据到远程服务器上面
1.连接远程服务器关键步骤:
// "AT+CIPSTART="TCP","60.186.20.162","5002" 串口调试发送
GPRS_SendString(AT_CIPHEAD);
////1----GPRS 接收方式
GPRS_SendString("AT+CIPSTART=\"TCP\",\"60.186.20.162\",\"5002\"");
Delay_10ms(400);//延时要充分
2.发短信命令
GPRS_SendString("AT+CMGF=1");//set text format
Delay_10ms(20);
GPRS_SendString("AT+CSMP=17,167,0,241"); //set SMS format
Delay_10ms(20);
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGL=\"ALL\"");// read SMS
main()
{
GPRS_ON();
Start_GPRS()//sim900 软件开关
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGDA=\"DEL ALL\"");
Clear_GPRS_ReBuffer();
while(1)
{
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CPIN?");//查询SIM卡状态
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0) { break;}
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CSQ");//查询SIM卡状态
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0) { break;}
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+IPR=9600");
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0){break; }
}
while(1)
{ Clear_GPRS_ReBuffer();
GPRS_SendString(AT_CIPHEAD); ////1----GPRS 接收方式
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0){ break; }
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CIPSTART=\"TCP\",\"60.186.20.162\",\"5002\"");
Delay_10ms(400);//
if(strstr2(GPRS_ReBuffer,CONNECT_OK)!=0)
{
RFID_SendString("tsest sww !");
break;
}
}
while(1)
{
GPRS_SendString(AT_CIPSEND);
Delay_10ms(100);
GPRS_SendString("Welcome to hello world !");
GPRS_Send_Char(0x1A); //结束符
Delay_10ms(200);
Clear_GPRS_ReBuffer();
//自动发送短信给目标手机911
/*GPRS_SendString("AT+CMGS=\"110\"");//
Delay_10ms(20);
GPRS_SendString("911");
GPRS_Send_Char(0x1A);
Delay_10ms(200); */
//发送短信控制stm32或者控制它自动发送数据到服务器
GPRS_SendString("AT+CMGF=1");//set text format
Delay_10ms(20);
GPRS_SendString("AT+CSMP=17,167,0,241"); //set SMS format
Delay_10ms(20);
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGL=\"ALL\"");// read SMS
Delay_10ms(150);
if(strstr2(GPRS_ReBuffer,"+86119")!=0)
{
GPRS_SendString(AT_CIPSEND);
Delay_10ms(100);
GPRS_SendString("Welcome to SMS !");
GPRS_Send_Char(0x1A); //结束符
Delay_10ms(200);
GPRS_SendString("AT+CMGDA=\"DEL ALL\"");//删除短信ALL
}
Clear_GPRS_ReBuffer();
}
}
}
}
/******************************************************************************/
//函数void Start_GPRS()
//实现功能:启动或关断GPRS
///*拉低至少100ms,PA8*/
/******************************************************************************/
void Start_GPRS()//sim900 软件开关
{
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(100);//1000ms
GPIO_SetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(200);//5000ms
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(2500);//5000ms
}
void GPRS_ON() //sim900电源总开关
{
GPIO_SetBits(GPIOD, GPIO_Pin_4);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);//sim900_EN 硬开关
Delay_10ms(200);
}
1.连接远程服务器关键步骤:
// "AT+CIPSTART="TCP","60.186.20.162","5002" 串口调试发送
GPRS_SendString(AT_CIPHEAD);
////1----GPRS 接收方式
GPRS_SendString("AT+CIPSTART=\"TCP\",\"60.186.20.162\",\"5002\"");
Delay_10ms(400);//延时要充分
2.发短信命令
GPRS_SendString("AT+CMGF=1");//set text format
Delay_10ms(20);
GPRS_SendString("AT+CSMP=17,167,0,241"); //set SMS format
Delay_10ms(20);
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGL=\"ALL\"");// read SMS
main()
{
GPRS_ON();
Start_GPRS()//sim900 软件开关
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGDA=\"DEL ALL\"");
Clear_GPRS_ReBuffer();
while(1)
{
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CPIN?");//查询SIM卡状态
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0) { break;}
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CSQ");//查询SIM卡状态
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0) { break;}
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+IPR=9600");
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0){break; }
}
while(1)
{ Clear_GPRS_ReBuffer();
GPRS_SendString(AT_CIPHEAD); ////1----GPRS 接收方式
Delay_10ms(100);
if(strstr2(GPRS_ReBuffer,"OK")!=0){ break; }
}
while(1)
{
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CIPSTART=\"TCP\",\"60.186.20.162\",\"5002\"");
Delay_10ms(400);//
if(strstr2(GPRS_ReBuffer,CONNECT_OK)!=0)
{
RFID_SendString("tsest sww !");
break;
}
}
while(1)
{
GPRS_SendString(AT_CIPSEND);
Delay_10ms(100);
GPRS_SendString("Welcome to hello world !");
GPRS_Send_Char(0x1A); //结束符
Delay_10ms(200);
Clear_GPRS_ReBuffer();
//自动发送短信给目标手机911
/*GPRS_SendString("AT+CMGS=\"110\"");//
Delay_10ms(20);
GPRS_SendString("911");
GPRS_Send_Char(0x1A);
Delay_10ms(200); */
//发送短信控制stm32或者控制它自动发送数据到服务器
GPRS_SendString("AT+CMGF=1");//set text format
Delay_10ms(20);
GPRS_SendString("AT+CSMP=17,167,0,241"); //set SMS format
Delay_10ms(20);
Clear_GPRS_ReBuffer();
GPRS_SendString("AT+CMGL=\"ALL\"");// read SMS
Delay_10ms(150);
if(strstr2(GPRS_ReBuffer,"+86119")!=0)
{
GPRS_SendString(AT_CIPSEND);
Delay_10ms(100);
GPRS_SendString("Welcome to SMS !");
GPRS_Send_Char(0x1A); //结束符
Delay_10ms(200);
GPRS_SendString("AT+CMGDA=\"DEL ALL\"");//删除短信ALL
}
Clear_GPRS_ReBuffer();
}
}
}
}
/******************************************************************************/
//函数void Start_GPRS()
//实现功能:启动或关断GPRS
///*拉低至少100ms,PA8*/
/******************************************************************************/
void Start_GPRS()//sim900 软件开关
{
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(100);//1000ms
GPIO_SetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(200);//5000ms
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
Delay_10ms(2500);//5000ms
}
void GPRS_ON() //sim900电源总开关
{
GPIO_SetBits(GPIOD, GPIO_Pin_4);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);//sim900_EN 硬开关
Delay_10ms(200);
}
相关文章推荐
- 利用Android Lost通过互联网或短信远程控制安卓设备
- 最近做的app,可以通过手机收发短信控制plc和变频器
- PC机控制短信收发设备原理及实现(1)
- 利用Android Lost通过互联网或短信远程控制安卓设备
- 如何用java语言控制短信设备实现短信收发?
- SIM900/SIM900A 模块实现收发短信,打电话
- 【安卓笔记】通过发送特定的短信远程控制手机
- STM32通过SIM800L向yeelink端上传数据
- 通过手机短信控制电脑
- 做一个项目,需要使用单片机控制GSM模块收发短信
- 编写了一个通过手机短信平台收发短信的软件
- 通过ADB控制多台Android设备
- 9C51单片机(特别是AT89S52)控制GSM模块TC35收发短信的程序
- STM32 控制GSM模块收发信息 F407 discovery
- sim900芯片—GPRS使用C语言接电话和收短信应用程序
- 通过免费手机短信来控制电脑---“执行者”介绍
- stm32与sim900之GPRS通信(电脑串口与SIM900通信)
- PHP通过php_dio扩展控制SIM800 GPRS模块模拟HTTP POST提交表单
- 关于stm32 控制SIM900A的控制心得与体会
- socat:通过网络控制串口设备案例分析