SMS command processing

Okay, struggling a little.

after getting to grips with using serial and being able to submit Telelphone numbers in the format

SMS1, SMS2 etc and saving to EEPROM I am able to do this for as many as I can store.

however, I now want to send an SMS command read the number and store it.

Currently I can read the SMS command that's sent in and store it to the same address allocation, whether be number for SMS1 or SMS2, SMS etc etc

command gets sents as SMS107xxxxxxxxx
we find SMS and the process it

I could if out each scenario,
ie

if(mySerial.find("SMS1")){

and

if(mySerial.find("SMS1")){

etc

but must be a smarter way?

as you can see, want to use i to provide the int to calculate where to store the data, although it will be i-1, if I take the value 1 from the SMS1, 2 if SMS2 etc

current code for the recieved message processing is:-

void RecieveMessage(){


mySerial.println("AT+CMGF=1\r");
mySerial.println("AT+CNMI=2,2,0,0,0\r"); // AT Command to recieve a live SMS

 while(1){if(mySerial.find("SMS")){ 
    no1 = mySerial.readString();
    Serial.println(no1);
  Serial.print("Saving variable string to address: ");
  Serial.println(i*11);
  myString = no1.substring(1);
   Serial.println(myString);
  myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
  strcpy(buf, myStringChar);
  eeprom_write_string((i*11), buf); 
  Serial.print("Reading string from address : ");
  Serial.println(i*11);
  eeprom_read_string((i*11), buf, BUFSIZE);
  Serial.println(buf);

 }}

Any guidance apprciated even if it is to look up a tutorial or reference material so i can try and understand.

You are combining a serial parse function with a eeprom store/retrieve function.
There may be more elegant ways to parse the result of your AT commands.
Google for "arduino parse sms data" to see other examples.

Regarding the eeprom, this is used normally for persistent storage which survives a shutdown.
Are you simply trying to accumulate all the incoming callers ?
Are you going to store the value of the index so that at the next system start, it does not overwrite the numbers from the last session ?

// these functions can be replaced by EEPROM.get() and EEPROM.put()
eeprom_read_string((i * 11), buf, BUFSIZE);
eeprom_write_string((i * 11), buf);

// this loops forever
while (1) { . . . }

OP, you have 25 posts.
By now, you should know how to post in tags.
Try reading the stickies.

Thanks for taking the time to reply.

@code posting, yeah that was a mistake these things happen, now corrected when I last checked.

In theory the power shouldn't be lost once the module is setup, certain data will need to remain after a power cycle, if it does occur. In theory once setup it will rarely ever change.

Currently the module is work in progress.

first objective get it working // can live with an untidy but functional system
second objective get it working smarter // learning
third objective get the code clean. // ultimate goal

I'll be honest been through many examples and had trouble getting some working full stop.

At the moment, I am only storing 3 numbers, in my original code i was able to enter them from the Serial monitor and prompted for each one in turn.

recalling the numbers start at 0, 11 and 22 so the indexs are not saved as i know where they are starting from so they are hard coded, I say hard coded.

I will revisit some the searches and have another look at my options.

below is what i was using for the Serial Monitor entries.

void Number(){
  int i;
  for (i = 0; i < 3; i++) {
    Serial.print("Input Mobile Number: ");
    Serial.println(i+1);
  Serial.println("Awaiting Input"+i);
    while(Serial.available()==0){}//wait for user input
    
    no1 = Serial.readString(); //read input
    //Serial.println(i+1);
    Serial.println(no1);
    if(no1.startsWith("SMS",0)){  
    Serial.println(i+1);
   
    Serial.print("Saving variable string to address: ");
    Serial.println(i*11);
    no1s = no1.substring(4);
    myString=no1s;
   
    myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
    strcpy(buf, myStringChar);

    eeprom_write_string((i*11), buf); 

    Serial.print("Reading string from address : ");
    Serial.println(i*11);
    eeprom_read_string((i*11), buf, BUFSIZE);
    Serial.println(buf);
  
    }
  }
}

Okay.

haven't got smart way of handling the telephone numbers as yet when I send them in via a text message.

  1. send in the SMS as SMS107xxxxxxxx and SMS207xxxxxxxx etc etc
  2. the system see the text come in and searchs for SMS while(1){if(mySerial.find("SMS")){
  3. then This is read to String no1 and passed to the function NumberProcessing
  4. this then based on the starts with 1,2 etc uses an if statement to process and store it in EEPROM
void RecieveMessage(){
 
  mySerial.println("AT+CMGF=1\r");
  mySerial.println("AT+CNMI=2,2,0,0,0\r"); // AT Command to recieve a live SMS

   while(1){if(mySerial.find("SMS")){ 
      no1 = mySerial.readString();
       NumberProcess();
    }}

and

  Serial.println(no1);
  if(no1.startsWith("1")){
  Serial.print("Saving variable string to address: ");
  Serial.println(0);
  myString = no1;
  Serial.println(myString);
  myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
  strcpy(buf, myStringChar);
  eeprom_write_string((0), buf); 
  Serial.print("Reading string from address : ");
  Serial.println(0);
  eeprom_read_string((0), buf, BUFSIZE);
  Serial.println(buf);}
else{ if(no1.startsWith("2")){
  Serial.print("Saving variable string to address: ");
  Serial.println(11);
  myString = no1;
  Serial.println(myString);
  myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
  strcpy(buf, myStringChar);
  eeprom_write_string((11), buf); 
  Serial.print("Reading string from address : ");
  Serial.println(11);
  eeprom_read_string((11), buf, BUFSIZE);
  Serial.println(buf);}
 }}

There will be other messages being received to determine the strings stored, this can be processed in a similar way, but don't think its smart.

at least 2 messages for pins activated and deactivated (2 lots of data for each Pin), cant see there ever being more than 10 pins (20 messages), but with this method I could only done 9 pins.

However 1 number may be stored, or upto 9 this way, as starts with 10 would end up with the SMS1 and SMS10 being confused, as SMS107xxxxx starts 10. Can't see me ver needing 9 number in the project but its a fair point.

Apart from losing the String variables, you’re on the right track.
You’re already using arrays.

Next step, make your storage a 2D array of numbers
e.g.
char myStorage[4][11]:
Then you have instant access to [4+1] strings of [11-1] characters each - with the trailing NULL.
(Careful - if your BUFSIZE is 11, fully qualified phone numbers can have more than 10 digits...)
e.g. +61402123456

Your ‘save’ function can become
eeprom_write_string(myStorage[index], buf);
where index is the index into your phone list.

Pulling numbers back from eeprom is the reverse.

Thanks for your reply.

I will look at this later, not sure its making any sense at the minute, need some time out to recharge.