ascoderu / lokole

Source code for the Lokole project. Lokole enables communities in the Congo DRC to pool resources to access efficient communication via email at an affordable price.
https://ascoderu.ca
Apache License 2.0
45 stars 12 forks source link

Add way to check SIM card balance #344

Open c-w opened 5 years ago

c-w commented 5 years ago

From @nzola

(1) It is difficult to know from the Lokole device when the data credit is finished. (2) When one buys data credit for the SIM inside the Lokole, one has to use USSD code on the phone to activate the data. Otherwise it would not work.

This could be done via gammu (code example).

Implementation notes: 1) To the admin page settings.html, add an element that displays the current SIM card balance and a form that enables the admin to submit a SIM card top-up code. 2) To actions.py add two new commands that back the elements in the settings page: one to check SIM card balance and one to top up the SIM card. 3) To views.py, add the glue to connect the admin page with the actions.

Suggested approach:

a) Insert a pay-as-you-go SIM card into a USB modem like Huawei MS2131i-8 and install gammu. b) Manually experiment on the CLI with gammu commands to retrieve the SIM card balance and top up the balance. c) Add code to actions.py that wraps the gammu CLI commands as described in 2) above. The code for StartInternetConnection can be used as a reference of an existing action that calls out to CLI commands. d) Run a Python interpreter and experiment with the actions to ensure that the wrapping code works. e) If the new action takes more than 1 second to run we'll have to run it outside of the http request/response cycle, so wrap it in tasks.py. f) Follow steps 1) and 3) above to wire the action into the Lokole admin page.

c-w commented 4 years ago

Vodacom details from @nzola:

To top up data: *1141*creditamount*phonenumber#yes To check data credit: *100*2#yes or *100*1#yes To check SIM card phone number: *89#yes

@sbathgate I would recommend that the UI is flexible enough that the user can edit any of these strings if their SIM provider requires a different setup.

nzola commented 4 years ago

Orange details: To check data credit: 12412#yes Airtel details: To check data credit: 5653#yes To check SIM card phone number: 502#yes Afritel details: To check data credit and SIM card phone number: 1000#yes

sbathgate commented 4 years ago

As discussed I have run into some difficulties with this issue. I have extracted a series of fault logs attached below. The short form is: An error is reported every time the "gammu getussd" command is sent via the Huawei MS2131i-8. Testing was successful with the Huawei e303 and the corresponding logs are attached in gist links below for comparison. I am unsure if this is strictly an incompatibility with the Huawei MS2131i-8 and Gammu.

Research has, unfortunately, shed little light on this error. After attempting to resolve this with just Gammu, I tried to work around it through the python-gammu package and utilizing Picocom to manually send the appropriate AT+ commands. Both resulted in similar faults. I can extract copies of these faults if that will assist with further troubleshooting.

Ultimately, I believe the fault lies with some form of encoding issue. On line 393 of the Huawei e303 Gammu Log Errors file, you can see the USSD code being successfully sent. It should read "AT+CUSD=1,"AADBEDA68A8D00",15" as seen here. The text in bold represents the "*777*1#" USSD code that my sim card provider uses to retrieve the account balance.

Review of line 372 of the Huawei MS2131i-8 Gammu Log Errors indicates the code sent was "AT+CUSD=1,"002A003700370037002A00310023",15". The mixture of characters in bold represents the USSD code the USB modem attempted to send.

As mentioned above, I have attempted to manually send the correct ("AADBEDA68A8D00") AT+CUSD code by making a serial connection with the USB modem via Picocom which resulted in a similar error to Gammu with the MS2131i-8. I found M2MSupport.net helpful to better understand the AT+ command requirements.

A few other ancillary notes:

Huawei e303:

Huawei MS2131i-8:

nzola commented 3 years ago

@shaun https://github.com/gammu/python-gammu/blob/master/examples/service_numbers.py