I am working on SMS communication with my phone and arduinoArduino. My intension is simple
"when. When somebody send smsan SMS, the arduinoArduino should read a text file located inon my server and forward the content to the same number"number.
The problem here is, when I send a smsan SMS to my arduinoArduino, which is waiting for my message, unfortunatelyit does not read my message. But when I separately run this exampleexample code, I see my smsSMS is received there. It means, my smsSMS is already present in the modem memory. But Whywhy does this happens happen? howHow to solve this ? I will describeHere is my code:
// libraries
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;
GSM_SMS sms;
// URL, path & port (for example: arduino.cc)
char server[] = "yourdomain.com";
char path[] = "/current.txt";
int port = 80; // port 80 is the default for HTTP
char k[30];
char z = '*';
int s=0;
String place;
char remoteNum[20]; // telephone number to send sms
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS connected");
// connection state
boolean notConnected = true;
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("GPRS connected...");
Serial.println("Server Connecting.");
// if you get a connection, report back via serial:
serverr();
}
void loop()
{
if (sms.available())
{
Serial.println("Message received from:");
sms.remoteNumber(remoteNum, 20);
Serial.println(remoteNum);
sms.flush();
Serial.println("MESSAGE DELETED");
}
}
void smss() {
// I just want phone number
{
if (client.available())
{
char c = client.read();
//***************************************************
// Filtering a specific message
//**************************************************
if (z==c)
{
s=1;
}
if(s == 1)
{
int i=0;
k[i] = c;
i=i+1;
// Serial.print(k);
}
place +=k;
//Serial.print(place);
}
//***************************************************
if (!client.available() && !client.connected())
{
sms.beginSMS(remoteNum);
Serial.print("Place =");
Serial.print(place);
sms.print(place);
sms.endSMS();
sms.flush();
Serial.println("MESSAGE DELETED");
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
// if you didn't get a connection to the server:
// Serial.print(server);
void serverr()
{
if (client.connect(server, port))
{
client.print("GET /current.txt");
Serial.print("GET /current.txt");
client.println(" HTTP/1.1");
Serial.println(" HTTP/1.1");
client.println("Host: www.yourdomain.com");
Serial.println("Host: www.yourdomain.com");
client.println("User-Agent: Arduino");
Serial.println("User-Agent: Arduino");
client.println("Accept: text/html");
Serial.println("Accept: text/html");
client.println("Connection: close");
Serial.println("Connection: close");
client.println();
Serial.println();
Serial.println("\nCOMPLETE!\n");
//client.stop();
}
else
{
Serial.println("connection failed");
Serial.println("\n FAILED!\n");
}
}