Search code examples
tcparduinogsmsim800sim800l

Arduino UNO & Modem Sim800L Can't write setup commands to send data to server


I am using arduino UNO board, with modem sim800l. I want use it to send data to server, but the problem is that I can't write the setup commands.

What am I doing wrong? Are not this the right commands to use for sim800l? I've tried with different commands and the output is the same.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L 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 SIM800L
  mySerial.begin(9600);

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

  mySerial.println("AT+CMEE=2"); // Error mode 
  delay(100);
  updateSerial();

  mySerial.println("AT"); //Once the handshake test is successful, i t will back to OK
  delay(100);
  updateSerial();

  mySerial.println("AT+CFUN=1"); //Level "full functionality" 
  delay(100);
  updateSerial();

  mySerial.println("AT+CGATT?"); //attach or detach from GPRS service 
  delay(100);
  updateSerial();

  mySerial.println("AT+CSTT=\"net\",\"\",\"\""); //AT+CSTT AT command sets up the apn, user name and password for the PDP context.
  delay(2000);
  updateSerial();

  mySerial.println("AT+CSTT?"); //AT+CSTT show apn
  delay(2000);
  updateSerial();

  mySerial.println("AT+CIICR"); //  Brings up wireless connection
  delay(2000);
  updateSerial();

  mySerial.println("AT+CIFSR"); //  Get local IP address if connected
  delay(2000);
  updateSerial();
}

Here is the output from the console of Arduino IDE:

Initializing... 
AT+CHEE=2 
OK 
AT 
OK 
AT+CFUN=1 
OK 
AT+CGAIT? 
+CGATT: 1 
OK 
AT+CSTT="net","","" 
+CME ERROR: operation not allowed 
AT+CSTT? 
+CSTT: "CMNET","","" 

OK 
AT+CIICR 
+CME ERROR: operation not allowed 
AT+CIFSR 
+CME ERROR: operation not allowed 

Solution

  • You have my sympathies, it took me weeks to get my Arduino talking to the net. I think your problem is happening on the line containing "CSTT", which I don't think SIM800L recognises.

    Try the below setup instead, with "SAPBR" in its place:

    SoftwareSerial gprsSerial(7, 8); // working here with Arduino ports 7 and 8
    void setup() {
      gprsSerial.begin(19200);
      Serial.begin(19200);
      Serial.println("connect to GPRS");
      gprsSerial.println("AT");
      toSerial();
      gprsSerial.println("AT+CREG?");  
      toSerial();
      gprsSerial.println("AT+CGATT?");
      toSerial();
      gprsSerial.println("AT+CSQ ");
      toSerial();
      gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
      delay(2000);
      toSerial();
      gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"" + String(APN) + "\"");
      delay(300);
      gprsSerial.println("AT+SAPBR=3,1,\"USER\",\"" + String(USER) + "\"");
      delay(300);
      gprsSerial.println("AT+SAPBR=3,1,\"PWD\",\"" + String(PWD) + "\"");
      delay(1000);
      toSerial();
      gprsSerial.println("AT+SAPBR=1,1");
      delay(2000);
      toSerial();
      gprsSerial.println("AT+SAPBR=2,1");
      delay(2000);
      toSerial();
    }
    

    Your run loop:

    void loop(){
    // Do your stuff
    }
    

    And your toSerial function:

    void toSerial()
    {
      delay(200);
      if(gprsSerial.available()>0){
        textMessage = gprsSerial.readString();
        delay(100);
        Serial.print(textMessage);    
      }
    }
    

    Your call server function should be like this:

    void callServer() {
      Serial.println("Calling server");
      gprsSerial.println("AT+CCLK?");
      toSerial();
      gprsSerial.println("AT+HTTPINIT");
      toSerial();
      gprsSerial.println("AT+HTTPPARA=\"CID\",1");
      toSerial();
      gprsSerial.println("AT+HTTPPARA=\"URL\",\"http:[YOURURL]") // NOTE: NOT HTTPS!
      delay(1000);
      toSerial();
      gprsSerial.println("AT+HTTPACTION=0");
      delay(3000);
      toSerial();
      gprsSerial.println("AT+HTTPREAD");
      delay(3000);
      toSerial();
    }