Go Down

Topic: Can I connect several a GPRS At command (Read 261 times) previous topic - next topic

pierrot10

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: [Select]

  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: [Select]

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: [Select]

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: [Select]

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?
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy