I try to send a message from my cell phone to the module so that it appears on the screen and at the same time (depending on the case), turn on or off a led, but instead of the message I sent I get <+ CIEV: "SMSFULL ", 2> in addition to the fact that the led does nothing.
I leave the code:
/ *
************* WORKING WITH THE A6 MODULE *****************
* /
#include <SoftwareSerial.h>
String PHONE = ""; // For multiple users
String msg;
// Pin RX del módulo a Arduino 9
// Pin TX del módulo a Arduino 8
#define rxPin 9
#define txPin 8
SoftwareSerial mySerial(txPin, rxPin);
#define LED_PIN 13
void setup() {
pinMode(LED_PIN, OUTPUT); // Configuration of pin 13 as output
digitalWrite(LED_PIN, LOW);
delay(1000);
Serial.begin(115200);
Serial.println("Initializing Serial... ");
mySerial.begin(115200);
Serial.println("Initializing GSM module...");
mySerial.println("AT+CMGF=1\r"); //SMS text mode
mySerial.println("AT+CNMI=1,2,0,0,0");
delay(1000);
}
void loop()
{
while (mySerial.available())
{
parseData(mySerial.readString());//Call the parseData function to parse SMS
}
doAction(); //Take the necessary action according to the SMS message
while (Serial.available())
{
mySerial.println(Serial.readString());
}
}
void parseData(String buff)
{
Serial.println(buff);
unsigned int index;
//Remove the "AT Command" sent from the reply string.
index = buff.indexOf("\r");
buff.remove(0, index + 2);
buff.trim();
if (buff != "OK")
{
index = buff.indexOf(":");
String cmd = buff.substring(0, index);
cmd.trim();
buff.remove(0, index + 2);
// Parse the required message from the serial buffer string
mySerialL
if (cmd == "+CMT")
{
// get the newly arrived memory location and store it in temp
index = buff.lastIndexOf(0x0D);// Buscando posición de CR (retorno)
msg = buff.substring(index + 2, buff.length());// Write the message in the variable "msg"
msg.toLowerCase();//The entire message is changed to lowercase
Serial.println(msg);
index = buff.indexOf(0x22);// Looking for the position of the first double quotes-> "
PHONE = buff.substring(index + 1, index + 14); // Write the phone number in the variable "PHONE"
Serial.println(PHONE);
}
}
}
void doAction()
{
if (msg == "led on")
{
digitalWrite(LED_PIN, HIGH);
Reply("LED is ON");
Serial.println("Did the led turn on?");
}
else if (msg == "led off")
{
digitalWrite(LED_PIN, LOW);
Reply("LED is OFF");
Serial.println("Did the led turn off?");
}
PHONE = "";// Delete the string from the phone
msg = "";// Delete the message string
}
void Reply(String text)
{
mySerial.println("AT+CMGF=1\r");
delay(1000);
mySerial.println("AT+CMGS=\"" + PHONE + "\"\r");
delay(1000);
mySerial.println(text);
delay(100);
mySerial.write(0x1A); // código ascii para ctrl + z, DEC-> 26, HEX-> 0x1A
delay(1000);
Serial.println("SMS Sent Successfully.");
}