A6 GSM Module stop transmitting after a while

Hello,
I recently made a GPS tracker using Ublox Neo-6M gps module, A6 GSM Module and Atmega328P. The device is working fine but after few hours, sometimes after 2 days the device stops transmitting data, when i try calling the sim card it get through and i can hear it ring, but somehow the data is no transmitted. Upon disconnecting from power and reconnecting the device start sending data again and stops after a while, so i added a transistor to automatically power down the GSM module if the velocity drop to zero and switch on if the velocity climb above a particular value, however this do not work either. I have applied AES encryption to the data, i don’t know whether its causing the problem or not. I will post the code below, it would be really grateful if anyone could point out whats wrong with the code.

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <AES.h>
#include <Base64.h>
#include <String.h>

SoftwareSerial SIM900(7, 8);
int gsm = 4;
int gps = 5;
int count = 0;
float velocity = 0;
float flat = 0;
float flon = 0;
bool gsmOFF = false;

void setup()
{
pinMode(gps, OUTPUT);
pinMode(gsm, OUTPUT);

digitalWrite(gsm, HIGH);
digitalWrite(gps, HIGH);
}

void loop()
{
String ndata = gpsData();

if (velocity < 7)
{
if (count < 6){
count = count + 1;
}
if (count == 5)
{

  String data = aesEncryptedData(ndata);
  data = "GET http://******************************************+data+  "\r\n\x1A";
  sendData(data);

  digitalWrite(gsm, LOW);
  gsmOFF = true;

}

}
else {
if (gsmOFF) {
digitalWrite(gsm, HIGH);
delay(20000);
gsmOFF = false;
String data = aesEncryptedData(ndata);
data = β€œGET http://”******************************************" + data + β€œ\r\n\x1A”;
sendData(data);
}
count = 0;
}
if (!gsmOFF) {
String data = aesEncryptedData(ndata);
data = β€œGET http://******************************************” + data + β€œ\r\n\x1A”;
sendData(data);

}

}

String gpsData()
{
SoftwareSerial ss(3, 2);

TinyGPS gps;

unsigned long age;

String getStr;

ss.begin(9600);

for (unsigned long start = millis(); millis() - start < 1000;) {

if (ss.available()) {

  char c = ss.read();
  gps.encode(c);
}

}

gps.f_get_position(&flat, &flon, &age);
velocity = round(gps.f_speed_kmph());
char buf[16];
getStr = dtostrf(flat, 4, 6, buf);
getStr += β€œ~”;
getStr += dtostrf(flon, 4, 6, buf);
getStr += β€œ~”;
getStr += dtostrf(velocity, 3, 1, buf);
ss.end();
return getStr;
}

String aesEncryptedData(String dataString) {

AES aes;
byte key = (unsigned char)β€œ01234567890101230123456789010123”;
int bits = 256;
byte iv [N_BLOCK] ;
unsigned long long int myIv = 123456789;

byte plain[dataString.length()];
int plainLength = sizeof(plain) - 1;
dataString.getBytes(plain, plainLength);
int padedLength = plainLength + N_BLOCK - plainLength % N_BLOCK;
byte plain_p[padedLength];
byte cipher [padedLength] ;
byte check [padedLength] ;
aes.set_IV(myIv);
aes.get_IV(iv);
aes.do_aes_encrypt(plain, plainLength, cipher, key, bits, iv);
aes.set_IV(myIv);
aes.get_IV(iv);

char ivdata[sizeof(iv)];
int encrypted_size = sizeof(cipher);
char encoded[encrypted_size];
base64_encode(encoded, (char*)cipher, encrypted_size);
base64_encode(ivdata, (char*)iv, sizeof(iv));

String d = (char*) encoded;
String d1 = (char*) ivdata;

String d2 = d1 + β€œ~” + d;
return (urlencode(d2));

}

void sendData(String data) {

int delayTime  = 1000;
int delayTimeF = 250;

SIM900.begin(9600);

SIM900.println("AT"); /* Check Communication */
delay(delayTime);

SIM900.println("AT+CIPMODE=0"); /* Non-Transparent (normal) mode for TCP/IP application */
delay(delayTime);

SIM900.println("AT+CIPMUX=0");  /* Single TCP/IP connection mode */
delay(delayTime);

SIM900.println("AT+CGATT=1"); /* Attach to GPRS Service */
delay(delayTime);

SIM900.println("AT+CREG?"); /* Network registration status */
delay(delayTime);

SIM900.println("AT+CGATT?");  /* Attached to or detached from GPRS service */
delay(delayTime);

SIM900.println("AT+CSTT=\"internet\""); /* Start task and set APN */
delay(delayTime);

SIM900.println("AT+CIICR"); /* Bring up wireless connection with GPRS */
delay(delayTime);

SIM900.println("AT+CIFSR"); /* Get local IP address */
delay(delayTime);

SIM900.println("AT+CIPSTART=\"TCP\",\"****.************.in\",80");
delay(2000);

SIM900.println("AT+CIPSEND"); /* Send data through TCP connection */
delay(delayTime);

SIM900.println(data);  /* URL for data to be sent to */
delay(delayTime);

SIM900.println("AT+CIPSHUT"); /* Deactivate GPRS PDP content */
delay(delayTime);

SIM900.end();

}

String urlencode(String str)
{
String encodedString = β€œβ€;
char c;
char code0;
char code1;
char code2;
for (int i = 0; i < str.length(); i++) {
c = str.charAt(i);
if (c == ’ ') {
encodedString += β€˜+’;
} else if (isalnumΒ©) {
encodedString += c;
} else {
code1 = (c & 0xf) + β€˜0’;
if ((c & 0xf) > 9) {
code1 = (c & 0xf) - 10 + β€˜A’;
}
c = (c >> 4) & 0xf;
code0 = c + β€˜0’;
if (c > 9) {
code0 = c - 10 + β€˜A’;
}
code2 = β€˜\0’;
encodedString += β€˜%’;
encodedString += code0;
encodedString += code1;
//encodedString+=code2;
}
yield();
}
return encodedString;
}

Thank You.
Best Regards.
Richards Babu.

1 Like

Modules can become non responsive or enter a bad state. You have to have provision in your code to exit and reboot the module in case of no response or in case of no data sent for a while. I do this by adding timeouts which count for a while whether data is sent or not and if not sent for a while or if there is no response for AT commands for a while then i reboot the module. A hard reset of power using MOSFET is recommended.

1 Like
#include <SoftwareSerial.h>

//Create software serial object to communicate with A6
SoftwareSerial mySerial(3, 2); //A6 Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and A6
  mySerial.begin(9600);

  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
  updateSerial();
  mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
  updateSerial();
  mySerial.println("AT+CREG?"); //Check whether it has registered in the network
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

hello
i have similar problem with GSM A6 module and NodeMCU .I use Cayenne library to send data to Cayenne Server.Cayenne use tinyGSM library to send data over gprs.
it Stop Sending Data after Hours (maximum 1 day) and it wont work until re plug power of module.i use Auto baud rate to communicate with A6
What really causes this problem?
what kind of MOSFET must use to reboot the module ?