Using Asterisk to Control your Arduino

Posted on
Using Asterisk to Control your Arduino

Being an avid Asterisk admin and a novice AGI coder, I decided that it would be cool to try my hand at using Asterisk to control my Arduino over ethernet. Upon googling similar projects I came across Kate Hartman’s page on doing just that with an Arduino connected via an XPort module. Well, I have the Adafruit ethernet shield with a WIZnet module, but I decided to give it a try anyway. The first thing I noticed was the Arduino code appeared to be communicating with the XPort module via serial communication. This is a bit of a problem as the WIZnet module needs to make use of the ethernet library in Arduino IDE. So I threw together a little test environment with an LED connected to pin 4 and plugged in my ethernet shield to give the code a shot. Needless to say, it didn’t work straight out of the box…so I’ve made a few minor modifications which you can find attached to this post. I also found that Kate’s Asterisk AGI code was a bit dusty, being written perhaps for an older version of Asterisk than what I have (1.4.21.2), so I made a few modifications and was able to get it up and running. This should come in REALLY handy for some of the projects I’ve got waiting in the wings (ArduinOIL). Here’s how to get it up and running.

    1. Download source code
    2. Upload the attached sketch to your Arduino
    3. Copy the arduino_control.php file into your agi-bin (usually /var/lib/asterisk/agi-bin) and edit the configurable options to match your setup. Make sure you change the permissions on the file with “chown asterisk:asterisk arduino_control.php” and also make it executable with “chmod +x arduino_control.php”
    4. Edit your dial plan (I use freePBX so the file is /etc/asterisk/extensions_custom.conf, otherwise it would be /etc/asterisk/extensions.conf) to include the following lines (you can change the 999 to whatever extension you prefer to dial to get control of your arduino):

; Arduino Control
exten => 999,1,Answer
exten => 999,2,AGI(arduino_control.php)
exten => 999,3,Hangup

 

  1. Restart asterisk services with “amportal restart”
  2. Hack the code apart and make it do something awesome!


Comments ( 6 )

  1. ReplyThe009
    Amazing Project, I was wondering if you know of a way to trigger the arduino to make a call out? I am working on modifying my crappy old home buzzer to make it ring a cordless phone here at my house so I know when someone is at the door. Any help would be great. Regards, The009
  2. ReplyDan
    That's a great idea. You can trigger asterisk to make an outbound call using the methods described on this page: http://www.voip-info.org/tiki-index.php?page=Asterisk+auto-dial+out The hardest part would be getting the arduino to trigger the process over IP...off the top of my head having the arduino SSH into the PBX would probably be the easiest way. Connecting over HTTP would be another option. I may take a stab at it and post the details if I can find the time.
  3. ReplyRalf
    Hi, interesting project. What about the other way? Connect the old door-bell push-botton to an arduino, which initiates a sip-call via ethernet-shield. So it rings on every phone / cell-phone at home or even in the garden. Is this possible? The commericial stuff including voice (SIP-Door-Station) is to expensive. Regards, Ralf
  4. ReplyDan
    Thanks Ralf! Unfortunately, in order to have an Arduino make a SIP phone call, you'd have to do some pretty serious coding to make it handle SIP registers / notifies, etc. I'm not THAT good at programming :) I agree though...it'd be really neat to see.
  5. Replysean
    Just curious to know if you have made any more progress with arduino and asterisk... nice job with connecting the two, btw.
  6. ReplyPablo
    Hi, I´m trying to do this project, but I have many question: What I need to connect my cell phone to Asterisk?? What I can do if I don't have WIZnet module?? Can you let me see the circuit's construction?