Pages: [1]   Go Down
Author Topic: Storing Phone Numbers for GSM project in EEPROM  (Read 1027 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am currently working on a GSM project where I want to store a phone number send through an SMS into the EEPROM.
This phone number will be then set as the number for Authorising future SMS. If SMS is send from any other number, they will get a reply as unauthorised access.

I have finished all the GSM coding part and they are working fine (with a phone number stored in the code).

Now I want the number to be stored into the EEPROM.
When I did the coding its showing error.

Error -1
error: no matching function for call to 'EEPROMClass::write(int&, String&)'

I am using the following code to retrieve the phone number (I am just attaching a snippet of the code as the whole code is very big)-

char smsbuffer[20];
char n[20];

void loop()
{
gsm.readSMS(smsbuffer, 20, n, 20)
}

I tried converting the String to int but dint work.

Please help
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When I did the coding its showing error.

Error -1
error: no matching function for call to 'EEPROMClass::write(int&, String&)'
So, don't try to call that version.

Quote
I am using the following code to retrieve the phone number
But, storing it is where you have problems. So, what use is the reading code?

Quote
I tried converting the String to int but dint work.
Then, you did it wrong. And, you shouldn't be converting the string to a String, anyway.


Why are you trying to convert a phone number to an int, anyway? Is your phone number in the range -32767 to 32767? If so, it's a most unusual phone number.

Why not just store the phone number as text, as you have it?

Posting at least some code that is related to what you are trying to do is going to be essential.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please note that, at present, the String library has bugs as discussed here and here.

In particular, the dynamic memory allocation used by the String class may fail and cause random crashes.

I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul,

In my code I am using gsm.readSMS to retrieve the number. The method reads the number into a char array.
This is the first time I have tried writing data into eeprom.
The number is a 10 digit one and I need to store it into the EEPROM
But it allows me to write only "uint8_t" type data. So I tried converting it into unsigned int using the below code but it dint work.
Code:
unsigned int numE;
numE = num.toInt();


Here is my complete code -

Code:
//#include <EEPROM.h>

#include <SoftwareSerial.h>
#include <SIM900.h>
#include <sms.h>
SMSGSM sms;
#include <String.h>

int numdata;
boolean started=false;
char smsbuffer[20];
char n[20];
int pin=8;
int pinT=0; //Temperature Sensor
float temp;
int addr=0;
void setup()
{
  
  pinMode(pin,OUTPUT);
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
    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");
  }
     delA();

}

void loop()
{
  if(started){
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 20, n, 20)){//message,msg length, number , number length
     String num=n;
     String smsIn=smsbuffer;
     int flag=0;
    
     temp = ( 5.0 * analogRead(pinT) * 100.0) / 1024.0;
    
    if(num.equals("+111234123412")){
    Serial.print("Authorised");
    Serial.println(n);
    Serial.println(smsbuffer);
      
          
     if(strcmp(smsbuffer,"ON")==13){
      flag=1;
      Serial.println(strcmp(smsbuffer,"ON"));
    }          
    else if(strcmp(smsbuffer,"OFF")==13){
      flag=2;
      Serial.println(strcmp(smsbuffer,"OFF"));
      
    }
    else{    
    Serial.println("Unknown Command. Please try again");
    Serial.println("Executing delete");
    delF();
    }
    if(flag==2){    
    Serial.println("System OFF");
    digitalWrite(pin,LOW);
    sms.SendSMS(n, "System OFF");
    delF();
    }
    else if(flag==1){    
    Serial.println("System ON");
    digitalWrite(pin,HIGH);
    sms.SendSMS(n, "System ON");
    delF();
    }
    
  }  
    else{    
     Serial.print("Unauthorised");
     if (sms.SendSMS(n, "Unauthorised Access"))
     Serial.println("\nSMS sent OK");
     delF();
   }  
    
   }
    delay(1000);
    
  }
    
};

void delF()
{
 Serial.println("Executing delete");
     for (int j=0;j<=4;++j){    
     Serial.println(sms.DeleteSMS(j));
     }
}

void delA()
{
 Serial.println("Executing delete");
     for (int j=0;j<=20;++j){
       Serial.println(sms.DeleteSMS(j));
     }
}

/*void storeNum(String num)
{
  //unsigned int numE;
  //numE = num.toInt();
  EEPROM.write(addr,num);
  addr = addr + 1;
  if (addr == 512)
     addr = 0;
  
  delay(100);
}*/


All I want is to write the retrieved char data into EEPROM.

And thanks a lot for your reply.
« Last Edit: November 16, 2012, 02:15:27 am by sanjumathew » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Nick,

I also had some issues with string during my previous projects. In this one I was just experimenting on converting char to String and coparing two strings or chars.

What I basically have is a char array of 12 which I need to store in the EEPROM.
Went through the internet a lot but couldn't get it done properly.

Thanks for your reply and I will try avoiding String in my projects for a while (or since it all gets fixed). smiley
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25763
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/playground/Code/EEPROMWriteAnything
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In my code I am using gsm.readSMS to retrieve the number. The method reads the number into a char array.
This is the first time I have tried writing data into eeprom.
The number is a 10 digit one and I need to store it into the EEPROM
But it allows me to write only "uint8_t" type data
A char and a uint8_t are the same size. What a happy coincidence. Well, not really. It was intentional.

Simply iterate through the array, storing one character (cast it to a uint8_t, if needed) at a time.
Logged

Pages: [1]   Go Up
Jump to: