I wanted to my GSM to recieve SMSs. I have written a sketch for it. But while verifying the sketch an error pops out in this part:
if (sms.available()) {
sms.remoteNumber(senderNnumber, 20);
if (senderNumber == "09432167015") {
c = sms.read();
if (c == "yes") {
alarm_police();
}
}
}
The error message:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Uno"
GuardDog_v2.5.ino: In function 'void loop()': GuardDog_v2.5:201: error: 'senderNnumber' was not declared in this scope GuardDog_v2.5:204: error: ISO C++ forbids comparison between pointer and>integer [-fpermissive] 'senderNnumber' was not declared in this scope
This report would have more information with "Show verbose output during compilation" enabled in File> Preferences.
I have checked the receiving sms example and have written the sketch according to the example.I need help regarding this error and how to fix it
-
You have a scope problem and you are comparing a pointer to an integer. Show us the rest of your sketch and provide a link to the library u're usingSoreDakeNoKoto– SoreDakeNoKoto2016年01月29日 14:57:20 +00:00Commented Jan 29, 2016 at 14:57
-
The sketch is a bit too big and contains parts which are not related to GSM. Should I show the complete sketch? BTW the library I used is the default GSM library which is present in the IDE.HDatta– HDatta2016年01月29日 15:22:18 +00:00Commented Jan 29, 2016 at 15:22
1 Answer 1
You misspelled the variable senderNumber
. Correct it. Also you aren't reading the SMS properly or comparing the phone numbers properly. Your code should be like this (using the examples):
#define MAX_MSG 50
char senderNumber[20];
char sms_buf[MAX_MSG]; // a buffer for your sms, max len = 50
if (sms.available()) { // this part should be in loop()
sms.remoteNumber(senderNumber, 20);
if (strcmp(senderNumber, "09432167015") == 0) { // compare numbers
while (sms.available() == 0); // wait for a char
char i = 0;
while (i < MAX_MSG - 1){ // till max len is reached; 1 byte for null
c = sms.read();
if (c == '0円') // assuming the modem terminates sms with null
break;
sms_buf[i++] = c; // write char to the buffer
while (sms.available() == 0); //wait for a char
}
sms_buf[i] = 0; // terminate the string, just in case
if (strstr(sms_buf, "yes") != NULL) // look for 'yes' in buffer
alarm_police();
}
}
-
-
It can be a char or int; just edited itSoreDakeNoKoto– SoreDakeNoKoto2016年01月30日 11:06:59 +00:00Commented Jan 30, 2016 at 11:06
-
during the upload an error for char sms_buf[MAX_MSG]; pops up: array bound is not an integer constant before ']' token.HDatta– HDatta2016年02月01日 12:40:21 +00:00Commented Feb 1, 2016 at 12:40
-
Change MAX_MSG to int and try againSoreDakeNoKoto– SoreDakeNoKoto2016年02月01日 13:17:38 +00:00Commented Feb 1, 2016 at 13:17
-
I had used int for MAX_MSG it doesn't work for both char and intHDatta– HDatta2016年02月02日 07:04:05 +00:00Commented Feb 2, 2016 at 7:04