0

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 
Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob May 02 '20 at 11:14

2 Answers2

0

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();
}
Hayden Eastwood
  • 928
  • 2
  • 10
  • 20
  • The bearer in that case is probably open, in which case A) it doesn't matter - it won't break anything and B) you can close the bearer before that if you really want! "gprsSerial.println("AT+SAPBR=0,1");" and then open it again, : "gprsSerial.println("AT+SAPBR=1,1");" Basically I think you can ignore that error and continue with the connection process. – Hayden Eastwood May 02 '20 at 11:32
  • Those commands work with my module. But It seems that I can't receive an IP: My output now is: AT+SAPBR=2,1 +SAPBR: 1,3,"0.0.0.0" OK AT+HTTPINIT OK AT+HTTPPARA="URL"," http://www.google.com" OK AT+HTTPACTION=0 OK +HTTPACTION: 0,601,0 I've used #define APN "everywhere" #define USER "eesecure" #define PWD "secure" My provider is Orange -> https://www.teamknowhow.com/discover/discover/orange-apn-settings – Cristina Lupu May 02 '20 at 12:17
  • The sim800L is not capable of making HTTPS requests to my knowledge (at least I could only get mine to work with HTTP ) . 601 errors, if I remember correctly, are the result of trying to call an HTTPS domain. Try the same commands with a domain that you know is HTTP. – Hayden Eastwood May 02 '20 at 12:28
  • ok - I've added the sequence of commands I had to use to get mine to work in making an HTTP request. Make sure you use an HTTP endpoint, and not HTTPS. Does it work? – Hayden Eastwood May 02 '20 at 12:34
  • One final point: I don't trust the page - https://www.teamknowhow.com/discover/discover/orange-apn-settings - I didn't get my Orange card to work with those settings. It's far better to put the sim card in your phone and see what settings are auto-generated following setup. Then copy these. – Hayden Eastwood May 02 '20 at 12:37
  • My phone say that the APN is "net" with no user and pwd – Cristina Lupu May 02 '20 at 12:38
  • "My phone say that the APN is "net" with no user and pwd " - that sounds correct - I set up mine in Luxembourg just using orange.lu as the APN, with user and password blank. I'm not sure what it would be in your territory. – Hayden Eastwood May 02 '20 at 12:40
  • NB - It's definitely an APN issue because your +SAPBR: 1,3,"0.0.0.0" return string should contain an IP address and not 0s – Hayden Eastwood May 02 '20 at 12:40
  • Yep. I moved to just "net" and now I have an IP. I can't send req to https, but this is not a problem, if I send to a http url I get AT+HTTPACTION=0. Should I assume that the get request worked? – Cristina Lupu May 02 '20 at 12:48
  • Great! You can also print the content of the request some how (though I can't remember right now how to do it) - To confirm it works it's often best to check server side that it has made the correct call. AT+HTTPACTION=0 is the correct response, I think. – Hayden Eastwood May 02 '20 at 13:27
0

The sequence of send commands to set up TCP/IP connection:

//Check the registration status
AT+CREG?

//Check attach status
AT+CGACT?

//Attach to the network
AT+CGATT=1

//Wait for Attach
WAIT=7

//Start task ans set the APN. Check your carrier APN
AT+CSTT="bluevia.movistar.es" // Here you havve net which I guess is not a NetworkAPN you have to use the APN from your provider (= sim card)

//Bring up the wireless connection
AT+CIICR

//Wait for bringup
WAIT=6

//Get the local IP address
AT+CIFSR

//Start a TCP connection to remote address. Port 80 is TCP.
AT+CIPSTART="TCP","74.124.194.252","80"

//Set prompt of '>' when module sends data
AT+CIPSPRT=1

//Send the TCP data
AT+CIPSEND

If you want to test quickly a stable setup use this 7 days free to use tool for SIM800, SIM900 and then copy the succesfull process into code.

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22