maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   General (https://talk.maemo.org/forumdisplay.php?f=7)
-   -   Mini how-to: displaying current prepaid balance on desktop (e-plus, germany) (https://talk.maemo.org/showthread.php?t=46322)

x-lette 2010-03-02 19:20

Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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. :o

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 :rolleyes:

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 :rolleyes:. 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. :D

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! :)

Andre Klapper 2010-03-02 20:19

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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)...

x-lette 2010-03-02 23:02

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by Andre Klapper (Post 552923)
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?
Quote:

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.

jabagaba 2010-03-04 19:13

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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 :(

x-lette 2010-03-04 19:22

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by jabagaba (Post 555952)
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.

Quote:

- 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.

KiberGus 2010-03-05 21:41

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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.
Quote:

Originally Posted by Andre Klapper (Post 552923)
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.

x-lette 2010-03-05 22:11

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by KiberGus (Post 557325)
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.

KiberGus 2010-03-06 06:33

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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).

x-lette 2010-03-06 11:37

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by KiberGus (Post 557576)
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.

x-lette 2010-03-07 15:19

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
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.

x-lette 2010-03-07 15:47

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Here is an example of a SMS which also includes usage and remaining traffic of the data plan. Carrier is sunrise in switzerland, the currency is CHF which cannot be converted to a nice symbol. (I guess no one yet found out how to make a symbol for chocolate :D)

Code:

Ihre aufgelaufenen Kosten ohne Abogebühr: CHF 1.20. Limite: CHF 5,000. Stand: 27.02.2010 11:49.Verbleibende Inklusiv-Leistungen:122.19 MB (surf) gültig bis 06.03.2010.
Angaben ohne Gewähr. Details unter www.sunrise.ch/costcontrol

The output shall look like

Code:

CHF 1.20 - 122.19 MB
Here we go: USSD-Widget has to setup to using code "*133#" which is the one used by this carrier. One instance of DCE has to get installed the same way as described in post #1, using the following code:

Code:

sqlite3 -separator ": " /home/user/.rtcom-eventlogger/el.db \
 "SELECT free_text FROM Events WHERE event_type_id = '7' AND free_text LIKE 'Ihre aufgelaufenen Kosten%' ORDER BY end_time DESC LIMIT 1"\
 | sed s/Ihr.*hr:.// | sed s/..Limite.*ungen:/' - '/ | sed s/..surf.*$//


moerderameise 2010-03-07 16:25

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
First of all i have to say thank you for editing the script to fit with sunrise ;)
I tried it out and have a problem. When i test the script in xterm it seems to work, even when i think the displayed infos aren't right right now, but when i try to put the script in a widget it only showes "invalid command"
I wrote the chmod line as root in xterm and into the dce i wrote /home/user/Guthaben.sh (where the file is)

what can be wrong?
When i tipe in xterm as user the file can't be opened, as root it works. is that wright?

x-lette 2010-03-07 16:36

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by moerderameise (Post 558829)
First of all i have to say thank you for editing the script to fit with sunrise ;)
I tried it out and have a problem. When i test the script in xterm it seems to work, even when i think the displayed infos aren't right right now, but when i try to put the script in a widget it only showes "invalid command"
I wrote the chmod line as root in xterm and into the dce i wrote /home/user/Guthaben.sh (where the file is)

what can be wrong?
When i tipe in xterm as user the file can't be opened, as root it works. is that wright?

Did you follow the steps in first posting? I just described the changes you have to make to USSD-Widget and inside the script I called Guthaben.sh. Don't create this skript as root but as user, i.e. open an xterm and right begin to edit the file, don't 'root up'. If the file is already owned by root you can re-own it to user by typing (as root):

chown user Guthaben.sh

Doing an "ls -l" will show you exactly the owner of the file.

Inside DCE you just call the script, not the sqlite command or the sed commands!

moerderameise 2010-03-07 17:03

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
ok ok now it works ;)

but it is displayed like this:

CHF 0.00249.88 MB

so there is no "-" between the different things. how to fix it?

and another question:

now i click on the ussd widget to get the sms, then the sms arrives and the dce shows the actual costs. but the sms is still unread and so the led blinks until i read the sms. is it also possible to mark the sms as read through the script? and the incomming message desktop widget shows also the unread sms. is there also a way to fix this?
and last: is it possible to execute the script once a day automaticly? so that i have not to click onto the ussd widget? would save me space on the desktop ;)

x-lette 2010-03-07 17:20

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by moerderameise (Post 558865)
ok ok now it works ;)

but it is displayed like this:

CHF 0.00249.88 MB

so there is no "-" between the different things. how to fix it?

Ooops, my failure, didn't insert the spaces and the dash. :o Will fix it in the original post.

Quote:

and another question:
You're welcome ;)

Quote:

now i click on the ussd widget to get the sms, then the sms arrives and the dce shows the actual costs. but the sms is still unread and so the led blinks until i read the sms. is it also possible to mark the sms as read through the script? and the incomming message desktop widget shows also the unread sms. is there also a way to fix this?
In fact, I don't know. I guess there are several points where an SMS might be marked as read/unread. But even if there is only one single field in the database it would need a writing access to this database which is what I want to avoid. Until now all accesses to the database are read-only and therefore cannot be harmful in any way to the system. Implementing a read/write-access would lead to many checkings and I would have to take care about consitency all over the device. That's pretty way out of goal. Therefore: no, I won't implement a check-as-read-feature. :rolleyes:

Quote:

and last: is it possible to execute the script once a day automaticly? so that i have not to click onto the ussd widget? would save me space on the desktop ;)
There are several tools which offer you a kind of cron-like behaviour, i.e. executing a command at a defined interval. But as far as I know they all are not really stable and still reside in -devel. If you dare installing them you might set up a daily execution of a USSD command line.

But if you just want to save space, you also might shorten the title of the widget. A single character doesn't take much space on desktop ;)

moerderameise 2010-03-07 17:42

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Hmm ok then lets forget my questions ;)

but to your point to make the ussd widget smaller: i did what you wrote in first post but it didn't change anythin... still the fat text "Vielen Dank für Ihre Anfrage blablabla...."

x-lette 2010-03-07 17:55

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Which version of USSD-Widget do you use? Might be it was implemented in a version which still is only in -devel. In current version there is a a field called "Parser for widget" which will rewrite the output.

Here are my current settings for USSD-Widget:
USSD number: *100#
Execute query on start: no
Name: Guthaben abfragen
Parser for widget: echo "Guthaben abfragen"
Enable banner: yes
Parser: echo "%"
Chain: <empty>
Regular expression: <empty>
Update every 0 minutes
Retry pattern: 10-30-300

Most of these settings are well documented via the question sign beneath them.

Forgot to mention: the point where you can shorten the output for space saving is to replace both strings "Guthaben abfragen" by something you like.

And if you don't want to see the answer at all you might also want to disable banner, which puts the answer as a temporary banner over your desktop, just like any incoming message.

moerderameise 2010-03-07 18:09

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
ok now it worked. had to restart the widget and than changes took effekt.
thank you very much ;) looks good.

KiberGus 2010-03-13 11:42

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
New version has support for taking reply from SMS. Please test, if it works. Some instructions are available here:
http://kibergus.su/node/19

moerderameise 2010-03-15 08:56

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by KiberGus (Post 565961)
New version has support for taking reply from SMS. Please test, if it works. Some instructions are available here:
http://kibergus.su/node/19

Don't know how to set up... Will look at it today or tomorrow maybe i get it worked. If i understand you right, it showes the costs just like the script, so it would not longer be necessary?

KiberGus 2010-03-15 10:17

Re: Mini how-to: displaying current prepaid balance on desktop (e-plus, germany)
 
Quote:

Originally Posted by moerderameise (Post 567511)
Don't know how to set up... Will look at it today or tomorrow maybe i get it worked. If i understand you right, it showes the costs just like the script, so it would not longer be necessary?

Yes. No script needed. You have to click only once to get information, which would be displayed on the widget.
But reply filtration is done in another way. So you would have to figure out what regular expression you need if you want show only necessary information from the SMS.


All times are GMT. The time now is 07:07.

vBulletin® Version 3.8.8