Hello ! I have an Icomsat that activates a relay upob receiveing an "on" sms and turns off upon receiving an "off" sms. it works.....sometimes..... the code is bellow.
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"
//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to send and receive SMS.
int led = 7;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup()
{
pinMode(led, OUTPUT);
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started){
//Enable this two lines if you want to send an SMS.
//if (sms.SendSMS("3471234567", "Arduino SMS"))
//Serial.println("\nSMS sent OK");
}
};
void loop()
{
char position1 = sms.IsSMSPresent(SMS_READ);
char position2 = sms.IsSMSPresent(SMS_UNREAD);
char position3 = sms.IsSMSPresent(SMS_UNREAD);
char position4 = sms.IsSMSPresent(SMS_UNREAD);
if(started){
//Read if there are messages on SIM card and print them.
if(gsm.readSMS(smsbuffer, 160, n, 20))
{
Serial.println(n);
Serial.println(smsbuffer);
}
delay(1000);
if (position1) {
sms.DeleteSMS(position1);
if (position2) {
sms.DeleteSMS(position2);
if (position3) {
sms.DeleteSMS(position3);
if (position4) {
sms.DeleteSMS(position4);
}
}
}
}
}
Serial.print("smsbuffer is: [");
Serial.print(smsbuffer);
Serial.println("]");
Serial.print("The result of strcmp is : ");
Serial.println((strcmp (smsbuffer,"On")));
if (strcmp (smsbuffer,"On") == 13)
{
Serial.print("match On");
digitalWrite(led,HIGH);
}
else
if (strcmp (smsbuffer,"On") == -8)
{
Serial.print("match Off");
digitalWrite(led,LOW);
}
}
void ProcessSms( String sms ){
}
the serial print is as bellow
GSM Shield testing.
status=READY
13/04/17,20:18:08+3
On
smsbuffer is: [On
]
The result of strcmp is : 13
match OnDesmond
Off
smsbuffer is: [Off
]
The result of strcmp is : -8
match OffDesmond
Off
smsbuffer is: [Off
]
The result of strcmp is : -8
match OffDesmond
+CMT: "+60168100114","Desmond","13/04/17,20:19:38+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:19:38+32"
]
The result of strcmp is : -36
Desmond
On
smsbuffer is: [On
]
The result of strcmp is : 13
match OnDesmond
On
smsbuffer is: [On
]
The result of strcmp is : 13
match OnDesmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:18+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:18+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
Desmond
+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
smsbuffer is: [+CMT: "+60168100114","Desmond","13/04/17,20:21:57+32"
]
The result of strcmp is : -36
notice that there is a repeat. when the text is on, its suppose to be strcmp = 13 and strcmp = -8 when off.... however occasionally a -36 appears i dont know where this comes from. as in sometimes when i sms "on" instead of 13 it appears -36..... any ideas? also the serial print keeps repeating itself i have no idea why... is it because of void loop? your help is much appreciated!!!!!!