Reply
Thread Tools
Posts: 486 | Thanked: 154 times | Joined on Sep 2009 @ New York City
#1
anyone have some python code which will allow me to pull the currently connected cell ID?

I want to be able to use this value to query an open cell database to get a rough location of the user (for when indoors/gps not working, etc)

thanks.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#2
http://talk.maemo.org/showthread.php?p=386188 showed how to do it in C. I know you requested for Python specifically, but I don't know python-dbus and I think python-osso won't help here, either, as the Cell ID is not the first thing returned...
 

The Following 2 Users Say Thank You to qwerty12 For This Useful Post:
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#3
@hypnotik:

and here you have an example of using DBus in Python (this one is for WLAN scanning):

http://slexy.org/view/s25h3to4Rr
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me
 

The Following 3 Users Say Thank You to hopbeat For This Useful Post:
Posts: 486 | Thanked: 154 times | Joined on Sep 2009 @ New York City
#4
Thanks qwerty12, hopbeat for the examples. I'll give a go.
 
Posts: 486 | Thanked: 154 times | Joined on Sep 2009 @ New York City
#5
Originally Posted by hopbeat View Post
@hypnotik:

and here you have an example of using DBus in Python (this one is for WLAN scanning):

http://slexy.org/view/s25h3to4Rr
Is there a point of reference for dbus for querying the GSM stack to read the Cell Tower ID?
I'm assuming I need to modify com.nokia.wlancond.signal to something else?

EDIT: Ok, this is slowly starting to make sense now...

qwerty12's post here shows the code for reading cellID. I just need to adapt it somehow to python.

http://talk.maemo.org/showpost.php?p=385947&postcount=2

Last edited by hypnotik; 2009-12-14 at 22:27.
 
Posts: 486 | Thanked: 154 times | Joined on Sep 2009 @ New York City
#6
Hmm.. I give up on this. Tried to adapt the code from qwerty12 into hopbeats' but I'm doing something wrong.

Code:
from dbus.glib import *
import gobject
import dbus
import array

loop=None

def scan_results(*args):
    loop.quit()

if __name__ ==  "__main__":

        #mandatory to receive dbus signal
        loop=gobject.MainLoop()
        bus = dbus.SystemBus()
        wlancond = bus.get_object('com.nokia.phone.net', '/com/nokia/phone/net')
        request = dbus.Interface(wlancond, 'Phone.Net')
        bus.add_signal_receiver(scan_results, dbus_interface="Phone.Net.get_registration_status", signal_name="get_registration_status")
        request.get_cell_id(dbus.Int32(4), dbus.ByteArray([]), dbus.Int32(2))
        loop.run()

All I get is:

Code:
ERROR:dbus.proxies:Introspect error on :1.16:/com/nokia/phone/net: dbus.exceptions.DBusException: rpc.Error: object /com/nokia/phone/net doesn't have interface org.freedesktop.DBus.Introspectable
Traceback (most recent call last):
  File "test2.py", line 31, in <module>
    request.get_cell_id(dbus.Int32(4), dbus.ByteArray([]), dbus.Int32(2))
  File "/usr/lib/pymodules/python2.5/dbus/proxies.py", line 68, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/pymodules/python2.5/dbus/proxies.py", line 140, in __call__
    **keywords)
  File "/usr/lib/pymodules/python2.5/dbus/connection.py", line 622, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: rpc.Error: can't find method Phone.Net::get_cell_id
Will have to revisit this later.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#7
I wanted to try, python-dbus, I really did... But you turned out to be a piece of **** that can't do this correctly. So I cheated:

File.c:
Code:
#include <glib.h>
#include <dbus/dbus-glib.h>

#define PHONE_NET_DBUS_NAME  "com.nokia.phone.net"
#define PHONE_NET_DBUS_IFACE "Phone.Net"
#define PHONE_NET_DBUS_PATH  "/com/nokia/phone/net"
#define PHONE_NET_REGISTRATION_METHOD  "get_registration_status"

guint get_cell_id (void)
{
  DBusGConnection *connection;
  DBusGProxy *proxy;
  GError *error = NULL;
  guchar status, network_type, supported_services;
  guint lac, cell_id, operator_code, country_code;
  gint net_err;

  g_type_init();

  connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
  if (!connection)
  {
    g_printerr("Failed to open connection to system bus: %s\n", error->message);
    g_clear_error(&error);
    return 0;
  }
  proxy = dbus_g_proxy_new_for_name(connection, PHONE_NET_DBUS_NAME, PHONE_NET_DBUS_PATH, PHONE_NET_DBUS_IFACE);

  if (!dbus_g_proxy_call(proxy, PHONE_NET_REGISTRATION_METHOD, &error, G_TYPE_INVALID, G_TYPE_UCHAR, &status, G_TYPE_UINT, &lac, G_TYPE_UINT, &cell_id, G_TYPE_UINT, &operator_code, G_TYPE_UINT, &country_code, G_TYPE_UCHAR, &network_type, G_TYPE_UCHAR, &supported_services, G_TYPE_INT, &net_err, G_TYPE_INVALID))
  {
    if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
      g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
    else
      g_printerr("Failed to call method: %s\n", error->message);
    g_clear_error(&error);
    return 0;
  }

  g_object_unref(proxy);
  dbus_g_connection_unref(connection);

  return cell_id;
}
gcc -Wall --shared File.c -o weed.so `pkg-config --cflags --libs glib-2.0 dbus-glib-1

File.py:
Code:
from ctypes import *

weed = CDLL("/sdk/weed.so")
crack = weed.get_cell_id(None)
print "%d" % crack
Which leaves me with the Cell ID number. I know, I know, using ctypes is not a proper solution but python-dbus sucks so bad...
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#8
Not quite what hypnotik wants, but here's a script I'm using to log cell ID changes, hopefully it'll help:

Code:
#!/usr/bin/env python

import sys
import traceback
import gobject
import dbus
import dbus.mainloop.glib

def cell_signal_handler(*args):
    print "%s,%s,%s" % (args[4], args[3], args[2])
    
if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    bus = dbus.SystemBus()
    bus.add_signal_receiver(cell_signal_handler, dbus_interface = "Phone.Net", signal_name = "registration_status_change")
    bus.add_signal_receiver(cell_signal_handler, dbus_interface = "Phone.Net", signal_name = "cell_info_change")

    loop = gobject.MainLoop()
    loop.run()
 

The Following 4 Users Say Thank You to lma For This Useful Post:
ewan's Avatar
Posts: 445 | Thanked: 572 times | Joined on Oct 2009 @ Oxford
#9
Originally Posted by hypnotik View Post
I want to be able to use this value to query an open cell database to get a rough location of the user (for when indoors/gps not working, etc)
I don't know for sure, but I was under the impression that the built-in liblocation would do this for you, rather than it needing to be implemented in each app - is that not the case?
 

The Following 2 Users Say Thank You to ewan For This Useful Post:
Posts: 432 | Thanked: 645 times | Joined on Mar 2009
#10
Originally Posted by ewan View Post
I don't know for sure, but I was under the impression that the built-in liblocation would do this for you, rather than it needing to be implemented in each app - is that not the case?
That's right. Have a look here. Further it is always better in terms of stability of the API to use the high-level APIs if it exists.


Daniel
 

The Following User Says Thank You to danielwilms For This Useful Post:
Reply

Tags
cell id, location, n900, python


 
Forum Jump


All times are GMT. The time now is 23:49.