forked from IOT-MCU/ESP-12S-A9-A9G-GPRS-Node-v1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP-12S_A9G_TEST.ino
195 lines (158 loc) · 4.18 KB
/
ESP-12S_A9G_TEST.ino
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include<stdio.h>
#include<string.h>
#define DEBUG true
#include <SoftwareSerial.h>
#define BAUD_RATE 115200
#define A9_BAUD_RATE 115200
/***********************************/
#define A9G_PON 16 //ESP12 GPIO16 A9/A9G POWON
#define A9G_POFF 15 //ESP12 GPIO15 A9/A9G POWOFF
#define A9G_WAKE 13 //ESP12 GPIO13 A9/A9G WAKE
#define A9G_LOWP 2 //ESP12 GPIO2 A9/A9G ENTER LOW POWER MODULE
void handleInterrupt();
int A9GPOWERON();
/***********************************/
SoftwareSerial swSer(14, 12, false, 256);
void setup() {
Serial.begin(BAUD_RATE);
swSer.begin(A9_BAUD_RATE);
for (char ch = ' '; ch <= 'z'; ch++) {
swSer.write(ch);
}
swSer.println("");
/************************************/
pinMode(A9G_PON, OUTPUT);//LOW LEVEL ACTIVE
pinMode(A9G_POFF, OUTPUT);//HIGH LEVEL ACTIVE
pinMode(A9G_LOWP, OUTPUT);//LOW LEVEL ACTIVE
digitalWrite(A9G_PON, HIGH);
digitalWrite(A9G_POFF, LOW);
digitalWrite(A9G_LOWP, HIGH);
Serial.println("After 2s A9G will POWER ON.");
delay(2000);
if(A9GPOWERON()==1)
{
Serial.println("A9G POWER ON.");
}
/********************A9G POWER OFF TEST***********************/
/*
Serial.println("After 5s A9G will POWER OFF.");
delay(5000);
if(A9GPOWEROFF()==0)
{
Serial.println("A9G POWER OFF.");
}
Serial.println("After 5s A9G will POWER ON.");
delay(5000);
if(A9GPOWERON()==1)
{
Serial.println("A9G POWER ON.");
}
*/
/******************A9G GPIO LOW POWER TEST****************************/
/*
Serial.println("After 15s A9G will ENTER GPIO LOW POWR MODULE.");
delay(15000);
// Serial.println(A9GENTERLOWPOWER());
if(A9GENTERLOWPOWER()==1)
{
Serial.println("A9G ENTER GPIO LOW POWR MODULE.");
}
*/
Serial.println("Enale the GPS");
sendData("AT+GPS=1",1000,DEBUG);
pinMode(A9G_WAKE, INPUT);//interruptPin
attachInterrupt(digitalPinToInterrupt(A9G_WAKE), handleInterrupt, RISING);
/*********************GPIO0 TEST********************/
/*
pinMode(0, INPUT_PULLUP);//interruptPin
attachInterrupt(digitalPinToInterrupt(0), handleInterrupt, FALLING);
*/
/***********************************/
}
void loop() {
while (swSer.available() > 0) {
Serial.write(swSer.read());
// yield();
}
while (Serial.available() > 0) {
swSer.write(Serial.read());
// yield();
}
Serial.print("analogRead:");
Serial.println(analogRead(A0));
delay(1000);
sendData("AT+CCID",1000,DEBUG);
delay(1000);
sendData("AT+CSQ",1000,DEBUG);
delay(1000);
sendData("AT+LOCATION=2",1000,DEBUG);
delay(1000);
}
void handleInterrupt() {
Serial.println("An interrupt has occurred.");
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
swSer.println(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(swSer.available())
{
char c = swSer.read();
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
int A9GPOWERON()
{
digitalWrite(A9G_PON, LOW);
delay(3000);
digitalWrite(A9G_PON, HIGH);
delay(5000);
String msg = String("");
msg=sendData("AT",1000,DEBUG);
if( msg.indexOf("OK") >= 0 ){
Serial.println("GET OK");
return 1;
}
else {
Serial.println("NOT GET OK");
return 0;
}
}
int A9GPOWEROFF()
{
digitalWrite(A9G_POFF, HIGH);
delay(3000);
digitalWrite(A9G_POFF, LOW);
delay(5000);
String msg = String("");
msg=sendData("AT",1000,DEBUG);
if( msg.indexOf("OK") >= 0 ){
Serial.println("GET OK");
return 1;
}
else {
Serial.println("NOT GET OK");
return 0;
}
}
int A9GENTERLOWPOWER()
{
String msg = String("");
msg=sendData("AT+SLEEP=1",1000,DEBUG);
if( msg.indexOf("OK") >= 0 ){
digitalWrite(A9G_LOWP, LOW);
return 1;
}
else {
return 0;
}
}