Hi, can anybody help me !
I try make solution that send multiple sms and takes command in serial.
Problem is:
first i send sms 1 → number and message text “xxxxxxxxxx#test 1”
Modul send message correctly.
then i send sms 2 “xxxxxxxxxxx#test 2” and serial flush put old commands in data message like “AT+CMGS=” +CMGS: 116 OK xxxxxxxxxxxxxx"
can’t send because number and message text is not correct.
Serial command are not cleared ? Serial.flush() ?
then i send sms 3 “xxxxxxxxxxx#test 3”
Modul send message correctly.
then i send sms 4 “xxxxxxxxxxx#test 4” and serial flush put old commands in data message like “AT+CMGS=” +CMGS: 116 OK xxxxxxxxxxxxxx"
Same problem !
Sorry my English.
Here is my code:
#include <LiquidCrystal.h>
int led = 13;
int onModulePin = 2;
String readString;
String nroString;
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
Serial.begin(115200);
switchModule();
delay(5000);
Serial.println("AT+CMGF=1");
delay(5000);
Serial.flush();
lcd.clear();
lcd.print("Wait serial...");
}
void Send(){
lcd.clear();
lcd.print(readString);
// Serial.println("AT+CMGF=1");
// delay(500);
Serial.print("AT+CMGS=");
Serial.print(34,BYTE);
Serial.print(nroString);
lcd.clear();
lcd.print(nroString);
Serial.println(34,BYTE);
delay(500);
Serial.print(readString);
// lcd.clear();
// lcd.print(readString);
delay(500);
Serial.println(0x1A,BYTE);
delay(500);
// lcd.clear();
// lcd.print("Ready..");
readString = "";
nroString = "";
Serial.flush();
}
void loop(){
while (Serial.available()) {
// lcd.clear();
// lcd.print("Serial....");
delay(10);
if (Serial.available() >0) {
// lcd.clear();
// lcd.print("Serial read..");
char c = Serial.read();
readString += c;
if (c == '#'){
nroString = readString;
}
}
}
if (readString.length() >0 && nroString.endsWith("#")) {
nroString = nroString.replace('#', "");
readString = readString.replace(nroString, "");
readString = readString.replace('#', "");
Send();
}
}