Hi, I am currently working on an Arduino Mega and a SIM900A Mini v3.8.2
I am really confused on how to send my data which I received from my 2 serial ports if the senders asks me to. My codes can only accepts only 2 specific phone numbers in which I declared and some specific messages. For example if num1 wants to ask a data from a specific serial by sending message "Data1" how can i send the data from serial 1 specifically to him without sending the data to num2?
The syntax for sending an sms is: sms.SendSMS("PHONENUMBER", "TEXT")
Syntax shows that I need to declare the number in order to send the sms but what if num1 wants the data but the declared number was num2? tried using the syntax but got and error
"no matching function for call to 'SMSGSM::SendSMS(String&, String&)'"
Here is my code:
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
char *p, pos, number[20], message[180];
String msg, numString;
String num1 = "+639xxxxxxxxx", num2 = "+639xxxxxxxxx";
String data1, data2;
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
Serial.print("Data Transmitter - GSM");
initializeGSM();
delay(5000);
}
void loop() {
rxdata1();
rxdata2();
sendSMS();
Serial.println("Data 1: ");
Serial.print(data1);
Serial.println("Data 2: ");
Serial.print(data2);
Serial2.flush();
Serial3.flush();
delay(2000);
}
//Sensore Node 1
void rxdata1() {
if (Serial2.available()) {
data1 = Serial2.readStringUntil(13);
}
}
//Sensore Node 2
void rxdata2() {
if (Serial3.available()) {
data2 = Serial3.readStringUntil(13);
}
}
void initializeGSM() {
if (gsm.begin(9600)) {
Serial.print("\nGSM Initialized!");
}
else {}
}
void sendSMS() {
if (pos = sms.IsSMSPresent(SMS_ALL)) {
}
if ((int)pos > 0 && (int)pos <= 20) {
message[0] = '\0';
sms.GetSMS((int)pos, number, message, 180);
msg = String(message);
numString = String(number);
if (numString.compareTo(num1)==0||numString.compareTo(num2)==0) {
if (msg == "Data1") {
//I wish to send the data from serial 1 to the number requesting it
msg = "";
}
if (msg == "Data2") {
//I wish to send the data from serial 2 to the number requesting it
msg = "";
}
if (msg == "DataAll") {
//I wish to send the data from both serials to the number requesting it
msg = "";
}
}
sms.DeleteSMS((int)pos);
Serial.println("Msg Deleted");
}
}
I also attached the library that I am currently using for reference.