AT+CUSD command question

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

Moderator: Benj

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

AT+CUSD command question

Post by hakkari »

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
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: AT+CUSD command question

Post by EtsDriver »

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. :/
Ill just keep the good work up!

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

Re: AT+CUSD command question

Post by hakkari »

thanks

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

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

Re: AT+CUSD command question

Post by Benj »

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 346 times

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

Re: AT+CUSD command question

Post by hakkari »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: AT+CUSD command question

Post by Benj »

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

Post by hakkari »

thanks i will try

Post Reply