Hello everybody,
I want to write the content of a received sms(phonenumber) into the EEPROM. The problem is that the sms is a char value and I need it as a char array to write every single sign to a specific address of the EEPROM. How can I do this?
I want to convert e.g:
char a='06604545'; to char a[]={'0','6'....};
I am looking forward hearing from you. 
char a='06604545';
This is most certainly not what you have because a char, by definition, can only hold a single character.
Please post your complete program so that we can see what you are talking about. When posting the code please use code tags (</>) to make it easier to copy.
#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSM_SMS sms;
char senderNumber[20];
char smsnumber[15];
void setup()
{
Serial.begin(9600);
Serial.println("SMS Messages Receiver");
boolean notConnected = true;
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
void loop()
{
char a;
if (sms.available())
{
Serial.println("Message received from:");
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
if (sms.peek() == '#')
{
Serial.println("Discarded SMS");
sms.flush();
}
while (a = sms.read())
Serial.print(a);
char smsnumber[15]=a; //Here we want to copy the content of char a to char smsnumber[15]
int addr = 0;
while(addr<=15)
{
EEPROM.write(addr, smsnumber[addr]);
addr=addr+1;
}
Serial.println("\nEND OF MESSAGE");
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
while (a = sms.read())
What's this all about ?
char smsnumber[15] = a; //Here we want to copy the content of char a to char smsnumber[15]
a is a single character. Why are you copying it to a newly declared array named smsnumber?
char smsnumber[15] = a; //Here we want to copy the content of char a to char smsnumber[15]
a is a single character. Why are you copying it to a newly declared array named smsnumber?
because I want to write the char array with the whole SmS into the EEProm and not only one char
Instead of this:-
while (a = sms.read())
Serial.print(a);
char smsnumber[15]=a; //Here we want to copy the content of char a to char smsnumber[15]
What about this:-
char smsnumber[15];
byte index=0;
while (a = sms.read())
{
smsnumber[index]=a;
Serial.print(a);
index++;
}
smsnumber[index]='\0';
or this:-
char smsnumber[15];
byte index=0;
while (a = sms.read())
{
smsnumber[index]=a;
index++;
}
smsnumber[index]='\0';
Serial.print(smsnumber);
because I want to write the char array with the whole SmS into the EEProm and not only one char
But a is a single character. If it held the whole of the number then you would not need to copy it to another array. Have you tried printing a anywhere in your code to see what it really contains ?
Take the advice in this thread and put each character into the smsnumber array as it is received and terminate it with a zero to turn it into a C style string.
This needs ==
while (a = sms.read())
or a comparison does not occur.
CrossRoads:
This needs ==
while (a = sms.read())
or a comparison does not occur.
OOPs, slipped. Quite right. I'll edit that.
(I copied and pasted the original line without looking at it properly.
)
Corrected 'properly' now. The comparison is for true/false on the read itself, not on the value read.
Thanks a lot guys. Now it works.
I don't think that I need a "==" because because the value should be allocated to a and not compared.
davidwobak:
Thanks a lot guys. Now it works.
I don't think that I need a "==" because because the value should be allocated to a and not compared.
Now I'm agreeing with everyone. 
You are correct. It's late and I'm half asleep and CrossRoads is wrong. (See how easily I can be led when I'm tired.
)
You're allocating to 'a', then testing for true if a character was read. As fickle as it is, I'll edit back for anyone in the future. (At least it's half right as-is.)
I'm going to bed for some obviously badly-needed sleep.
Guess I don't follow what sms.read() does.
CrossRoads:
Guess I don't follow what sms.read() does.
If 'a==sms.read()' is used, 'a' never receives the value that sms.read() actually returns and everything falls apart.
OMG, the code was silently copied from there! It would have been courteous to let us know!
Does sms.read actually return a null character at the end? According to the documentation, it returns -1 when no more data is available. In that case you need to save the return value in an int variable and check for -1 instead of 0.
aarg:
https://www.arduino.cc/en/Reference/GSMSMSRead
OMG, the code was silently copied from there! It would have been courteous to let us know!
Well spotted. That's why the OP had no curly brackets around the two lines after the 'while()', which was part of the problem - because the original only had one line and didn't need them.
(I guess you figured out why the 'while()' loop is there. Glad I'm not the only one making mistakes.
)