Currently we have a functioning Bluetooth set but we can only place calls, and interact with it through the cold touchscreen of our smartphone.
It is time to use the peripherals of the rotary phone to answer calls, dial-numbers, and end-calls.
Ofono exposes the most important methods to the D-Bus. D-Bus is an inter-application messaging system for Linux. D-Bus can be easily accessed and controlled using the Python module 'dbus'. The following snipped shows how to place a call:
number = 123456789
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager')
modems = manager.GetModems()
modem = modems
hide_id = "default"
print("Using modem %s" % modem)
voice_call_manager = dbus.Interface(bus.get_object('org.ofono', modem), 'org.ofono.VoiceCallManager')
More information about the complete Ofono API can be found on its GitHub repository documentation. Specifically the most interesting part is the VoiceCallManager API.
Our phone should be able to place calls, answer them, and hang them up. On top of that, it would be nice if it could replicate all bells and whistles (pun intended) of the rotary-phone. The plain old telephone system (POTS) produces a 440 Hz tone when the receiver is lifted in order to signal that the line is available for use.
Moreover, we want to also exploit additional functionalities thanks to the internet connection of our new phone. We could, for example, use the numbers dialed when the receiver is hooked to trigger features such as spoken weather forecast, spoken mail reading, shutting down the system, or fast dialing; while the numbers dialed when the receiver is lifted will work as they were intended to: by dialing that number on our smartphone and starting the call.
The telephone.py script contained on this project implements the most important of these described functionalities. We will copy this file on our /home/pi/ directory.
Once our script is finished, we can add it as a service that runs on boot for headless operation. We will create the file /etc/systemd/system/telephone.service and copy the following text in it:
Description=Bluetooth Telephone interface
This will force to run our system as soon only if our soundcard has been loaded properly and after ofono service is initiated. Afterwards the service needs to be enabled with:
systemctl enable telephone.service
Our telephone interface script will be now loaded on each reboot.