hello, guys,
I would like to share my own experience with A7 (GPRS and GPS) and Arduino Nano. All this weekend I spend to understand and manage A7 board. So, maybe for someone, will be useful this post…
The main task, what I was trying to do, to make “application” which will periodicaly upload GPS (NMEA) data to the web.
My setup:
• Ai Thinker A7 (for GPS I bought another antenna, because antenna shipped with board is not compatible for GPS signal).
• Arduino Nano
• Level shifter (It is needed because Arduino is using 5V for high signal and A7 is using 3.3V)
My mistakes and solutions:
A7 has separate pin for GPS data. After turning on GPS (with command AT+GPS=1) board start transfering GPS NMEA data to this pin. So to get these data through GPS pin, it is needed to support two serials (one for board management - AT commands and second for GPS data). I tried to do it with library SoftwareSerial, got some positive results, but there was more problems than success 
Then I found out, that A7 board has command “AT+GPSRD”, which as response provide one packet of GPS NMEA data through AT serial. So using this command it is enough to have one Serial. But while I was using library SoftwareSerial, I had some problems in communication. Then I decided to use library AltSoftSerial and vuolia – everything started to work as I wanted 
Note: AltSoftSerial require to use pins D8 and D9 for serial.
There is my code:
p.s. I’m not professional programmer, so sorry for some mess in code, but it works 
You need to find thease lines and modify according your situation:
sendCommand("at+cipstart="TCP","46.251.52.32",118","CONNECT OK",5000,1000,cont);
A6board.print("GET /gps.php?msg=");
A6board.print("HOST: 46.251.52.32");
The 46.251.52.32 is my own web, which is created only for testing.
The same with "/gps.php?msg=". So you need to use own web.
sendCommand("AT+CGDCONT=1,""IP"",""omnitel""","OK",2000,0,cont);
sendCommand("AT+CSTT=""omnitel"",""omni"",""omni""","OK",2000,0,cont);
This is my APN setup. You need setup according your mobile network provider.
#include <AltSoftSerial.h>
AltSoftSerial A6board;
char buffer[100];
char end_c[2];
int i;
int8_t answer;
/************************************************************************************************/
int8_t sendATcommand(String ATcommand, String expected_answer, unsigned int timeout, String &content){
uint8_t answer=0;
unsigned long previous;
delay(100); // Delay to be sure no passed commands interfere
while( A6board.available() > 0) A6board.read(); // Wait for clean input buffer
A6board.println(ATcommand); // Send the AT command
previous = millis();
content = "";
// this loop waits for the answer
do{
// if there are data in the UART input buffer, reads it and checks for the asnwer
if(A6board.available() != 0){
String part = String(char(A6board.read()));
content += part;
// check if the desired answer is in the response of the module
if (content.indexOf(expected_answer)>0){
answer = 1;
}
}
// Waits for the answer with time out
} while((answer == 0) && ((millis() - previous) < timeout));
return answer;
}
/************************************************************************************************/
boolean sendCommand(String cmd, String expAnsw, unsigned int timeout, unsigned int freez, String &cont){
//String cont;
cont = "";
boolean stat = false;
if (sendATcommand(cmd,expAnsw,timeout, cont)==1) {
Serial.print("OK: "); Serial.print(cmd); Serial.print("(Wait for: "); Serial.print(replace4VIEW(expAnsw)); Serial.println(")");
stat = true;
} else {
Serial.print("ERROR: "); Serial.print(cmd); Serial.print("(Wait for: "); Serial.print(replace4VIEW(expAnsw)); Serial.println(")");
stat = false;
}
Serial.println("*********** Content Begin *************");
Serial.println(replace4VIEW(cont));
Serial.println("*********** Content End *************");
Serial.println();
delay(freez);
return stat;
}
String replace4URL(String txt){
txt.replace("\r","%0D");
txt.replace("\n","%0A");
return(txt);
}
String replace4VIEW(String txt){
txt.replace("\r","\\r");
txt.replace("\n","\\n");
return(txt);
}
/************************************************************************************************/
void uploanGPS(){
String answ;
int i;
if (sendCommand("AT+GPSRD","OK",10000,0,answ)) {
String cont;
sendCommand("at+cipstart=\"TCP\",\"46.251.52.32\",118","CONNECT OK",5000,1000,cont);
sendCommand("AT+CIPSTATUS","OK",5000,1000,cont);
sendCommand("AT+CIPSEND",">",2000,500,cont);
//A6board.print("GET /gps.php?msg=AT+GPSRD%0D%0A+GPSRD:$GPGGA,215549.000,,,,,0,00,,,M,,M,,0000*76%0D%0A$GPRMC,215549.00V,0,%0DVTNN%0A%0D HTTP/1.1");
A6board.print("GET /gps.php?msg=");
for (i=1; i<=answ.length(); i++) {
char simb = answ.charAt(i);
if (simb == 0x0D) {
A6board.print("%0D");
} else if (simb == 0x0A) {
A6board.print("%0A");
} else {
A6board.print(char(simb));
}
}
A6board.print(" HTTP/1.1");
A6board.print("\r\n");
A6board.print("HOST: 46.251.52.32");
A6board.print("\r\n");
A6board.print("\r\n");
sendCommand(end_c,"OK",30000,0,cont);
sendCommand("AT+CIPSTATUS","OK",5000,1000,cont);
sendCommand("AT+CIPCLOSE","OK",15000,0,cont);
}
}
/************************************************************************************************/
void setup() {
String cont;
Serial.begin(19200);
A6board.begin(19200);
Serial.println("Start");
end_c[0] = 0x1a;
end_c[1] = '\0';
A6board.listen();
Serial.print("Swiching to 19200 baudrait -> ");
while(answer == 0){ // Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000, cont);
Serial.print("*");
}
Serial.println("");
sendCommand("AT+GPS=1","OK",2000,0,cont);
sendCommand("AT+CREG=0","OK",2000,1000,cont);
sendCommand("ATE0","OK",2000,1000,cont);
sendCommand("AT+CMEE=2","OK",2000,1000,cont);
sendCommand("AT+CGATT=1","OK",5000,1000,cont);
sendCommand("AT+CGDCONT=1,""IP"",""omnitel""","OK",2000,0,cont);
sendCommand("AT+CSTT=""omnitel"",""omni"",""omni""","OK",2000,0,cont);
sendCommand("AT+CGACT=1,1","OK",2000,0,cont);
////////////
sendCommand("AT","OK",5000,0,cont);
sendCommand("AT+GPSRD","OK",1000,0,cont);
sendCommand("AT+GPSRD","\r\n\r\n",1000,0,cont);
sendCommand("AT","OK",5000,0,cont);
}
/************************************************************************************************/
void loop() {
String hh;
String cont;
if (Serial.available()) {
hh = Serial.readStringUntil('\n');
hh.toCharArray(buffer, hh.length() + 1);
if (hh.indexOf("show_gps") == 0) {
sendCommand("AT+GPSRD","OK",10000,0,cont);
Serial.println(replace4VIEW(cont));
} else if (hh.indexOf("upload_gps") == 0) {
uploanGPS();
}else{
A6board.write(buffer);
A6board.write('\n');
}
}
if (A6board.available()) {
hh = A6board.readStringUntil('\n');
Serial.println("gprs: "+hh);
}
uploanGPS();
}
Currently I know few problems, which is not solved:
- Time to time, A7 give to big package of GPS NMEA data, so there is it needed to parse these data.
- As I noticed, currently A7 board don’t wait until he will receive answer from WEB. It put data to the web and close communication. Any way web receive these data, but it would be good always get response from the web and parse it to find out if web got and saved these data.
- Some SMS or Call to A7 board will rise errors to the commands, which was executed at that time. So it is needed to find out how to manage incoming commands, when A7 board is executing something else.