Trotsko

Hi. I have a little problem. Every time when I receive message to the GSM shild I need to delete all sms messages on the my SIM card. I tried to use flush() function but not success. My be somebody know how to solve this problem. Help please.

I tried to use flush() function but not success

Please post your code, and when you do please use [­code] code goes here [­/code] tags around it

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER “”

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// 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);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println(“SMS Messages Receiver”);

// connection state
boolean notConnected = true;

// Start GSM connection
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println(“Not connected”);
delay(1000);
}
}

Serial.println(“GSM initialized”);
Serial.println(“Waiting for messages”);
}

void loop() {
char c;
char str1[4] = {‘T’,‘e’,‘m’,‘p’};
int i,j;
// If there are any SMSs available()
if (sms.available()) {
Serial.println(“Message received from:”);

//I think in this place I must delete all previous messages

// 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(“Discarded SMS”);
sms.flush();
}

// Read message bytes and print them
i = -1;
j=0;//Mark for true or false
while (c = sms.read()) {
i =i+1;
if (c != str1*) {j = 1;}//if symbol from message doesn’t compare with symbol with massive then false (j=1)*
_ //Serial.println(str1*);_
_
Serial.print(c);//Print the message symbol*_
* }*
* //Serial.println(j);*
* //Serial.println(i);*
* if ((j ==0 )&&(i == 3)) {//if all symbols compared and count of symbol equal in massive (i=1) then true *
* Serial.println(“Temperature”);*

* }*
* // Delete message from modem memory*
* Serial.println("\nEND OF MESSAGE");*
* sms.flush();*
* Serial.println(“MESSAGE DELETED”);*
* }*
* delay(1000);*
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Did you miss my request to use code tags ?
Without them parts of your code has been interpreted as HTML tags, hence the italics.

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// 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);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() {
  char c;
  char str1[4] = {'T','e','m','p'};
  int i,j;
  // If there are any SMSs available()
  if (sms.available()) {
    Serial.println("Message received from:");



   //I think in this place I must delete all previous messages


    // 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("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    i = -1;
    j=0;//Mark for true or false
    while (c = sms.read()) {
      i =i+1;
      if (c != str1) {j = 1;}//if symbol from message doesn't compare with symbol with massive then false (j=1)
      //Serial.println(str1);
      Serial.print(c);//Print the message symbol
    }
    //Serial.println(j);
    //Serial.println(i);
    if ((j ==0 )&&(i == 3)) {//if all symbols compared and count of symbol equal in massive (i=1) then true   
      Serial.println("Temperature");


      
      } 

    // Delete message from modem memory
    Serial.println("\nEND OF MESSAGE");
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

The compiler is definitely not too happy with this lineif (c != str1) {

Thank for you answer. I know that operator is incorrect. It must be c != str1*. My scetch works well. But the problem is I don't know how to clean all sms on the SIM card before receiving the message.*

Your sketch doesn't even compile. What you wrote in the reply is what is in the code, no change there. c is a variable and str1 is a pointer.

Can't help with your other part of the code as I don't have knowledge of the gsm.

/*
 SMS receiver

 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port.

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 25 Feb 2012
 by Javier Zorzano / TD

 This example is in the public domain.

 http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveSMS

*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// 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);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() {
  char c;
  char str1[4] = {'T','e','m','p'};
  int i,j;
  // If there are any SMSs available()
  if (sms.available()) {
    Serial.println("Message received from:");



   //I think in this place I must delete all previous messages


    // 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("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    i = -1;
    j=0;//Mark for true or false
    while (c = sms.read()) {
      i =i+1;
      if (c != str1[i]) {j = 1;}//if symbol from message doesn't compare with symbol with massive then false (j=1)
      //Serial.println(str1[i]);
      Serial.print(c);//Print the message symbol
    }
    //Serial.println(j);
    //Serial.println(i);
    if ((j ==0 )&&(i == 3)) {//if all symbols compared and count of symbol equal in massive (i=1) then true   
      Serial.println("Temperature");


      
      } 

    // Delete message from modem memory
    Serial.println("\nEND OF MESSAGE");
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

My code compile and work well. I took it from arduino example modified it. On the code I wrote //I think in this place I must delete all previous messages
If you can’t help say about it honestly.

Hi,
What model arduino are you using?
What shield are you using? Link to data/specs please.

Thanks.. Tom... :slight_smile:

Hi,
Code in post #9, compiled for me, UNO and 1.6.11 IDE.

Tom... :slight_smile:

I use Arduino Uno r3 clone and GSM shild IComSat v1.1 with SIM900.