Active Topics

 


Reply
Thread Tools
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#1
First of all I should mention that I don't have a clue where to post this how-to. So I put it to General. If it's not the right place, please move it.

OK, in germany there is a provider called e-plus who changed the way of telling the current balance in last summer. Actually, when querying *100# (thanks god for ussd-widget!!) the user gets a message saying, that the balance will be sent by SMS within the next moments. The SMS arrives, but ussd-widget of course still shows the intermediate message. This was very annoying for me so I figured out a way to get the balance right on the desktop.

All you need is the packages ussd-widget and desktop-command-execution. Please keep in mind that installing 3rd-party software and executing this how-to might kill a randomly selected kitten somewhere in the suburbs. But probably not

Step 1: install and configure one instance of ussd-widget. At least you need to fill in the field for the ussd code; it must contain '*100#' (without the quotes). Make sure it works and you receive the SMS containing the balance. There must be at least one of these SMSs stored on your phone to get this how-to to work.

Step 2: install desktop-command-execution. There is no need to put one of the pre-defined commands on your desktop if you don't want to.

Step 3: create a file in your home folder (should not be placed in MyDocs as this is a sometimes-unmounted-FAT-filesystem and I just don't know if a script can get executed from there reliable) copy the following code to it and make it executable.

Step-by-step:

Assumed the file is called /home/user/Guthaben.sh type the following into the terminal (as user, not root):
Code:
cat > /home/user/Guthaben.sh
then copy this text and paste it in (or type it in)
Code:
#!/bin/sh
# simple query to the RTCOM database:
# - selects the last incoming SMS beginning with the string "Ihr Guthaben"
# - formats the output to only display date and account balance in €

sqlite3 -separator ": " /home/user/.rtcom-eventlogger/el.db \
 "SELECT strftime('%d.%m.%Y',storage_time,'unixepoch','localtime'), free_text FROM Events WHERE event_type_id = '7' AND free_text LIKE 'Ihr Guthaben%' ORDER BY end_time DESC LIMIT 1"\
 | sed s/Ihr.*gt\ // | sed s/.EUR./€/
Now press <ctrl>-<d> to close the file.

Instead of the described command you might use any other editor or whatever-tool-you-like, as long as it is able to write a standard textfile.

Now make the script executable (again: in terminal):
Code:
chmod u+x /home/user/Guthaben.sh
Test the script by typing
Code:
/home/user/Guthaben.sh <enter>
You should now see a line with the date and the balance of the last query. If not, something went wrong.

Last step: put one instance of desktop-command-execution on your desktop and go to the settings. Push "add cmd" and enter the path and filename to your script (i.e.: /home/user/Guthaben.sh) into the field "Command:". In the field "Title:" you may put whatever you like, I used 'Guthaben'. You just have to remember it . Save the settings. The just added command should now be selected. If not, open the command list and select it (now you need to remember the name you gave it). Adjust the other options to your needs and save the widget.

If nothing went bad, you should see your actual balance on desktop.

For convenience I modified the output of ussd-widget, as the complete answer from e-plus is too ugly to have it on desktop all day. Now the answer is displayed in a short note and the widget just changes it's name. This is what I did (just the names of the fields I changed and their value):

Name: Guthaben
Parser for widget: echo "Kto abgefragt"
Enable banner: yes
Parser: echo "%"
Font: Nokia Sans Cn Regular 16


Have fun!
 

The Following 5 Users Say Thank You to x-lette For This Useful Post:
Andre Klapper's Avatar
Posts: 1,665 | Thanked: 1,649 times | Joined on Jun 2008 @ Praha, Czech Republic
#2
I think the remaining balance will be displayed in the next public Maemo5 update after you have called somebody in case the mobile provider sends out a short message about the remaining money after a call.
At least it works here so far (but I use Vodafone CZ and run a non-public version)...
__________________
maemo.org Bugmaster
 

The Following User Says Thank You to Andre Klapper For This Useful Post:
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#3
Originally Posted by Andre Klapper View Post
I think the remaining balance will be displayed in the next public Maemo5 update after you have called somebody in case the mobile provider sends out a short message about the remaining money after a call.
Don't know if I understand right: you talk about getting a sms containing the actual balance after making a call automatically? sounds nice, saves one step in this guide. but what about the display in the next update?
At least it works here so far (but I use Vodafone CZ and run a non-public version)...
you mean this guide or the update on maemo?
would be nice to hear wether this also works for other providers or even in other countries. didn't think about it til now.
 
Posts: 2 | Thanked: 1 time | Joined on Mar 2010 @ Dhahran, Saudi Arabia
#4
I wonder how Nokia forgot to add this!
- Where I live, after I make a call I get a sms showing the last call charge and remaining balance left, and this phone doesn't seem to do that.
- I also would like to know how I can send a USSD sms.

I could not understand the techie stuff you said in the above posts. Sorry
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#5
Originally Posted by jabagaba View Post
I wonder how Nokia forgot to add this!
- Where I live, after I make a call I get a sms showing the last call charge and remaining balance left, and this phone doesn't seem to do that.
Given, your provider sends a regular SMS you should receive this one even with the N900. This device is capable of receiving and displaying SMS.

What I was talking about is another constellation: my provider doesn't send me a SMS after each call I make, I have to query it by sending a special USSD code. Formerly the answer -- containing the actual balance -- was send as reply to this code but it was changed to the described behaviour.

- I also would like to know how I can send a USSD sms.
USSD are special codes, not to compare with a regular SMS. You can send these codes and watch the resulting answer using the application USSD-Widget. This is just a kind of workaround until Nokia implements USSD support to the firmware.
 
Posts: 254 | Thanked: 122 times | Joined on Nov 2009
#6
I think, that this task can be done in a better way. You can use ussd-widget's parser option to start some script after the query was made. In that script you can wait for SMS and show balance on widget itself. The only issue is that parser invocation is sinchronous and would cause hildon-home to freese unil it runs. But, if you are intereted in this scenario, I can make is asinchronous.
Originally Posted by Andre Klapper View Post
I think the remaining balance will be displayed in the next public Maemo5 update after you have called somebody in case the mobile provider sends out a short message about the remaining money after a call.
At least it works here so far (but I use Vodafone CZ and run a non-public version)...
What do you mean under short messages? This is very interesting news.
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#7
Originally Posted by KiberGus View Post
You can use ussd-widget's parser option to start some script after the query was made. In that script you can wait for SMS and show balance on widget itself. The only issue is that parser invocation is sinchronous and would cause hildon-home to freese unil it runs.
I was also thinking about implementing it all in USSD-Widget but I decided for a 2-tool version because this way you can tap on the DCE-Widget to display the latest balance and don't have to always request for the current balance. As I don't do calls often and rarely send SMS I'm quite satisfied with querying the balance once or twice a week. But for convenience I'd like to have the balance displayed on my desktop.
 
Posts: 254 | Thanked: 122 times | Joined on Nov 2009
#8
If your operator don't charge you for requesting your balance, why should you bother send or not to send one more query. While implementing widgetI've sent more than 1000 queries. And main advantage is that you don't need to click twice. You even don't need to click at all if you set automatic update functionality (but then you wouldneed to find a way to make a phone to be silent and not to wibrate, whan you expect SMS from operator).
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#9
Originally Posted by KiberGus View Post
If your operator don't charge you for requesting your balance, why should you bother send or not to send one more query.
Just for one reason: it's not necessary.

Why should I ask for my balance every day when I know, my last fee requiring action was some days ago and there is no difference to display?

The reason for having it always displayed on screen is an obvious one: If the balance is near zero I get reminded to spend some money again. I don't like automatic charging or charge by time interval. If I would want this I wouldn't use prepaid.
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#10
As there just has been the question of how to adapt this script to his own needs, I'll try to explain by example how the extraction of the neccessary information works.

First of all: it all depends on the structure of the SMS you receive with the account balance or data plan balance (you lucky guys, I have no chance to get the data plan usage by SMS).

As an example, this is the SMS I receive when calling *100#:
Code:
Ihr Guthaben für <HEREISMYPHONENUMBER> berträgt <XX,YY> EUR.
Now let's dissect the skript from post #1. We can divide it into three separate commands which are linked together by using the pipe command '|'. First command is the sqlite SELECT-Statement.

We are using the database from RTCOM eventlogger, where the SMS are stored:
Code:
sqlite3 -separator ": " /home/user/.rtcom-eventlogger/el.db
Then we define to read only the fields containing date (storage_time) and content of SMS (free_text). The transformation of the timestamp is needed because the time is stored in unixepoch, which means in seconds since 1.1.1970. This is the first point one might change. In my script the date is displayed as DD.MM.YYY which is a typical german notation. Others might want to change this to the format MM.DD.YYYY (%m.%d.%Y) or even to the ISO conforming YYY-MM-DD (%Y-%m-%d). And users who frequently check their balance might want to add the time: HH:MM would be an additional %h:%s. I guess the 'localtime' statement is needed for most users, as the time is stored in UTC and not being automatically converted to local timezone.
Code:
SELECT strftime('%d.%m.%Y',storage_time,'unixepoch','localtime'), free_text
Next we select to only look at incoming SMS (type 7) and within these only the ones containing the string "Ihr Guthaben" in the beginning of the text (compare with the example SMS above!). This might lead to false results if someone sends me a SMS beginning with the same words. But thats very unlikely to happen. I could also try to match the whole SMS but this could be tricky regarding the german umlauts. One solution would be to also match the end of the SMS, which in my case ends with "EUR.": "Ihr Guthaben%EUR.". Finally the ORDER BY and LIMIT statements just order all these matching SMS by date, newst first and only pick the first of the list, which by definition is the newest one.
Code:
FROM Events WHERE event_type_id = '7' AND free_text LIKE 'Ihr Guthaben%' ORDER BY end_time DESC LIMIT 1"
Now the first sed statement. It just strips everything from the beginning of the SMS until the end of the word "beträgt" which is then followed by the actual balance which we will keep in output.
Code:
sed s/Ihr.*gt\ //
The second statement replaces the letter-coded currency EUR and the trailing dot by the symbol €.
Code:
sed s/.EUR./€/
That's it!

The output in this example looks as follows:

Code:
04.03.2010: 17.21€
Next will be an example which also incudes the data plan usage.

Last edited by x-lette; 2010-03-07 at 15:52. Reason: added example output
 

The Following User Says Thank You to x-lette For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 01:24.