Quantcast
Channel: OpenEnergyMonitor aggregator
Viewing all articles
Browse latest Browse all 328

Nathan Chantrell.net: Sending incoming call info to MQTT

$
0
0

asterisk-mqttI’ve used Asterisk at home since around 2004, originally using a clone of a Digium FXO card and later a Sipura SPA-3000 (later owned and branded by Linksys) to interface to my landline. When that server decommissioned itself (with a bang and bad smell) a year or so ago I switched over to the Asterisk based FreePBX on a Raspberry Pi (using the RasPBX distro) but still using the old but perfectly serviceable SPA-3000. It’s rare that anyone I want to speak to calls me on the landline these days (hi Mum!) but I need to keep it active for my BT Infinity fibre broadband so I may as well have something connected to it. Most of the calls I do get on it are junk so I have Asterisk set up to only ring the phones for a specific set of callers and anyone else just gets dumped straight to voicemail or rejected.

On the old server I had set up various extensions that I could dial to perform tasks or drop me into a home automation menu if I called home from my mobile but it never really got any use so I haven’t bothered reimplementing that but one thing I did want to do was as feed incoming call info (caller number and time and date) into MQTT so I could log it and create notifications or events based on a particular callers numbers using Node-RED.

AGI the “Asterisk Gateway Interface” was obviously the way to do this and it turned out that someone has made this very easy by creating an agi-mqtt bridge.

Setting this up was a doddle:

  1. Clone the agi-mqtt Github into a suitable location on the Asterisk box, I put it in /opt/agi-mqtt/
  2. Copy mqtt.cfg.sample to mqtt.cfg and edit it to set the details for your MQTT server.
  3. Make sure the mqtt python script is executable
  4. Edit /etc/asterisk/extensions_custom.conf and add:[from-pstn-custom]
    exten => _X.,1,AGI(/opt/agi-mqtt/mqtt,/opt/agi-mqtt/mqtt.cfg,calls/pstn-in)

Obviously changing /opt/agi-mqtt/ for the location you used to install agi-mqtt and calls/pstn-in is the topic you want to send the call info to.

Then in Node-Red you can parse the number from the call data passed into the payload, this could just be a simple function to output the caller number such as:

var calldata = JSON.parse(msg.payload);
msg.payload = calldata.callerid;

I do a bit of translation of numbers to names for the select group that might ever call me on my landline so that voice and display notifications use their name instead of the number. I also log all calls to a text file, mainly so I can look at it once in a while and be amazed at all the phone spam I (didn’t) get.

Landlines; The sooner I don’t need one for my internet connection, the better.


Viewing all articles
Browse latest Browse all 328

Trending Articles