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 (220.127.116.11), 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.
- Download source code
- Upload the attached sketch to your Arduino
- 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”
- 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
- Restart asterisk services with “amportal restart”
- Hack the code apart and make it do something awesome!