2

I am using SIM900 with arduino mega and have to send a message to a specific number I store in a variable, using AT commands. I am storing the number as a String but it gives an error. Below are the relevant lines of code:

String number1 = "923360234233";
Serial1.write("AT+CMGS=\"" + number1 + "\"");

It gives the following error.

no matching function for call to 'HardwareSerial::write(StringSumHelper&)'

What am I doing wrong here?

13.SS
  • 37
  • 8

1 Answers1

3

Method write can be used only for C-strings char *, uint8_t * and similar buffers.

However if you've used string addition: const char * + String + const char * you'll get StringSumHelper which is not supported by write.

So you can use:

Serial1.print("AT+CMGS=\"" + number1 + "\"");

or

Serial.write(("AT+CMGS=\"" + number1 + "\"").c_str());

or

Serial1.write("AT+CMGS=\"");
Serial.print(number1);
Serial.write("\"");
KIIV
  • 3,534
  • 2
  • 18
  • 23
  • But it still does not work. I am unable to receive text on my phone. – 13.SS Sep 15 '16 at 13:48
  • Well, you asked why that part of code can't be compiled and that's solved. And attached code is incomplete. So how should I know why it's not sending anything. At least take a look [here](https://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/at-cmgs-text-mode/). – KIIV Sep 15 '16 at 14:04
  • Right! My apologies. If I upload the code, will you be able to figure out what's wrong? – 13.SS Sep 15 '16 at 14:24
  • Well, new question would be better. – KIIV Sep 15 '16 at 14:30
  • Worked for SIM808. – opu 웃 Aug 02 '18 at 03:58