File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < SoftwareSerial.h>
2+
3+ SoftwareSerial s1 (1 ,2 );
4+ String num=" " ;
5+ String con=" " ;
6+ int del=27 ;
7+ String data=" " ;
8+
9+ void setup () {
10+ s1.begin (9600 );
11+ }
12+
13+ void sendSms (String phonecode ,String content) {
14+ delay (del*1000 );
15+ s1.println (" AT+CMGS=\" " +phonecode+" \" " );
16+ delay (500 );
17+ s1.print (content);
18+ s1.write (0x1A );
19+ }
20+
21+ void met (String raw){
22+ String type,res;
23+ int i,j;
24+ for (i=0 ;i<=3 ;i++){
25+ type+=raw[i];
26+ }
27+ for (j=4 ;raw[j]!=' >' ;j++){
28+ res+=raw[j];
29+ }
30+ if (type==" num<" ){
31+ num=res;
32+ }else if (type==" con<" ){
33+ con=res;
34+ }
35+ }
36+
37+ void loop (){
38+ while (s1.available ()>0 ){
39+ if (char (s1.read ())==' X' ){
40+ if (num!=" " &&con!=" " ){
41+ sendSms (num,con);
42+ }
43+ }else {
44+ data+=char (s1.read ());
45+ if (char (s1.read ())==' >' ){
46+ met (data);
47+ data=" " ;
48+ }
49+ delay (7 );
50+ }
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments