I am trying this code which I found from a tutorial where he used an Arduino UNO Clone. The code below is to turn on or off an LED on pin 7 after an SMS instruction is received.
In my project I want to use an Arduino Mega 2560 so I needed to modify some lines in the GSM Library for GSM Shield based on SIM900 which it got from "http://www.gsmlib.org/"
Unfortunately I ran into these error after compiling the sketch:
C:\Users\alexi\Downloads\arduino-1.6.7\libraries\GSMSHIELD\HWSerial.cpp: In member function 'size_t HWSerial::print(const __FlashStringHelper*)':
C:\Users\alexi\Downloads\arduino-1.6.7\libraries\GSMSHIELD\HWSerial.cpp:55:9: error: 'prog_char' does not name a type
const prog_char *p = (const prog_char *)ifsh;
^
In file included from C:\Users\alexi\Downloads\arduino-1.6.7\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,
from C:\Users\alexi\Downloads\arduino-1.6.7\libraries\GSMSHIELD\HWSerial.h:6,
from C:\Users\alexi\Downloads\arduino-1.6.7\libraries\GSMSHIELD\HWSerial.cpp:1:
C:\Users\alexi\Downloads\arduino-1.6.7\libraries\GSMSHIELD\HWSerial.cpp:58:37: error: 'p' was not declared in this scope
unsigned char c = pgm_read_byte(p++);
^
exit status 1
Error compiling.
Below is the sample sketch:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
char number[]="ur cellphone number here";
char message[180];
char pos;
char *p;
void setup() //declaring inputs and outputs
{
Serial.begin(9600); //initiate gizduino witha baud rate of 9600
pinMode(13, OUTPUT); //output for turning LED ON or OFF
if (gsm.begin(9600)) //condition if gsm is initialized
Serial.println("\nstatus=READY"); //displays "ready" on the serial monitor if gsm is ready
else Serial.println("\nstatus=IDLE"); //otherwise displays "idle" on the serial monitor if gsm is not found
};
void loop() //looping of the program
{
pos=sms.IsSMSPresent(SMS_UNREAD); //save to variable if there is an SMS
Serial.println((int)pos); //display position number (a.k.a index) of the message
if((int)pos>0&&(int)pos<=20) //if message from 0-20 is found
{
Serial.print("Message Received, INBOX="); //display an output on the serial monitor
Serial.println((int)pos); //display the position/index of the message
message[0]='\0'; //display '0' if no messages found
sms.GetSMS((int)pos,number,message,180); //get position/index, number of sender, and text message
Serial.println(message); //display the text on serial monitor
if(strstr(message, "ON")) digitalWrite(13,HIGH); //if message 'ON' is received, LED is ON
if(strstr(message, "OFF")) digitalWrite(13,LOW); //if message 'OFF' is received, LED is OFF
sms.DeleteSMS((int)pos); //after reading, delete SMS
}
delay(5000); //delay of 5seconds per loop
};