An ever-expanding telephone system

In the year and a half since I wrote IP04 Progress, I've expanded my simple telephone system into something a little more comprehensive. I had three goals in mind; to provide that "complete accounting" of incoming and outgoing calls that my provider wouldn't supply, to manage the incoming calls so that I would be less bothered by telemarketers and other annoying callers, and to position the IP04 as a part of a much larger home automation project.

I've slowly worked my way towards all that, in fits and starts, and am ready to share some of my progress.

After my initial implementation, I defined a "switchboard" database on my server to store Asterisk call detail records. With that, I wrote a shell script that would run on the server to download call detail records from the IP04 and insert them into this database. A cron schedule runs this script hourly, giving me a queriable database for call accounting reporting. I augmented this with a number of rudimentary web pages that show daily calls and call history, all sourced from this "switchboard" database and the server's webserver.

Next, I added code to the IP04's Asterisk dialplan to notify my server when a call completes, so that the server can download the call detail record immediately. The process consisted of

  1. an IP04 Dialplan change that invokes a local shell script whenever a call terminates
  2. this shell script uses netcat to send a "call complete" message to my server
  3. the server's inetd intercepts this "call complete" message, and launches a script to process it
  4. this server-side script reads the "call complete" message, and runs the previously written download script to download the CDR and update the "switchboard" database

This results in almost-immediate update of the "switchboard" database when a call completes, permitting the various web pages to display near-realtime results.

Now that I had a database, I added a "known caller" table which associated specific caller-IDs with callers known to me, and known callers with an indicator of how I wanted the IP04 to handle the call. This call handling indicator had several values, rangeing from a "polite rejection of call" through to "pass through to home phones without delay". I updated the Asterisk dialplan to take advantage of these "known caller" call handling values by looking incoming call CallerId up in an Asterisk KnownCaller database, and routing the call according to the value found (or not found)1. To get these values from server to the IP04, I added cron job to the IP04 which would refresh this Asterisk DB by querying a host webpage that, in turn, would push the values up to Asterisk on the IP04. Now that I had this "known caller" information on the IP04, I also added a "distinctiver ring" to the dialplan, based on the value retrieved from the Asterisk KnownCaller database, to help identify the type of caller to the household.

Not satisfied to stop there, I added more "push notification" code to the IP04 to send a "call started" message to server when Asterisk accepted an incoming call. On the server and other household computers, I installed Mosquitto, an open source message broker that implements the MQTT protocol. Additionally, I installed the CMU Flite text-to-speech programs and libraries on the household computers. With changes to the server script that handles incoming IP04 notifications, when the IP04 pushes an "incoming call" message, the server distributes the notification (through MQTT) to all household computers, along with the caller's name (if any) from the "known caller" database tables, where a process then reads the notification aloud2. So, I get a voice notification of the caller's name (or phone-number, if no name or text callerid is available) before the phone rings.

The next steps are to replace that netcat/inetd hack I use to push call notifications from the IP04 to my server with something a bit more acceptable. With this in mind, I have now compiled the Mosquitto MQTT library and it's publication client for the IP04, packaged them both in a BAPS ipkg3, and installed them on the IP04. The next changes will be to replace the netcat push script with the MQTT publication client, and rewrite the server's notification receipt script to use MQTT instead of inetd. With this, I can start integrating the IP04 and Asterisk dialplan into a larger home automation project that will use MQTT as it's communications backbone.


  1. Here is a flowchart of the dialplan for incoming calls.
  2. I've written a suite of programs that makes this a bit easier. A daemon handles system-wide voice output, and various clients feed it text to speak. The daemon supports multiple voices, so that each source can have it's own sound.
  3. In time, I will make these packages available on the website. But first, I have to work with them a bit to ensure that they don't fail, and that the packaging is acceptable.