-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_GSM.js
85 lines (62 loc) · 1.54 KB
/
archive_GSM.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var cmd="";
var global_response=0;
var answer="OK";
//Function handles data coming in from Serial.
Serial4.onData(function (e) {
if(cmd.indexOf(answer) > 0){
console.log(cmd);
cmd="";
global_response=1;
}
else
{
cmd+=e.data;
}
});
//Function handles sending AT commands to GSM device.
function Send_Command(command,time,caller){
var AT = setInterval(function (f) { Serial4.write(command); }, time);
var timey = setInterval(function(){
if(global_response==1){
clearInterval(AT);
global_response=0;
clearInterval(timey);
caller();
}
},300);
}
//Start the GSM Module
function Start_Gsm() {
answer="OK";
console.log("GSM Starting..");
pinMode(C0,"output");
digitalPulse(C0,1,2000);
Send_Command("AT\r\n",500,function(){Set_SMS_Mode();
});
}
function Stop_GSM() {
pinMode(C0,"output");
digitalPulse(C0,1,2000);
console.log("GSM Stopped...");
}
//Set the SMS Mode
function Set_SMS_Mode() {
answer="OK";
console.log("Setting SMS Mode..");
Send_Command("AT+CMGF=1\r\n",1000,function(){Set_SMS_Number();});
}
//Set the SMS number to send text message to
function Set_SMS_Number() {
answer=">";
console.log("Setting Phone Number..");
Send_Command('AT+CMGS=\"xxxxxxxxxxx\"\r',1000,function(){Send_SMS();});
}
//Send the text message
function Send_SMS(){
console.log("Send Message");
answer="OK";
Send_Command("testing\x1A\r",3000,function(){Stop_GSM();});
}
//Set up the Serial port for the GSM
Serial4.setup(9600);
Start_Gsm();