0

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

  • 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 Nov 30 '18 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#" . – Marko Šinkovc Nov 30 '18 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 Nov 30 '18 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. – Marko Šinkovc Nov 30 '18 at 9:08
  • It is interesting that a similar command: SIM800.print("ATD*123#\r"); works fine ( return OK) and without any compiler comment. – Marko Šinkovc Nov 30 '18 at 9:22
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.

  • 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? – Marko Šinkovc Nov 30 '18 at 10:15
  • .....or the provider does not recognise this parameter \"*123#\ ? – Marko Šinkovc Nov 30 '18 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 Nov 30 '18 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 Nov 30 '18 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." – Marko Šinkovc Nov 30 '18 at 13:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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