need to compare a received phone number callerIDbuffer to phone numbers hardcoded and change a variable reply from 0 to 1
tried code below and got switch quantity not integer and other errors. All the examples I have seen the case is either one letter or number not a string.
I know I can do it with if then else statemnts if it can be done but would like to know if only one letter or number can be used in the label of a case statement.
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
char callerIDbuffer[]="+12222222222";
char phone_numberMaritza[] = "+12222222222";
char phone_numberAnna[] = "+13333333333";
char phone_numberChip[] = "+14444444444";
int reply;
void setup() {
// put your setup code here, to run once:
// Open serial communications and wait for port to open:
while (!Serial)
Serial.begin(115200);
; // wait for serial port to connect. Needed for native USB port only
Serial.begin(115200);
Serial.println(F("FONA SMS caller ID test"));
Serial.println(F("Initializing....(May take 3 seconds)"));
// make it slow so its easy to read!
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
Serial.println(F("FONA is OK"));
}
void loop() {
Serial.println(F("comparing caller ID to phonenumber"));
switch (callerIDbuffer){
case phone_numberMaritza:
reply=1;
break;
case phone_numberAnna:
reply=2;
break;
case phone_nmberChip:
reply=3;
break; }
//if(strcmp(callerIDbuffer, phone_numberMaritza)==0){// works as string comparison
// reply = 1; //
Serial.print(F("reply after if= ")); Serial.println(reply);}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.