I am new to programming and have been experimenting using examples and code shared by others. I am trying to Read/Write to EEPROM using AVR/EEPROM.h library and eeprom_read_block/eeprom_write_block. My current project utilizes the GSM shield to send receive SMS. I want to store the phone number of an incoming SMS in certain cases and utilize in other sections of code. I wrote a sketch to test the capabilities. It compiles but does not produce intended results. The phone number prints out as yyyyyyyyyyyyyyyyyyyy. Any help is appreciated. Here is the sketch
*/
// include the GSM library
#include <GSM.h>
#include <avr/eeprom.h>
// PIN Number for the SIM
#define PINNUMBER ""
#define NUM_MAX 20
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char senderNumber[NUM_MAX];
//Array to define the number to send all SMS alerts
char smsNum[NUM_MAX];
//save location
char save[NUM_MAX];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Receiver");
// connection state
boolean notConnected = true;
// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
delay(60000);
sms.flush();
Serial.println("All Messages Deleted");
Serial.println("Waiting for messages");
}
void loop()
{
char c;
// If there are any SMSs available()
if (sms.available())
{
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
if (millis() < (300000)){
char *smsNum = senderNumber;
eeprom_write_block(save, smsNum, NUM_MAX);
Serial.print("SMS Number change accepted -");
eeprom_read_block(smsNum, save, NUM_MAX);
Serial.println(smsNum);
Serial.print("Sending Confirmation SMS");
sms.beginSMS(smsNum);
sms.print("Your phone will receive SMS alerts for this device");
sms.endSMS();
}
else{
Serial.println("sms number change locked");
eeprom_read_block(smsNum, save, NUM_MAX);
Serial.print("SMS Number is -");
eeprom_read_block(smsNum, save, NUM_MAX);
Serial.println(smsNum);
}
// Read message bytes and print them
while(c=sms.read())
Serial.print(c);
Serial.println("\nEND OF MESSAGE");
//Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
Serial.println("\nCOMPLETE!\n");
}
delay(1000);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.