May
14
Posted on 14-05-2009
Filed Under (Arduino, Asterisk) by Dan

I’m currently working on a project that works with pachube to post information to the web. It’s really handy to be able to get the sensor information from my Arduino to the web with an ethernet shield and a few lines of code. However, I want to take this functionality a step further and make the pachube feed available from my Asterisk phone system in the rare event that I’m away from civilization and don’t have access to an internet connection. The script I came up with is geared towards my ArduinOil project, but could easily be converted and used in any way with any information. The way it works is this: user calls extension (or could be made available from an AVR), the AGI script requests pachube feed information, flight or cepstral is used to read information to user. Here’s what you’ll need to do to get it up and running:

  1. Download the pachube PHP library, and pachube AGI script.
  2. Unzip the pachube_functions.php file from the PHP library zip and copy it and the AGI script into /var/lib/asterisk/agi-bin/
  3. Unzip pachube.php from the AGI script zip and copy it into /var/lib/asterisk/agi-bin/
  4. chmod +x and chown asterisk:asterisk both files
  5. Make changes to configurable options in pachube.php (ie. api key, feed id, etc.)
  6. Add the following dial plan code to your extensions.conf or extensions_custom.conf (FreePBX)
  7. exten => 750,1,Answer
    exten => 750,n,Wait(2)
    exten => 750,n,AGI(pachube.php)
    exten => 750,n,Hangup

  8. Reload your asterisk dial plan: asterisk -rx dialplan reload

There is more feed information available from the pachube PHP library such as latitude and longitude of the project, multiple datastreams, etc. But this should be enough to get you on your way. Enjoy!

(0) Comments    Read More   
March
13
Posted on 13-03-2009
Filed Under (Arduino, Asterisk) by Dan

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):
  5. ; Arduino Control
    exten => 999,1,Answer
    exten => 999,2,AGI(arduino_control.php)
    exten => 999,3,Hangup

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

(0) Comments    Read More