ContextPhone Python interface
ContextPhone now has a Python interface to access the sensor data (aka BlackBoard aka tuplespace). Currently you can just get data from it, but in the future you will be able to put data and requests on it as well.
To test the Python interface, get the latest build from latest/s60v2/ (you will probably want the log-only-X.SIS where X is the latest available date, at the moment log-only-20060630T125936.SIS). After that you can just import contextphone in your Python script.
Please note that the exact data representation might still change...
Example usage 1:
>>> import contextphone import contextphone >>> bbs=contextphone.bbsession() bbs=contextphone.bbsession() >>> id=bbs.get(contextphone.CELLID) id=bbs.get(contextphone.CELLID) >>> print id print id {u'priority': 2L, u'eventname': u'location.value', u'eventdata': {u'!value': {u'location.network': u'RADIOLINJA', u'location.lac': 9006L, u'location.cellid': 18L, u'location.id': 3L, u'location.mnc': 5 L, u'location.mcc': 244L}, '!bbtype': (270565662, 1, 1, 0)}, u'datetime': u'20030126T144540'}
Some explanation:
- To access the data in the blackboard, you first get a reference to a BlackBoard session by calling contextphone.bbsession (this is a singleton)
- Retrieving current data from the blackboard is done by calling get()
- All data in the blackboard is identified by a tuplename: a tuple of two integers (first a Symbian UID, second an ID within that component). These tuples are available as constants in the contextphone module. Do dir(contextphone) to see them.
- All data is encoded in Python dictionaries, lists and primitive types. The sensor data always comes in a sensor event with a priority, eventname, eventdata and datetime (in UTC).
Example usage 2:
import contextphone bbs=contextphone.bbsession() def cb(tn, sn, d) : print 'tn', tn print 'sn', sn print 'd', d ss=bbs.subsession(cb) ss.addnotification(contextphone.ANYSENSOR)
Some explanation:
- To get a callback when data changes, you create a sub session on the blackboard session, giving it a function to call
- The function will get three arguments: the tuplename, a subname (don't worry about that for now) and the data for that tuple
- The callback will be in effect until the subsession is released
- The ANYSENSOR is a special tuplename which means all sensor data
- The callback is always called from an active object RunL, so
Available data:
(incomplete due to lack of time)
- cell id
- cell name (user given, or from network service)
- city name (user given)
- country name (automatic)
- bluetooth neighbourhood (from periodic scan)
- own bluetooth address
- GPS (from periodic reading, if device set up)
- current calendar events
- unread message count / unanswered call count
- currently active application
- user idle or active
- charger status
- battery status
- network coverage
Links
Up to: Context project main page |Department of Computer Science | HIIT Basic Research Unit