AT+CUSD command question

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

hakkari
Posts: 4
Joined: Thu Mar 08, 2018 9:46 am
Contact:

AT+CUSD command question

Postby hakkari » Thu Mar 08, 2018 9:52 am

hello

how to use AT+CUSD to check balance ???
Last edited by EtsDriver on Mon Mar 12, 2018 7:18 am, edited 1 time in total.
Reason: SPLITTED FROM Send and receive serial data via GSM

EtsDriver
Valued Contributor
Valued Contributor
Posts: 431
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 346 times
Been thanked: 224 times
Contact:

Re: AT+CUSD command question

Postby EtsDriver » Mon Mar 12, 2018 8:08 am

Hi and welcome to forums.
The AT+CUSD will work only if SIM supports it.
Firstly, if you put your SIM card into phone and there is new option in menu that has SIM card logo or similar, this is the menu you want to get to using the AT+CUSD commands. If the menu is not availabe, AT+CUSD is most likely not then the option.

Some SIM providers dont provide it and you must then use regular SMS to get the balance. (Like in here, most operators accept messages like "SALDO" "TOTAL" "BAL" "BALANCE" and send you back a SMS containing the balance information).

To check balance with AT+CUSD you must first send enable USSD AT command to modem using SendCommand.

Code: Select all

AT+CUSD=1

This will enable your USSD services/features on the SIM card.

If you receive message "OK" from modem, you may now get the menu options. Replace the CODE with your operators USSD code for the SIM card.

Code: Select all

AT+CUSD=1,"<CODE>"


You get response like:

Code: Select all

+CUSD: 1, "1. Load more balance.2.Check balance.3.Customer service number.",64



After that you select your correct menu option;

Code: Select all

AT+CUSD=1,"<OPTION>"


And return should contain the message what provides balance.

Code: Select all

+CUSD: 1, "Your balance on <today> is 0 EUR. In this month, you have used calls 750 minutes, sent 1.2Million text messages, driven to moon and back with your car and got old milk carton in your fridge.",64


PS.
You may try what kind code your device accepts. In the old days, the Service Provider gave a list of these provided with the SIM card (the little book that people throw away). Some providers provide list on their website on the codes (mobile menu code).

And here in Finland, Telia provides the little booklet as pdf, and it seems to no more have the codes as the USSD:s are dying out on the cards. Only using text message you can get your balance it seems. :/
These users thanked the author EtsDriver for the post (total 3):
medelec35 (Mon Mar 12, 2018 9:05 am) • kersing (Mon Mar 12, 2018 9:34 pm) • Benj (Wed Jun 20, 2018 12:19 pm)
Rating: 15%
 
Ill just keep the good work up!

hakkari
Posts: 4
Joined: Thu Mar 08, 2018 9:46 am
Contact:

Re: AT+CUSD command question

Postby hakkari » Wed Jun 20, 2018 8:42 am

thanks

but i want to know how extract the balance from the string i received ?? in flowcode

User avatar
Benj
Matrix Staff
Posts: 14670
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4655 times
Been thanked: 4276 times
Contact:

Re: AT+CUSD command question

Postby Benj » Wed Jun 20, 2018 12:31 pm

Can you give us an example of the string you receive and we should be able to help you parse the numeric balance from that.

Probably something like parse through until you get a character in the range of '0' to '9' and then from there using a standard string to float type conversion routine.

Here's a simple example to collect a numeric value contained in a string into a sub string. You can then call the String to Float function if you need the value as a numeric variable.
GetBalance.fcfx
(6.19 KiB) Downloaded 97 times

hakkari
Posts: 4
Joined: Thu Mar 08, 2018 9:46 am
Contact:

Re: AT+CUSD command question

Postby hakkari » Fri Jun 22, 2018 8:09 am

i want to check balance by sensing message to gsm and the gsm send to my phone number the account balance

we use "AT+CUSD=1,\"*211#\""

but when i use receive string eblocks the string show me OK only

but in really it contain +CUSD "your balance is 209IQD .... " after one line

how can i extract that line contain +CUSD .... ??

User avatar
Benj
Matrix Staff
Posts: 14670
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4655 times
Been thanked: 4276 times
Contact:

Re: AT+CUSD command question

Postby Benj » Fri Jun 22, 2018 5:35 pm

Hello,

ReceiveString will read up to a new line character, maybe call the function a second time to collect the next part of the reply.

hakkari
Posts: 4
Joined: Thu Mar 08, 2018 9:46 am
Contact:

Re: AT+CUSD command question

Postby hakkari » Sat Jun 23, 2018 8:41 am

thanks i will try