it is, but whilst I have now got something that works for the mobile number as entered, I am not sure I understand it properly.
whilst I get what certain parts of it are doing I don't fully understand, but having a play and see if I can gain a better understanding later
code extracted from:-
changes in my code:-
added pre setup();
const int EEPROM_MIN_ADDR = 0;
const int EEPROM_MAX_ADDR = 1023;
boolean eeprom_is_addr_ok(int addr) {
return ((addr >= EEPROM_MIN_ADDR) && (addr <= EEPROM_MAX_ADDR));
}
boolean eeprom_write_bytes(int startAddr, const byte* array, int numBytes) {
// counter
int i;
if (!eeprom_is_addr_ok(startAddr) || !eeprom_is_addr_ok(startAddr + numBytes)) {
return false;
}
for (i = 0; i < numBytes; i++) {
EEPROM.update(startAddr + i, array*);*
}
return true;
}
boolean eeprom_write_string(int addr, const char* string) {
int numBytes; // actual number of bytes to be written
//write the string contents plus the string terminator byte (0x00)
numBytes = strlen(string) + 1;
return eeprom_write_bytes(addr, (const byte*)string, numBytes);
}
boolean eeprom_read_string(int addr, char* buffer, int bufSize) {
byte ch; // byte read from eeprom
int bytesRead; // number of bytes read so far
if (!eeprom_is_addr_ok(addr)) { // check start address
return false;
}
if (bufSize == 0) { // how can we store bytes in an empty buffer ?
return false;
}
// is there is room for the string terminator only, no reason to go further
if (bufSize == 1) {
buffer[0] = 0;
return true;
}
bytesRead = 0; // initialize byte counter
ch = EEPROM.read(addr + bytesRead); // read next byte from eeprom
buffer[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
while ( (ch != 0x00) && (bytesRead < bufSize) && ((addr + bytesRead) <= EEPROM_MAX_ADDR) ) {
// if no stop condition is met, read the next byte from eeprom
ch = EEPROM.read(addr + bytesRead);
buffer[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
}
if ((ch != 0x00) && (bytesRead >= 1)) {
buffer[bytesRead - 1] = 0;
}
return true;
}
const int BUFSIZE = 15;
char buf[BUFSIZE];
String myString;
char myStringChar[BUFSIZE];
added in Current();- //so I can read the data without having to input again
eeprom_read_string(0, buf, BUFSIZE);
Serial.println(buf);
added in Number():-
Serial.println("Saving variable string to address 0");
myString=no1; //changed this line to use the string as inputed in the serial monitor, rather than the pre formatted number.
myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
strcpy(buf, myStringChar);
eeprom_write_string(0, buf);
Serial.print("Reading string from address 0: ");
eeprom_read_string(0, buf, BUFSIZE);
Serial.println(buf);
My code that's working and storing to EEPROM for the number.
```
*#include <SoftwareSerial.h>
#include <EEPROM.h>
SoftwareSerial mySerial(7, 8);
int EE1;
String no1;
String SMS1;
String ATD1= "ATD" + no1+";";
String Message2="Alarm";
String Siteid="Home\r";
String Message;
String Message1="Arm";
const int EEPROM_MIN_ADDR = 0;
const int EEPROM_MAX_ADDR = 1023;
boolean eeprom_is_addr_ok(int addr) {
return ((addr >= EEPROM_MIN_ADDR) && (addr <= EEPROM_MAX_ADDR));
}
boolean eeprom_write_bytes(int startAddr, const byte* array, int numBytes) {
// counter
int i;
if (!eeprom_is_addr_ok(startAddr) || !eeprom_is_addr_ok(startAddr + numBytes)) {
return false;
}
for (i = 0; i < numBytes; i++) {
EEPROM.update(startAddr + i, array[i]);
}
return true;
}
boolean eeprom_write_string(int addr, const char* string) {
int numBytes; // actual number of bytes to be written
//write the string contents plus the string terminator byte (0x00)
numBytes = strlen(string) + 1;
return eeprom_write_bytes(addr, (const byte*)string, numBytes);
}
boolean eeprom_read_string(int addr, char* buffer, int bufSize) {
byte ch; // byte read from eeprom
int bytesRead; // number of bytes read so far
if (!eeprom_is_addr_ok(addr)) { // check start address
return false;
}
if (bufSize == 0) { // how can we store bytes in an empty buffer ?
return false;
}
// is there is room for the string terminator only, no reason to go further
if (bufSize == 1) {
buffer[0] = 0;
return true;
}
bytesRead = 0; // initialize byte counter
ch = EEPROM.read(addr + bytesRead); // read next byte from eeprom
buffer[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
while ( (ch != 0x00) && (bytesRead < bufSize) && ((addr + bytesRead) <= EEPROM_MAX_ADDR) ) {
// if no stop condition is met, read the next byte from eeprom
ch = EEPROM.read(addr + bytesRead);
buffer[bytesRead] = ch; // store it into the user buffer
bytesRead++; // increment byte counter
}
if ((ch != 0x00) && (bytesRead >= 1)) {
buffer[bytesRead - 1] = 0;
}
return true;
}
const int BUFSIZE = 15;
char buf[BUFSIZE];
String myString;
char myStringChar[BUFSIZE];
///
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case '1':
Message = Siteid+Message1;
SendMessage();
break;
case '2':
Message = Siteid+Message2;
SendMessage();
break;
case'd':
DialCall();
break;
case 'm':
Number();
break;
case 'n':
Current();
break;
default:
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SMS1 ="AT+CMGS="" + no1 + ""\n\r";
mySerial.println(SMS1); // Replace x with mobile number mySerial.println("AT+CMGS="xxxxxxxxxx"\n\r");
delay(1000);
mySerial.println(Message);// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0\r"); // AT Command to recieve a live SMS
delay(1000);
}
void DialCall()
{
mySerial.println(ATD1); // ATDxxxxxxxxxx; -- watch out here for semicolon at the end!!"ATD07815698180;"
delay(30000);
mySerial.println("ATH");
delay(10000);
mySerial.println("ATDL");
}
void Number()
{Serial.println(" Enter Mobile Number:");// prompt user input
while(Serial.available()==0){}//wait for user input
no1 = Serial.readString(); //read input
Serial.println(no1);
/Serial.println(" Enter EEPROM value");// prompt user input
while(Serial.available()==0){}//wait for user input
EE1 = Serial.parseInt(); //read input
EEPROM.update(256,EE1);
Serial.println(EEPROM.read(256));/
//
Serial.println("Saving variable string to address 0");
myString=no1;
myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
strcpy(buf, myStringChar);
eeprom_write_string(0, buf);
Serial.print("Reading string from address 0: ");
eeprom_read_string(15, buf, BUFSIZE);
Serial.println(buf);
//
}
void Current()
{Serial.println("Current Mobile No:");
eeprom_read_string(15, buf, BUFSIZE);
Serial.println(buf);
//
}*
```