Skip to main content

SMS in modemsmodem's memory

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");
    }
}

SMS in modems memory

I am working on SMS communication with my phone and arduino. My intension is simple

"when somebody send sms, the arduino should read a text file located in my server and forward the content to the same number".

The problem here is, when I send a sms to my arduino, which is waiting for my message, unfortunately does not read my message. But when I separately run this example code, I see my sms received there. It means, my sms is already present in the modem memory. But Why this happens ? how to solve this  ? I will describe 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");
    }
}

SMS in modem's memory

I am working on SMS communication with my phone and Arduino. My intension is simple. When somebody send an SMS, the Arduino should read a text file located on my server and forward the content to the same number.

The problem here is, when I send an SMS to my Arduino, which is waiting for my message, it does not read my message. But when I separately run this example code, I see my SMS is received. It means my SMS is already present in the modem memory. But why does this happen? How to solve this? Here 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");
    }
}
code formatting
Source Link
jfpoilpret
  • 9.2k
  • 7
  • 38
  • 54
    // 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");
  }

  }
}
    // 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");
  }

  }
// 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");
    }
}
added 2493 characters in body
Source Link
Manihatty
  • 395
  • 1
  • 5
  • 16

The problem here is, when I send a sms to my arduino, which is waiting for my message, unfortunately does not read my message. But when I separately run this example code, I see my sms received there. It means, my sms is already present in the modem memory. But Why this happens ? how to solve this ? I will describe my code stucture :

    // 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 GSMcommunications and GPRSwait initializationfor port to open:
 Serial.begin(9600);
 while (!Serial) {
; // wait for Connectionserial port to serverconnect. 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);
if    sms.flush(smss);
    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(;;)
       ;
    }
    }

   }

   bool smss() // Iif justyou wantdidn't phoneget numbera connection to the server:
  // Serial.print(server);


void serverr()
 { 

if (smsclient.availableconnect(server, port))
 { 

   client.print("GET /current.txt");
   Serial.print("GET /current.txt");

   client.println("Message" receivedHTTP/1.1");
 from:  Serial.println(" HTTP/1.1");
   client.println("Host: smswww.remoteNumberyourdomain.com");
   Serial.println(remoteNum,"Host: 20www.yourdomain.com");
   client.println("User-Agent: Arduino");
   Serial.println(remoteNum"User-Agent: Arduino");
   client.println("Accept: smstext/html");
   Serial.flushprintln("Accept: text/html");
   client.println("Connection: close");
   Serial.println("MESSAGE"Connection: DELETED"close");
   client.println();
 return true; Serial.println();

   Serial.println("\nCOMPLETE!\n");
   //client.stop();

}
return 
 false;else
 {

  Serial.println("connection failed");
  Serial.println("\n FAILED!\n");
  }

  }

The problem here is, when I send a sms to my arduino, which is waiting for my message, unfortunately does not read my message. But when I separately run this example code, I see my sms received there. It means, my sms is already present in the modem memory. But Why this happens ? how to solve this ? I will describe my code stucture :

 void setup()
  {
    GSM and GPRS initialization

    Connection to server
  } 

  void loop()
   {


if (smss())
{
 
  
    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(); 
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();

       // do nothing forevermore:
       for(;;)
       ;
    }
    }

  }

   bool smss() // I just want phone number
 {
if (sms.available())
{
    Serial.println("Message received from:");
    sms.remoteNumber(remoteNum, 20);
    Serial.println(remoteNum);
    sms.flush();
    Serial.println("MESSAGE DELETED");
    return true;
}
return false;
 }

The problem here is, when I send a sms to my arduino, which is waiting for my message, unfortunately does not read my message. But when I separately run this example code, I see my sms received there. It means, my sms is already present in the modem memory. But Why this happens ? how to solve this ? I will describe 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");
  }

  }
added 926 characters in body
Source Link
Manihatty
  • 395
  • 1
  • 5
  • 16
Loading
added 266 characters in body
Source Link
Manihatty
  • 395
  • 1
  • 5
  • 16
Loading
Source Link
Manihatty
  • 395
  • 1
  • 5
  • 16
Loading