1

I am making an Arduino program with SIM800L module and would like to check credit status of the SIM card. When I manually enter the command: AT+CUSD=1,"*123#" into Serial Monitor, it works fine.

But in the Arduino (1.8.7) I am receiving an error stray "#" in program

when compiling this line of sketch: SIM800.print("AT+CUSD=1,"*123#"\r");

I am not experienced enough to fix this problem. Could somebody help me, please?

Thank you. Marko

5
  • I think something else is stray. Why are there three double quotes in "*123#"\r". A backslash is a normal part of a string, why did you put it outside the string?
    – Jot
    Commented Nov 30, 2018 at 8:57
  • There are four quotes in the command ("AT+CUSD=1,"*123#"\r"). When I manually enter this command into Serial Monitor, I type AT+CUSD=1,"*123#" . Commented Nov 30, 2018 at 9:03
  • Sorry, there are four indeed. A double quote " in a string closes the string. You need the escape backslash and use \" in the same way as the escape is used for \r. en.cppreference.com/w/cpp/language/escape
    – Jot
    Commented Nov 30, 2018 at 9:08
  • I understand that *123# is a string for provider to perform this function (return a info of my SIM credit). When I make a phone call from my mobitel, I just enter *123# and receive an answer with this info. Commented Nov 30, 2018 at 9:08
  • It is interesting that a similar command: SIM800.print("ATD*123#\r"); works fine ( return OK) and without any compiler comment. Commented Nov 30, 2018 at 9:22

1 Answer 1

3

Use the escape backslash to get a double quote in a text. See: https://en.cppreference.com/w/cpp/language/escape

Is the *123$ between double quotes?

Serial.println("Hello");
Serial.println("I said: Hello to you");
Serial.println("I said: \"Hello\" to you");
Serial.println("AT+CUSD=1,\"*123#\"\r");
Serial.println("AT+CUSD=1,\"*123#\"");

I think the carriage return \r at the end is not needed when the println is used. The println adds a linefeed \n by the way.

6
  • The last suggested command SIM800.println("AT+CUSD=1,\"*123#\""); is accepted by compiler but returns only "OK" - the same answer as basic command SIM800.println("AT+CUSD=1"); . It looks like as the parameter \"*123#\ is not forwarded to SIM800? Commented Nov 30, 2018 at 10:15
  • .....or the provider does not recognise this parameter \"*123#\ ? Commented Nov 30, 2018 at 10:19
  • You could try to send the ASCII code of these characters with Serial.write(). In that way you don't have to bother about escaping and the compiler doesn't see the # anymore.
    – PimV
    Commented Nov 30, 2018 at 11:10
  • The command \"*123#\" is translated by the compiler into "*123#" including the two double quotes. I don't know if that is recognized, I see examples that have a comma and a number after it.
    – Jot
    Commented Nov 30, 2018 at 13:32
  • Thank you all for the good will and your efforts to help me. Jot, can you please clarify what is meant by "... have a comma and a number after it." Commented Nov 30, 2018 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.