So heres the Scenario, im trying to interface my "Form" made from Visual Studio C# to an Arduino Uno which is connected to a TC35 GSM Module. The GSM module should send a notification (in the from of a message to the Arduino) whenever and whatever key i press in the Forms textbox. it will then send a TEXT if it sees the "!" character in the notification which was received by the arduino containing the message itself . I will follow a general format for the message in order to efficiently allocate the 160 chars in a text. Now, the first message sent follows the format and is non repeating, but since the notification will be sent WHEN i press a button, it should always send the SAME exact message everytime which is not the case.
Heres the code:
#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(2,3); // Intialize use of pins 2 and 3 for TX and RX
byte check;
char letter[159];
char cle[159]; // for clearing
int x =0;
void setup()
{
Serial.begin(9600);
gsmSerial.begin(9600); //9600 Baud Rate
delay(5000);
}
void loop() {
SendNotify();
}
void SendNotify(){
if (Serial.available()) {
check = Serial.read();
if(check==33){
gsmSerial.print("AT+CMGF=1\r"); //SEND SMS
delay(100);
gsmSerial.println("AT+CMGS=\"+63xxxxxxxxx\""); //Phone Number
delay(100);
gsmSerial.print(letter);
delay(100);
gsmSerial.println((char)26);
int x =0;
gsmSerial.flush();
//Serial.print(letter);
}
if (x <=159){
letter [x] = check;
x++;
}
}
}
Heres an Example message generated from the code above:
1st message: Hello you are over speeding
2nd message: !Hello you are over speeding !Hello you are over speeding !Hello you are over speeding
same goes for the 3rd message.
I believe its because of not clearing the char array "letter" so i made another char array of the same size "cle" and used strcpy to clear "letter" like so:
gsmSerial.print("AT+CMGF=1\r"); //SEND SMS
delay(100);
gsmSerial.println("AT+CMGS=\"+63xxxxxxxxx\""); //Phone Number
delay(100);
gsmSerial.print(letter);
delay(100);
gsmSerial.println((char)26);
int x =0;
strcpy(letter,cle); // added this
gsmSerial.flush();
The first message is the same (no problems whatsoever) BUT the message received and anything following that is just a V
Yes, it send a letter "V".
Am I correct with my assumption that the repeating message is because of me not clearing the char array?
if NO then what should I change in my codes / what is the cause of the repetition
if YES then what am I doing wrong? am i using strcpy correctly?