(this post originally posted earlier in the wrong category)
I have a new official Arduino GSM Shield and am attempting to use it with the GSM library to post data to a web server and receive SMS messages. However, I have encountered a problem using the GSM library with my AT&T prepaid SIM. I can run the GSMWebClient example just fine once, but it fails to post a second time and instead hangs the program. I added the debug parameter "GSM gsmAccess = true;" which prints out the communications between the Arduino and the GSM. It appears that AT&T is sending message after every transaction letting you know how much it cost and this message must be confusing the GSM Library. I can use the Bluevia SIM that came with the shield and everything works fine. However, Bluevia will not accept SMS messages from out of their network.
The serial data I am getting back looks like this for the first post which completes:
Starting Arduino web client.
.AT%13%
.0 9>AT%13%%13%%10%OK%13%%10%
.AT+CGREG?%13%
.9 40>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
.AT+CGREG?%13%
.40 71>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
.AT+IFC=1,1%13%
.71 88>AT+IFC=1,1%13%%13%%10%OK%13%%10%
.AT+CMGF=1%13%
.88 106>%19%%17%AT+CMGF=1%13%%13%%10%OK%13%%10%
.AT+CLIP=1%13%
.106 122>AT+CLIP=1%13%%13%%10%OK%13%%10%
.ATE0%13%
.122 5>ATE0%13%%13%%10%OK%13%%10%
.AT+COLP=1%13%
.5 11>%13%%10%OK%13%%10%
.AT+CGATT=1%13%
.11 17>%13%%10%OK%13%%10%
.AT+QIFGCNT=0%13%
.17 23>%13%%10%OK%13%%10%
.AT+QICSGP=1,"wap.cingular","",""%13%
.23 29>%13%%10%OK%13%%10%
.AT+QIMUX=0%13%
.29 35>%13%%10%OK%13%%10%
.AT+QIMODE=1%13%
.35 41>%13%%10%OK%13%%10%
.AT+QINDI=1%13%
.41 47>%13%%10%OK%13%%10%
.AT+QIREGAPP%13%
.47 53>%13%%10%OK%13%%10%
.AT+QIACT%13%
.53 59>%13%%10%OK%13%%10%
.connecting...
.AT+QIDNSIP=1%13%
.59 65>%13%%10%OK%13%%10%
.AT+QIOPEN="TCP","arduino.cc",80%13%
.65 71>%13%%10%OK%13%%10%
.
.65 82>%13%%10%OK%13%%10%%13%%10%CONNECT%13%%10%
.connected
.GET / HTTP/1.1%13%%10%Host: arduino.cc%13%%10%Connection: close%13%%10%%13%%10%
The out put from the second post looks like this:
AT%13%
.78 87>AT%13%%13%%10%OK%13%%10%
.AT+CGREG?%13%
.87 118>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
.AT+CGREG?%13%
.118 21>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
.AT+CGREG?%13%
.21 52>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
.AT+IFC=1,1%13%
.52 69>AT+IFC=1,1%13%%13%%10%OK%13%%10%
.AT+CMGF=1%13%
.69 65>%19%%17%AT+CMGF=1%13%%13%%10%OK%13%%10%%13%%10%+CMT: "78108858",,"2014/01/28 08:52:44-20"%13%%10%The last transaction cost %2% 0.04. Your account balance is %2%
.AT+CLIP=1%13%
At this point, the program stops.
The code is the Web Client example which has been modified to repeat the post every twenty seconds.
Code:
/*
Web client
This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://arduino.cc/asciilogo.txt" and
prints it to the Serial monitor.
Circuit:
* GSM shield attached to an Arduino
* SIM card with a data plan
created 8 Mar 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/GSMExamplesWebClient
*/
// libraries
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "wap.cingular" // replace your GPRS APN
//#define GPRS_APN "bluevia.movistar.es" // replace your GPRS APN
#define GPRS_LOGIN "" // replace with your GPRS login
#define GPRS_PASSWORD "" // replace with your GPRS password
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess = true;
GSM_SMS sms;
// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/";
int port = 80; // port 80 is the default for HTTP
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// connection state
}
void loop()
{
char c;
boolean notConnected = true;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port))
{
Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
delay(20000);
}