0

I provided LiPo 3.7V 3 cells 3000mAh to SIM800L. The led blynks stably every 3 seconds which means The module has made contact with the cellular network. I ran the code below and it outputs Waiting for network...fail without any AT response

#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <SoftwareSerial.h>

const char apn[]  = "VINAPHONE"; // you can leave this as it is
const char user[] = ""; // you can leave this as it is
const char pass[] = ""; // you can leave this as it is

SoftwareSerial SerialGSM(9, 8);

TinyGsm modem(SerialGSM);
TinyGsmClient client(modem);

void setup() {
  Serial.begin(9600);
  SerialGSM.begin(9600);

  delay(3000);
  testATCommand();

}

void loop() {

  SerialGPS.listen();
  checkGPSFix();
  if(!gpsIsFix){
    Serial.println("GPS is not fixed");
    return;
  }
  
  Serial.println("GPS is fixed now!");


  SerialGSM.listen();
    Serial.print("Waiting for network...");
  if (!modem.waitForNetwork()) {
    Serial.println(" fail");
    delay(10000);
    return;
  }
  Serial.println(" OK");

  Serial.print("Connecting to ");
  Serial.print(apn);
  if (!modem.gprsConnect(apn, user, pass)) {
    Serial.println(" fail");
    delay(10000);
    return;
  }
  Serial.println(" OK");

}

void testATCommand(){
  
  Serial.println("------------------ CHECK AT COMMAND ---------------");
  delay(3000);
  
  //Once the handshake test is successful, it will back to OK
  SerialGSM.println("AT");
  updateSerial();
  delay(1000);
  
  SerialGSM.println("ATE1");
  updateSerial();

  SerialGSM.println("AT+CMEE=1");
  updateSerial();
  
  //Checks Signal Strength, value range from 0-31(best)
  SerialGSM.println("AT+CSQ");
  updateSerial();
  delay(1000);

  //Enable network registration
  SerialGSM.println("AT+CREG=1");
  updateSerial();
  delay(1000);

  SerialGSM.println("AT+CREG?");
  updateSerial();
  delay(1000);

  //Check which network connecting to
  SerialGSM.println("AT+COPS?");
  updateSerial();
  delay(1000);

//  //Read SIM information (confirm if SIM is plugged)
//  SerialGSM.println("AT+CCID");
//  updateSerial();
//  delay(5000);

  //GPRS attached
  SerialGSM.print("AT+CGATT=1\r\n");              
  updateSerial();
  delay(1000);

  SerialGSM.println("AT+CGATT?");
  updateSerial();
  delay(1000);
  
  //Set connection type to GPRS
  SerialGSM.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n");
  updateSerial();
  delay(1000);

  //Return battery status [Battery level, actual voltage (mV)]
  SerialGSM.println("AT+CBC");
  updateSerial();
  delay(1000);
    
  Serial.println("------------------  FINISH ---------------");
  
}

Its output

------------------ CHECK AT COMMAND ---------------
------------------  FINISH ---------------
********** *********** ***** 
GPS is not fixed
xxxxxxxxx xxxxxxxxx  0.00  
GPS is fixed now!

Trying to send data to Server: 
Waiting for network... Fail wait for network
Error times: 1
xxxxxxxxx  xxxxxxxx 0.00  
GPS is fixed now!

Trying to send data to Server: 
Waiting for network...

When I change source to VCC the it outputs AT normally but also wait for network

------------------ CHECK AT COMMAND ---------------
AT

OK
ATE1

OK
AT+CMEE=1

OK
AT+CSQ

+CSQ: 15,0

OK
AT+CREG=1

OK
AT+CREG?

+CREG: 1,1

OK
AT+COPS?

+COPS: 0,0,"VINAFONE"

OK
AT+CGATT=1

OK
AT+CGATT?

+CGATT: 1

OK
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK
AT+CBC

+CBC: 0,100,4641

OK
------------------  FINISH ---------------
********** *********** ***** 
GPS is not fixed
xxxxxxxx  xxxxxxxxx  0.00  
GPS is fixed now!

Trying to send data to Server: 
Waiting for network...

I am do not know what to do next to fix. Any suggestion?

Thanks in advanced!

0 Answers0