Pages: [1]   Go Down
Author Topic: Can I connect several a GPRS At command  (Read 230 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 455
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All,

Today I had a reflexion while thining about my project.
I am trying to write AT commande to connect and send data to a remote server.

In my loop() I have that code to connect
Code:
  Serial.println(F("Attaching GPRS..."));
  cell.println("AT+CGATT=1");
  waitFor("OK");
 
  Serial.println(F("Setting up PDP Context..."));
  cell.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
  waitFor("OK");

  Serial.println(F("Activating PDP Context..."));
  cell.println("AT+CGACT=1,1");
  waitFor("OK");
 
  Serial.println(F("Configuring TCP connection to TCP Server..."));
  cell.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80");
  waitFor("OK");
 
  Serial.println(F("Starting TCP Connection..."));
  cell.println("AT+SDATASTART=1,1");
  waitFor("OK");
 

When it's connected it send the data
Code:
int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
 
  Serial.println(F("Sending HTTP packet..."));
  cell.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
  waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
  cell.print(request+"\r\n"); // SIZE: 2
  cell.print("Host: "+host+"\r\n"); // SIZE: 8
  cell.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
  cell.write(26); // ctrl+z character: send the packet
  waitFor("OK");

 Serial.println("Yes! Sent data acknowledged by server!");

Then it wait for 1mn and the loop starts again.

But should I run that code again
Code:
Serial.println(F("Attaching GPRS..."));
  cell.println("AT+CGATT=1");
  waitFor("OK");
 
  Serial.println(F("Setting up PDP Context..."));
  cell.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
  waitFor("OK");

  Serial.println(F("Activating PDP Context..."));
  cell.println("AT+CGACT=1,1");
  waitFor("OK");
 
  Serial.println(F("Configuring TCP connection to TCP Server..."));
  cell.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80");
  waitFor("OK");
 
  Serial.println(F("Starting TCP Connection..."));
  cell.println("AT+SDATASTART=1,1");
  waitFor("OK");
 
  delay(5000); // wait for the socket to connect

It's already connected! no?

I should loop on that code:
Code:
int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
 
  Serial.println(F("Sending HTTP packet..."));
  cell.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
  waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
  cell.print(request+"\r\n"); // SIZE: 2
  cell.print("Host: "+host+"\r\n"); // SIZE: 8
  cell.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
  cell.write(26); // ctrl+z character: send the packet
  waitFor("OK");

But if I am true, and I leave my module runing for 5 hours, it will be connected for 5 hours, then I will my my ISP provide?
Should I not disconnect at the end of the loop and reconnect when loop starts?
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Pages: [1]   Go Up
Jump to: