#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(7, 8);
char incomingByte;
String inputString;
void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, LOW);
pinMode(3, LOW);
Serial.begin(9600);
gsmSerial.begin(9600);
while (!gsmSerial.available())
{
gsmSerial.println("AT");
delay(1000);
Serial.println("Connecting...");
}
Serial.println("Connected!");
gsmSerial.println("AT+CMGF=1");
delay(1000);
gsmSerial.println("AT+CNMI=1,2,0,0,0");
delay(1000);
gsmSerial.println("AT+CMGL=\"REC UNREAD\"");
}
void loop()
{
if (gsmSerial.available())
{
inputString = "";
delay(1000);
while (gsmSerial.available())
{
incomingByte = gsmSerial.read();
inputString += incomingByte;
}
delay(100);
// inputString.replace("\n","");
Serial.print("input : ");
Serial.print(inputString);
Serial.println(" end");
inputString.toUpperCase();
Serial.println("input up : " + inputString);
if (inputString.indexOf("ON1") > 0)
{
pinMode(2, HIGH);
}
f(inputString.indexOf("ON2") > 0)
{
pinMode(3, HIGH);
}
if (inputString.indexOf("OFF1") > 0)
{
pinMode(2, LOW);
}
if (inputString.indexOf("OFF2") > 0)
{
pinMode(3, LOW);
}
delay(50);
if (inputString.indexOf("OK") > -1)
{
gsmSerial.println("AT+CMGDA=\"DEL ALL\"");
delay(1000);
}
}
}