SIM900 AT来电显示开启,一些代码
/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and
send a http request to the website, upload data to pachube.com by TCP connection, The microcontrollers Digital Pin 7 and hence allow unhindered
communication with GPRS Shield using SoftSerial Library.
IDE: Arduino 1.0 or later
Replace the following items in the code:
1.Phone number, don't forget add the country code
2.Replace the Access Point Name
3. Replace the Pachube API Key with your personal ones assigned
to your account at cosm.com
*/ #include <SoftwareSerial.h>
#include <String.h> SoftwareSerial mySerial(, ); void setup()
{
mySerial.begin(); // the GPRS baud rate
Serial.begin(); // the GPRS baud rate
delay();
} void loop()
{
//after start up the program, you can using terminal to connect the serial of gprs shield,
//if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
//if input 'd' in the terminal, it will execute DialVoiceCall(), etc. if (Serial.available())
switch(Serial.read())
{
case 't':
SendTextMessage();
break;
case 'd':
DialVoiceCall();
break;
case 'h':
SubmitHttpRequest();
break;
case 's':
Send2Pachube();
break;
}
if (mySerial.available())
Serial.write(mySerial.read());
} ///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay();
mySerial.println("AT + CMGS = \"+8613616761237\"");//send sms message, be careful need to add a country code before the cellphone number
delay();
mySerial.println("A test message!");//the content of the message
delay();
mySerial.println((char));//the ASCII code of the ctrl+z is 26
delay();
mySerial.println();
} ///DialVoiceCall
///this function is to dial a voice call
void DialVoiceCall()
{
mySerial.println("ATD+8613616761237;");//dial the number
delay();
mySerial.println();
} ///SubmitHttpRequest()
///this function is submit a http request
///attention:the time of delay is very important, it must be set enough
void SubmitHttpRequest()
{
mySerial.println("AT+CSQ");
delay(); ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too. mySerial.println("AT+CGATT?");
delay(); ShowSerialData(); mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(); ShowSerialData(); mySerial.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
delay(); ShowSerialData(); mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(); ShowSerialData(); mySerial.println("AT+HTTPINIT"); //init the HTTP request delay();
ShowSerialData(); mySerial.println("AT+HTTPPARA=\"URL\",\"http://122.226.151.4:6543/DHT11data.ashx?c=20.1&h=45.5\"");// setting the httppara, the second parameter is the website you want to access
delay(); ShowSerialData(); mySerial.println("AT+HTTPACTION=0");//submit the request
delay();//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
//while(!mySerial.available()); ShowSerialData(); mySerial.println("AT+HTTPREAD");// read the data from the website you access
delay(); ShowSerialData(); mySerial.println("");
delay();
} ///send2Pachube()///
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
void Send2Pachube()
{
mySerial.println("AT+CGATT?");
delay(); ShowSerialData(); mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
delay(); ShowSerialData(); mySerial.println("AT+CIICR");//bring up wireless connection
delay(); ShowSerialData(); mySerial.println("AT+CIFSR");//get local IP adress
delay(); ShowSerialData(); mySerial.println("AT+CIPSPRT=0");
delay(); ShowSerialData(); mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
delay(); ShowSerialData(); mySerial.println("AT+CIPSEND");//begin send data to remote server
delay();
ShowSerialData();
String humidity = "";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
String moisture = "";//you can replace these four variable to the real sensor data in your project
String temperature = "";//
String barometer = "60.56";//
mySerial.print("{\"method\": \"put\",\"resource\": \"/feeds/42742/\",\"params\"");//here is the feed you apply from pachube
delay();
ShowSerialData();
mySerial.print(": {},\"headers\": {\"X-PachubeApiKey\":");//in here, you should replace your pachubeapikey
delay();
ShowSerialData();
mySerial.print(" \"_cXwr5LE8qW4a296O-cDwOUvfddFer5pGmaRigPsiO0");//pachubeapikey
delay();
ShowSerialData();
mySerial.print("jEB9OjK-W6vej56j9ItaSlIac-hgbQjxExuveD95yc8BttXc");//pachubeapikey
delay();
ShowSerialData();
mySerial.print("Z7_seZqLVjeCOmNbEXUva45t6FL8AxOcuNSsQS\"},\"body\":");
delay();
ShowSerialData();
mySerial.print(" {\"version\": \"1.0.0\",\"datastreams\": ");
delay();
ShowSerialData();
mySerial.println("[{\"id\": \"01\",\"current_value\": \"" + barometer + "\"},");
delay();
ShowSerialData();
mySerial.println("{\"id\": \"02\",\"current_value\": \"" + humidity + "\"},");
delay();
ShowSerialData();
mySerial.println("{\"id\": \"03\",\"current_value\": \"" + moisture + "\"},");
delay();
ShowSerialData();
mySerial.println("{\"id\": \"04\",\"current_value\": \"" + temperature + "\"}]},\"token\": \"lee\"}"); delay();
ShowSerialData(); mySerial.println((char));//sending
delay();//waitting for reply, important! the time is base on the condition of internet
mySerial.println(); ShowSerialData(); mySerial.println("AT+CIPCLOSE");//close the connection
delay();
ShowSerialData();
} void ShowSerialData()
{
while(mySerial.available()!=)
Serial.write(mySerial.read());
}
#include <SoftwareSerial.h>
#include <String.h> SoftwareSerial GPRS(, );
String currentLine = ""; // string to hold the text from server
String triggerNo="";
String mobile = "";
boolean readingNo=false;
long lastTriggerTime=;
boolean fireing=false;
int led=;
void setup()
{
GPRS.begin(); // the GPRS baud rate
Serial.begin(); // the GPRS baud rate
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
delay();
powerUpOrDown();
}
void loop()
{
if(fireing){
if( millis() - lastTriggerTime >= * ){
Serial.println("stop fire!");
digitalWrite(led,LOW);
fireing=false;
}else{
return;
}
} while(GPRS.available()){
char inChar=GPRS.read();
currentLine +=inChar; if(inChar=='\n')currentLine=""; if(currentLine.endsWith( "+CLIP: \"")){
readingNo=true;
mobile="";
} if(readingNo){ if(inChar !=','){
if(inChar !='"')mobile+=inChar;
}else{
readingNo=false;
Serial.println(mobile);
if(mobile==triggerNo){
lastTriggerTime=millis();
Serial.println("fire!!");
fireing=true; currentLine="";
mobile="";
delay();
digitalWrite(led,HIGH);
delay(); GPRS.println("ATH");
while(GPRS.available()){
GPRS.read();
} } }
}
}
} void powerUpOrDown()
{
pinMode(, OUTPUT);
digitalWrite(,LOW);
delay();
digitalWrite(,HIGH);
delay();
digitalWrite(,LOW);
delay();
}
发送:AT+COLP=1,设置被叫号码显示
参考:
http://www.51hei.com/bbs/dpj-30516-1.html
http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0
SIM900 AT来电显示开启,一些代码的更多相关文章
- [android] 手机卫士来电显示号码归属地
继续N天前的项目 开启服务监听手机来电,查询数据库,显示归属地 详细内容可以参考这篇博文:http://www.cnblogs.com/taoshihan/p/5331232.html Address ...
- gvim如何显示html属性代码提示? vim 如何显示 javascript属性及方法提示?
gvim如何显示html属性代码 可以在vim中 显示 html, css, js等的属性/方法 提示: 一是: 在 ~/.vim/after/syntax/ 目录中 安装 css-color.vim ...
- C# WinForm中 让控件全屏显示的实现代码
夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...
- 关于Hexo,Next主题的‘下一页’、‘上一页’按钮错误显示为html代码 的解决方法
关于Next主题的'下一页'.'上一页'按钮错误显示为html代码的解决方法 我在建立自己的博客过程中遇到了页面'下一页'和'上一页'按钮显示为html代码<i class="fa f ...
- 【OpenCV练习】简单显示图片的代码
今天依照网上的教程尝试了一下最基本的图片显示. 首先想说一下编译时出现的问题,开始时在编译时会出现无法识别cvReleaseImage的情况,是因为没有在配置中包含相应的core的库文件. 加进去就解 ...
- 点击自动显示/隐藏DIV代码。(简单实用)
注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 很多时候我们需要将DIV的信息默认为隐藏状态,只有当用户点击时才显示DIV中包含的提示文字.这类效果在互联网上应用得很多,但实现的方 ...
- 在word中显示漂亮的代码
在word中粘贴或写代码时,通常得不到想要的格式,可用‘Notepad++’工具实现. 步骤: (1)安装Notepad++软件,把代码粘贴进去,选择菜单栏中的语言,然后选择相应代码语言,如P-> ...
- 单色VGA显示verilogHDL通用代码
今天做VGA,真是拼凑了好久啊.唉,总算完成了. 本来想偷懒移植,最后还是自己写的代码. //2015/12/13 //designer : pengxiaoen //function : vga c ...
- vs 2010调用matlab dll显示窗口核心代码
matlab代码: figure('NumberTitle','off','menubar','none','toolbar','none','name','Topo Image'); x=0:pi/ ...
随机推荐
- Linux系统之更改默认块大小
查看操作系统块大小:#tune2fs -l /dev/sda1 |grep 'Block size' ( tune2fs -l /dev/sda1可以查看更多相关文件 ...
- inotify用法简介及结合rsync实现主机间的文件实时同步
一.inotify简介 inotify是Linux内核2.6.13 (June 18, 2005)版本新增的一个子系统(API),它提供了一种监控文件系统(基于inode的)事件的机制,可以监控文件系 ...
- ant使用备忘
ant是一个脚本构建工具,可能就是持续集成里面所需要的构建工具. 如果使用eclipse,里面会自带有ant工具,不需要再安装了,创建一个build.xml(或者其他的名字都可以),使用ant来运行就 ...
- 更新日志(建议升级到2017.1.18a) && 更新程序的方法
更新程序的步骤: 1,在控制面板里点击备份当前数据库文件到磁盘,把当天获取的信息从内存写到磁盘/存储卡.2,下载最新版的源码 wget -O "infopi.zip" " ...
- Nexus 按项目类型分配不同的工厂来发布不同 项目
但是有时候,一个公司会有很多项目[crm,oa,erp]等等的项目.如果把这些项目全部都放到releases或者snapshots中的话会有点混乱.比较好的办法是,按项目来分.每个项目一个工厂:cms ...
- Spring RabbitMQ 延迟队列
一.说明 在实际业务场景中可能会用到延时消息发送,例如异步回调失败时的重发机制. RabbitMQ本身不具有延时消息队列的功能,但是可以通过rabbitmq-delayed-message-excha ...
- 使用Maven部署构件至私服
--------------------siwuxie095 使用 Maven 部署构件至私服 1.部署构件到 Nexu ...
- 【校招面试 之 C/C++】第6题 C++深拷贝与浅拷贝
1.两个的区别(1)在未定义显示拷贝构造函数的情况下,系统会调用默认的拷贝函数——即浅拷贝,它能够完成成员的一一复制.当数据成员中没有指针时,浅拷贝是可行的: 但当数据成员中有指针时,如果采用简单的浅 ...
- log4j每天,每小时产生一日志文件
log4j每天,每小时产生一日志文件 2016年08月05日 14:14:33 阅读数:6254 一.之前的文章中有log4j的相关配置以及属性的介绍,下面我们先把配置列出来: log4j.roo ...
- Ubuntu-18.04Python2与Python3自由切换
一.配置ssh链接 安装openssh-server devops@devops-virtual-machine:~$ sudo apt-get install openssh-server 二.安装 ...