int
val;
//定義變量val
#define MAXCHAR 81
char
aa[MAXCHAR];
int
j=0;
int
g_timeout=0;
int
Gas_Sensors = A0;
////////////////////////////////////////////////////
char
ATE0[]=
"ATE0"
;
char
CREG_CMD[]=
"AT+CREG?"
;
char
SMS_send[]=
"AT+CMGS=18"
;
char
ATCN[]=
"AT+CNMI=2,1"
;
char
CMGF0[]=
"AT+CMGF=0"
;
char
CMGF1[]=
"AT+CMGF=1"
;
char
CMGR[12]=
"AT+CMGR=1"
;
char
CMGD[12]=
"AT+CMGD=1"
;
/*************************************************/
//#define SEND_MESSA_TO_YOUR "at+cmgs=\"18382117086\"\r\n"http://發(fā)短信接收的手機(jī)號碼
#define CALL_YOU_TELNUMBER "ATD18382117086;\r\n"http://打電話接受的手機(jī)號碼
//功能模塊矯正完畢,請放心使用,。
char
*Num1 =
"The liquefied gas value is 200~300, the normal value has exceeded. Please check the liquefied gas is closed.\n openjumper "
;
//當(dāng)前液化氣氣體值為200~300,,已超過正常值。請檢查液化氣,。
char
*Num2 =
"The liquefied gas value is 300~700, many have more than normal value. Easy to cause fire and poisoning please close the liquefied petroleum gas immediately.\n openjumper "
;
//當(dāng)前液化氣氣體值為300~700,,已超過正常值很多。容易引起火災(zāi)和中毒請立即關(guān)閉液化氣。
char
*Num3 =
"The liquefied gas value has exceeded 700, now that the range of extreme danger, easy to cause fire and poisoning please close the liquefied petroleum gas immediately.\n openjumper "
;
//當(dāng)前液化氣值已超過700,,現(xiàn)在此范圍內(nèi)極度危險,,容易引起火災(zāi)和中毒請立即關(guān)閉液化氣。
char
*yy =
"at+cmgs=\"18382117086\"\r\n"
;
//發(fā)短信接收的手機(jī)號碼
//可以設(shè)置多個電話 格式如 char *yy = "at+cmgs=\"18382117086\"\r\n"; 即可.
/*************************************************/
int
readSerial(
char
result[])
{
int
i = 0;
while
(Serial.available() > 0)
{
char
inChar = Serial.read();
if
(inChar ==
'\n'
)
{
result
[i] =
'\0'
;
Serial.flush();
return
0;
}
if
(inChar!=
'\r'
)
{
result
[i] = inChar;
i++;
}
}
}
void
clearBuff(
void
)
//打電話發(fā)短信清除指令
{
for
(j=0;j<MAXCHAR;j++)
{
aa[j]=0x00;
}
j=0;
}
int
Hand(
char
*s)
//發(fā)短信打電話發(fā)短信調(diào)用指令
{
delay(200);
clearBuff();
delay(300);
readSerial(aa);
if
(
strstr
(aa,s)!=NULL)
//檢測單片機(jī)和模塊的連接
{
g_timeout=0;
clearBuff();
return
1;
}
if
(g_timeout>50)
{
g_timeout=0;
return
-1;
}
g_timeout++;
return
0;
}
void
send_english(
char
*x,
char
*i)
{
clearBuff();
Serial.println(CMGF1);
delay(500);
while
(Hand(
"OK"
)==0);
clearBuff();
Serial.println(x);
delay(500);
while
(Hand(
">"
)==0);
Serial.println(i);
delay(100);
Serial.print(
"\x01A"
);
//發(fā)送結(jié)束符號
delay(10);
delay(1000);
while
(Hand(
"OK"
)==0);
}
void
send_call(
void
)
//打電話
{
clearBuff();
Serial.println(CALL_YOU_TELNUMBER);
//打電話
delay(2000);
while
(Hand(
"OK"
)==0);
}
void
setup (
void
)
{
Serial.begin(115200);
//設(shè)置波特率為115200
Serial.println(
"serial port [ok]!"
);
}
void
loop (
void
)
{
send_english(yy,Num);
while
(1)
{
int
sensorValue = analogRead(Gas_Sensors);
Serial.print(
"Gas Sensors = "
);
Serial.println(sensorValue);
if
((sensorValue>=200)&&(sensorValue<=300))
{
send_english(yy,Num1);
}
if
((sensorValue>=301)&&(sensorValue<=700))
{
send_english(yy,Num2);
}
if
(sensorValue>=701)
{
send_english(yy,Num3);
}
delay(60000);
//每隔一分鐘檢查一次氣體情況
}
}