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– Jot2018年11月30日 08:57:22 +00:00Commented 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#" .Marko Šinkovc– Marko Šinkovc2018年11月30日 09:03:58 +00:00Commented 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/escapeJot– Jot2018年11月30日 09:08:06 +00:00Commented 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.Marko Šinkovc– Marko Šinkovc2018年11月30日 09:08:51 +00:00Commented 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.Marko Šinkovc– Marko Šinkovc2018年11月30日 09:22:51 +00:00Commented Nov 30, 2018 at 9:22
1 Answer 1
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– Marko Šinkovc2018年11月30日 10:15:46 +00:00Commented Nov 30, 2018 at 10:15
-
.....or the provider does not recognise this parameter \"*123#\ ?Marko Šinkovc– Marko Šinkovc2018年11月30日 10:19:22 +00:00Commented 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– PimV2018年11月30日 11:10:24 +00:00Commented 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– Jot2018年11月30日 13:32:26 +00:00Commented 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."Marko Šinkovc– Marko Šinkovc2018年11月30日 13:58:42 +00:00Commented Nov 30, 2018 at 13:58