Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« on: March 23, 2013, 02:53:04 am » |
Hello, i need help with a sketch. i am using this GSM module from iTead Studio. This sketch can only view and display the SMS once, i have to remove the sim, use a phone and delete all the read and unread sms. only when the sim is empty i can display the SMS. but like i said, i can only send 1 sms to it. the second time will not work. any body has any ideas? been very frustrated with this code.
thanks for the help!
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #1 on: March 23, 2013, 03:17:19 am » |
been very frustrated with this code What code ?
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #2 on: March 23, 2013, 04:32:51 am » |
LOL i tot i have uploaded -.- so sorry #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 numdata; boolean started=false; char smsbuffer[160]; char n[20];
void setup() { //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() { 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); } };
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #3 on: March 23, 2013, 05:14:44 am » |
I have solved the problem already, i just added this at the end void ProcessSms( String sms ){ } after that everything went well =) however i have a second problem. i want to activate an LED via SMS. when i SMS "on" the LED will light. the code is as below #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 A=7; int numdata; boolean started=false; char smsbuffer[160]; char n[20];
void setup() { //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"); pinMode( 7, OUTPUT ); 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); } } } } } if (smsbuffer== "on")digitalWrite(A, HIGH); }
void ProcessSms( String sms ){ }
the sketch can compile, but when i send "on" nothing happens i have tried using strcmp to compare stringa as well but that turned out a failure too....any suffestions? smsbuffer is the SMS content
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #4 on: March 23, 2013, 05:41:40 am » |
I have solved the problem already, i just added this at the end
Code: void ProcessSms( String sms ){ } What does that function do ? Where is it called from ?
|
|
|
|
« Last Edit: March 23, 2013, 05:44:55 am by UKHeliBob »
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #5 on: March 23, 2013, 05:50:29 am » |
As to your other problem. What do you get when you print smsmbuffer having sent an SMS message "on" ? If the message looks correct when printed,(I would surround it with start/end marker such as [ and ] ) then you should be suspicious of your test if (smsbuffer== "on")
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #6 on: March 23, 2013, 07:03:30 am » |
What does that function do ? Where is it called from ? honestly, i have no idea....biggest mystery haha. i just tried an error What do you get when you print smsmbuffer having sent an SMS message "on" ? on the serial monitor, it says "on" but the led does not light up. basically what SMS i send to the arduino GSM, it will appear on the serial Monitor. in my case "smsbuffer" is a variable right? so is there a way to say if this vairiable = "on" then <action>?
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #7 on: March 23, 2013, 09:40:00 am » |
if (strcmp (smsbuffer,"on") == 0) { Serial.println("match"); }
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #8 on: March 23, 2013, 11:54:09 pm » |
Hi, thanks for the reply! unfortunately it still did not work  however, when i changedit to >=0, it can display "match" in serial monitor, but led not lit, my sketch is as below if (strcmp (smsbuffer,"on") >= 0) { digitalWrite(led, HIGH); Serial.println("Match On"); } if (strcmp (smsbuffer,"off") >= 0) { digitalWrite(led, LOW); Serial.println("Match Off"); Thanks! i know its close to accomplish!!
|
|
|
|
« Last Edit: March 23, 2013, 11:58:06 pm by desmondttm123 »
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #9 on: March 24, 2013, 12:05:57 am » |
Hi an add on to my previos reply, i can get the led to on if i remove the"off" because in the serial monitor it dislays
on match on match off
how should i improve it? thanks!!!!
This is the full serial monitor, i dont understand the pattern, some text other than "off" can turn it off and same as "on" can anyone explain ? GSM Shield testing.
status=READY 13/03/24,13:57:05+3 Abc
Match OFF
Ate
Match OFF 13/03/24,13:57:37+3 Am
Match OFF 13/03/24,13:57:52+3 On
Match ON 13/03/24,13:58:07+3 Op
Match ON Desmond Pe
Match ON Desmond ad
Match ON 13/03/24,13:59:16+3 Shj
Match ON 13/03/24,13:59:31+3 Off
Desmond Abc
Match OFF Desmond Abc
Match OFF
|
|
|
|
« Last Edit: March 24, 2013, 01:02:48 am by desmondttm123 »
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #10 on: March 24, 2013, 02:46:16 am » |
A zero value returned from strcmp indicates that both strings are equal. Try printing out the values to see what is going on. Whatever is happening, your test must be for zero otherwise you are testing that teh two strings don't match.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #11 on: March 24, 2013, 03:52:04 am » |
Hi,When i put if (strcmp (smsbuffer,"On") == 0) this is the results in the serial monitor. however if i put >= 0 it works..i dont understand GSM Shield testing.
status=READY 13/03/24,16:50:04+3 On
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #12 on: March 24, 2013, 04:18:05 am » |
What I meant was for you to print out the value of the strcmp. If it is not zero then the strings do not match.
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Full Member
Karma: 3
Posts: 166
Stay calm and call batman!
|
 |
« Reply #13 on: March 24, 2013, 05:00:34 am » |
Im sorry i still dont quite understand..can u explain? or give an example?
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 55
Posts: 1599
May all of your blinks be without delay
|
 |
« Reply #14 on: March 24, 2013, 06:57:03 am » |
Serial.print(smsbuffer is : "; Serial.println(smsbuffer); Serial.print("The result of strcmp is : "; Serial.println((strcmp (smsbuffer,"On")); if (strcmp (smsbuffer,"On") == 0)
If strcmp is not zero then the strings don't match but the value printed may help diagnose what is going on.
|
|
|
|
|
Logged
|
|
|
|
|
|