Dears,
I am using arduino UNO with this IComSat gsm shield. On top of those I tried to use both libraries:
- GitHub - MarcoMartines/GSM-GPRS-GPS-Shield: GSM/GPRS & GPS Shield Library for modules using SIM900/SIM908
- GitHub - Seeed-Studio/GPRS_SIM900: library for GPRS shield with sim900 module.
Even thought libraries are working perfectly (send/receive sms) I cannot use the sms read method based on timer events.
Please have a look:
#include <TimerOne.h>
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define PIN_TX 2
#define PIN_RX 3
#define BAUDRATE 9600
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char phone[16];
char datetime[24];
GPRS gprsTest(PIN_TX,PIN_RX,BAUDRATE);//RX,TX,PWR,BaudRate
void setup() {
Serial.begin(9600);
while(!gprsTest.init()) {
Serial.print("init error\r\n");
delay(1000);
}
delay(3000);
Serial.println("Init Success, please send SMS message to me!");
delay(1000);
/*TIMER 1*/
Timer1.initialize(500000); // initialize timer1, and set a 1/2 second period
Timer1.attachInterrupt(readSMS); // attaches callback() as a timer overflow interrupt
Timer1.setPeriod(13000000);
}
void loop() {
}
void readSMS()
{
Serial.print("/");
messageIndex = gprsTest.isSMSunread();
Serial.println("=");
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
Serial.print("From number: ");
Serial.println(phone);
Serial.print("Datetime: ");
Serial.println(datetime);
Serial.print("Recieved Message: ");
Serial.println(message);
}
else
{
Serial.println("No unread sms");
}
}
The result of the above code on my terminal is to have only one time this:
Init Success, please send SMS message to me!
/
My purpose is to check for unread SMS every 13000000 uS, and keep the main loop to handle other routines.
Could you please let me know why the posted code won't work?