I use the official GSM Shield with Mega2560 board.
I try to use in the same sketch SMS reception and connection to a webserver using GSM_client.
The SMS reception and connection to a webserver work well when they are not in the same sketch but not together.
I don't know if it's possible to use both in the same sketch?
Thank you for your help.
Here is my code
smsEtWebclient2.ino (7.5 KB)
My code more simple :
#include <SD.h>
#include <Wire.h>
#include <GSM.h>// PIN Number
#define PINNUMBER "1234"// APN data
#define GPRS_APN "free" // replace your GPRS APN
#define GPRS_LOGIN "" // replace with your GPRS login
#define GPRS_PASSWORD "" // replace with your GPRS passwordGSMClient client;
GPRS gprs;
GSM gsmAccess;
GSM_SMS sms;IPAddress server(???,???,???,???);
File fichierActuel; //fichier pour carte SD
int i;
int port = ???;
char c;
char command = '0';
boolean connecteAvant = false;char senderNumber[20];
char smsrecu[22];
boolean demande_fichier_sms = false;void setup()
{
Serial.begin(38400);
Serial.println(F("reset"));
delay(1000);Serial.println(F("connecting au reseau free..."));
// connection state
boolean notConnected = true;
previous = millis();// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and passwordwhile(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
{ delay(500);
Serial.println(F("GSM OK"));
if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)
{ notConnected = false;
}
else
{
Serial.println(F("Not connected"));
delay(1000);
}
}
}
Serial.println(F("connected au reseau free"));
}void loop()
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}if (demande_fichier_sms == true)
{
Serial.println(F("connecting to server..."));
if (client.connect(server, port))
{
connecteAvant = true;
Serial.println(F("connected sever"));
//le client Make a HTTP request avec POST
client.println(F("POST /Burkina/memorisation_donnees_burkina.php HTTP/1.1"));
client.println(F("Host: ???.???.???.???:???"));
client.println(F("Connection: close\r\nContent-Type: application/x-www-form-urlencoded"));
client.print(F("Content-Length: "));
client.println(PostLength);
client.println();
client.print(F("var"));
client.print(F("="));
client.print(F("test"));
}
myfile.close();
}
demande_fichier_sms = false;
}
else
{
// kf you didn't get a connection to the server:
Serial.println(F("connection server failed"));
}
}
if ( (!client.connected()) && (!client.available()) && (connecteAvant==true) )
{
Serial.println();
Serial.println(F("disconnecting."));
client.stop();
connecteAvant = false;
}
if (sms.available())
{
Serial.println(F("Message received from:"));// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println(F("Discarded SMS"));
sms.flush();
}// Read message bytes and print them
i=0;
while(c=sms.read())
{
Serial.print(c);
if (i<=20)
{ smsrecu* = c;*
}*
i++;*
}*
_ Serial.println(F("\nEND OF MESSAGE"));_
_ Serial.println(smsrecu);_// Delete message from modem memory*
sms.flush();*
_ Serial.println(F("MESSAGE DELETED"));_}*
if (smsrecu[0] == '&')*
{ if (smsrecu[1] == 't') *
{ *
_ Serial.print(F("envoi sms a:"));_i = 4;*
while ((senderNumber >= '0') && (senderNumber *<= '9')) *
* { i++;*
* }*
_ senderNumber* ='\0';
Serial.println(senderNumber);
sms.beginSMS(senderNumber);
sms.print(F("hello"));
sms.endSMS();
Serial.println(F("SMS envoyé"));
}
else if (smsrecu[1] == 'f') _
{ demande_fichier_sms = true;
_ delay(2000);
}
smsrecu[0] = ' ';
}*__ if (Serial.available())
* {
command = Serial.read();
if (command=='e')
{ _
demande_fichier_sms = true;
_ }
}
}
[/quote]*_
Is there anyone who have experienced with arduino GSM module?