Hi everyone,
my project is to send a SMS to the SIM800L module which is connected with an Arduino Nano. The Nano should compare the SMS to a saved phone number and if the SMS is from the number it should switch on an LED.
I have achieved, that i can see the SMS in the Serial Monitor, when in the void loop only is updateSerial.
Can someone pls help me, because i don´t get it, where my mistake is.
#include <SoftwareSerial.h>
#include <String.h>
#define PIN_TX 8
#define PIN_RX 9
SoftwareSerial mySerial(PIN_RX, PIN_TX);
int LED = 5; //Set Led to Pin 5
char num_1 = "+491525342xxx"; //String with first mobilenumber
String textSms; //String to store text
void setup()
{
pinMode (LED, OUTPUT); //Set Pin 5 as Output
digitalWrite (LED, LOW);
Serial.begin(38400); //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
mySerial.begin(38400); //Begin serial communication with Arduino and SIM800L
delay (1000);
Serial.println("Initializing...");
// Once the handshake test is successful, it will back to OK
mySerial.println("AT");
delay (1000);
updateSerial();
// Configuring TEXT mode
mySerial.println("AT+CMGF=1");
delay (1000);
updateSerial();
// Decides how newly arrived SMS messages should be handled
mySerial.println("AT+CNMI=1,2,0,0,0");
updateSerial();
}
void loop()
{
updateSerial();
textSms = Serial.readString(); //this will save the whole data to the String variable d..
if(strcmp(textSms.indexOf("+4915253426039"), num_1) >= 0) // checking whether the msg(that is saved in d) has got "num_1" in it
{
digitalWrite(LED, HIGH); // turning on led
}
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}