#include "Adafruit_FONA.h"
#define FONA_RST 5
#define FONA_RI_INTERRUPT 0
#include <EEPROM.h>
#include <SoftwareSerial.h>
#define FONA_RX 4
#define FONA_TX 3
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
const int button1 = 12, button2 = 11, swtch = 9;
void setup()
{
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(swtch, INPUT_PULLUP);
Serial.begin(115200);
Serial.println(F("Init..."));
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial))
{
Serial.println(F("GSM NOT FOUND"));
while (1);
}
Serial.println(F("FONA is OK"));
// Enable incoming call notification.
if (fona.callerIdNotification(true, FONA_RI_INTERRUPT))
{
Serial.println(F("C_id n. en"));
EEPROM.write(7,1);
}
}
void loop()
{
char phone[32] = {0};
// Check for an incoming call. Will return true if a call is incoming.
if (fona.incomingCallNumber(phone))
{
Serial.println(F("RING!"));
Serial.print(F("Phone Number: "));
Serial.println(phone);
if (digitalRead(button1) == LOW)
{
for (int k = 0; k < 12; k++)
{
EEPROM.update(101 + k, phone[k + 3]); delay(60);
Serial.print(phone[k + 3]);
}
char phn[12] = {0};
Serial.println(F("Saved Phn number: "));
for (int i = 0; i < 12; i++)
{
phn[i] = EEPROM.read(101 + i);
}
Serial.println(phn);
//reject the call
if (! fona.hangUp()) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
delay(1000);
String text = "1st number: " + String(phn);
int length_text = text.length() + 1;
char sms_text[length_text];
text.toCharArray(sms_text, length_text);
if (!fona.sendSMS(phn, sms_text))
{
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
EEPROM.update(1,1);
}
if (digitalRead(button2) == LOW)
{
for (int k = 0; k < 12; k++)
{
EEPROM.update(201 + k, phone[k + 3]); delay(60);
Serial.print(phone[k + 3]);
}
char phn[12] = {0};
Serial.println(F("Saved Phn number: "));
for (int i = 0; i < 12; i++)
{
phn[i] = EEPROM.read(201 + i);
}
Serial.println(phn);
//reject the call
if (! fona.hangUp()) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
delay(1000);
String text = "2nd number: " + String(phn);
int length_text = text.length() + 1;
char sms_text[length_text];
text.toCharArray(sms_text, length_text);
if (!fona.sendSMS(phn, sms_text))
{
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
EEPROM.update(2,1);
}
}//fona end
}
//