I am trying to build a system with an Arduino Mega and a SIM900 development board. The idea is to send a text message to the system which then responds with a text message to the sender. I can detect and decode the incoming message but when i construct the AT command for the respond I fail. If I hardcode the command it works fine but the constructed code wont work even if it looks the same.
I have tried and tested different solution for over a week now but am probably barking up the wrong tree.
void sendSMS()
{
int i, k;
char cmd[26];
char cmd1[] = {'"', 'A', 'T', '+', 'C', 'M', 'G', 'S', '=', 92, '"'}; //Start of SMS string
char cmd3[] = {92, '"', '"'}; //End of SMS string
for (i = 0; i < sizeof(cmd1); i++)
{
cmd[i] = cmd1[i];
}
k = i;
for (i = 1; i < sizeof(phone)-1; i++) //Phone,exclude '\0'
{
cmd[k] = phone[i];
k++;
}
for (i = 0; i < sizeof(cmd3); i++)
{
cmd[k] = cmd3[i];
k++;
}
cmd[k]='\0';
Serial.print("cmd: "); //Debug
Serial.println(cmd); //Debug
Serial3.print("AT+CMGF=1\r");
delay(100);
//Serial3.println("AT+CMGS=\"+46705957262\""); // THIS WORKS
Serial3.println(String(cmd)); // THIS DOES NOT WORK,
Serial.println(String(cmd)); //Serial monitor shows "AT+CMGS=\"+46705957262\""
delay(50);
Serial3.print("Sugga i Suntak!");
delay(100);
Serial3.println((char)26);
}
It is probably something quite basic I miss but I just can't put my finger on it.