ECE497 Beagle VNS

Executive Summary


We wanted a way for students to be able to leave audio (and possibly video) messages for professors when they are out of their office. Using a BeagleBoard Bone, we plan to connect a wireless USB device and a PlayStation Eye to achieve this. Students will be able to walk up to the device and press a button to record their message which will then be available for the professor.

At this time, we are able to successfully capture audio while a user presses and holds a button. Once the button is released, there is a python script that will encode the recording into a mp3 file and send it via an email attachment to a predetermined email address. We have also developed a web interface that will allow a user to change the preferences for what email account to use, who to send the email message too, as well as what text to populate the subject and body field with.

The wireless usb adapter does not work at this time. We are still trying to get recompile the kernel to install and enable the driver for this wireless adapter.

Overall we have a functioning project that consist of a C program, python script, bash script, and nodejs webserver. The C program controls how the audio is recorded. The python script controls sending emails with attachments. The bash script is in charge of moving the audio file, converting it to mp3, and firing the python script. The node.js server controlls the preference file for the python script.

Hardware



 * BeagleBone


 * This project is design primarily for the BeagleBone, but could be implemented on any other Beagle Board given the proper driver installation for the USB hardware and available GPIOs. The BeagleBone is applicable for this project due to is small size, low power consumption, and networking capabilities. Make sure to use the A5 image of Ångström as the A6 image is still buggy with respect to audio/video capturing, as well as using the USB WiFi drivers.


 * Further BeagleBone documentation can be found on the official Beagle Board website.


 * This device can be found available here


 * Camera


 * In this project tutorial, we will be using the PlayStation Eye as the audio and video source to recod messages and capture face images. The PlayStation Eye is very compatible with the A5 image of Ångström and used in many other Beagle embedded Linux projects.


 * This device can be found available here


 * Wifi dongle


 * Here we would like to use a WiFi dongle to easily connect to surrounding wireless networks for ease of installation and placement in the remote stretches of hallways and doorframes. We will need we will need network connectivity to transmit e-mails and recording attachments over to an available e-mail server account. In particularly we are using the Belkin N150 Micro Wireless USB Adapter.


 * Although this device is not natively supported with the stock A5 image of Ångström, a brief tutorial has already been made on how to compile and install the device drivers for this particular wireless USB adapter: Belkin Micro Wi-Fi USB dongle on the BeagleBoard


 * Battery Pack and USB Hub


 * To again better a ease installation and quick deployment for our system we are using a battery pack to provide power for the BeagleBone, the WiFi dongle and the USB camera. Due to the hottest limitations of the Beagle bones single USB port, in addition to the limited amount of current that the single USB port can provide, we will also use a USB hub with power adapter to solve both issues.


 * Specific products we are using included Duracell Instant USB Charger and Gigaware® USB 4-Port Hub


 * Doorbell


 * In order for the end user to trigger the recording sequence, we will implement a traditional mechanical momentary pushbutton that will connect to the BeagleBone’s GPIO using the enabled internal pull-up resistors.


 * LED


 * As a simple display, our project will utilize a simple LED as an indicator for the user that the audio is currently being recorded and that a face capture will be taken.

Software

 * Angstrom A5 Image


 * In order to use the camera drivers for the playstation eye you will need to install the A5 image on the beagle bone. To do this you will need to download the A5 image.  Then you will need to install this image on the sd card of the BeagleBone using the instructions bases on | ECE 497 Exercise 03 Installing a Beagle OS.


 * github


 * In order to use the project code for the Beagle VNS, you will need github installed in order to download the code. If you do not have github there are instruction on how to install it on the ECE Exercise 16 web page.


 * Python


 * Python is natively installed on the Beagle operating system. However it is important to note that the program will be using a python script to send email, and that we have been working under Python 2.7 and did not need to modify our code for version 3.0 syntax.


 * ALSA


 * The project uses ALSA drivers in order to record audio from a microphone device.


 * In order to download the ALSA drivers you will need to run the following commands:

beagle$ opkg update beagle$ opkg install alsa-utils-aplay alsa-utils-amixer alsa-dev alsa-utils


 * Lame


 * Lame is a audio encoder that will take raw audio and convert it into an mp3 format.


 * To install the lame onto the beagle board you will need to run the following command.

beagle$ opkg install lame


 * Node.js


 * Node.js is a tool for quickly make web or browser based interfaces for networking with the beagle or any comparable platform.


 * Installation instructions can be found here: ECE497 Notes on node.js

Install Instructions

 * In order to run this application the ALSA library must be installed.
 * Node.js is an optional installation if you would like a web interface for changing the email preferences file.


 * No other installation is required. The application developed is available on a git repository. The python script does not need any additional packages, and the javascript libraries are also located in the repository.


 * For simplicity and clarity when reading and understanding the code, as well as some limitations with using mix of C, Python, and bash scripts, there exists some hard-coded references dependencies. As such, we suggest cloning the repo to your home directory to get up and running first before modifying anything for your own application. Otherwise the program will not work.  Follow the github section below to download the repository.


 * To download the code for the Beagle VNS run the following code:

beagle$ cd beagle$ git clone git://github.com/geislekj/BeagleBoardVNS.git

User Instructions

 * Basic Command Line Examples


 * In order to give you a feel to how the program is capturing and sending emails. Here is a short run down of how the program works


 * Restart the Network
 * If you cannot grab an ip address from a dns server when the A5 image initially boots up. Run the following command in order to restart the network service

beagle$ /etc/init.d/networking restart


 * Audio Capture


 * In order to capture audio, the project uses arecord. This application allows you to grab audio from a microphone that is attached to your device and save to the current directory in a raw format.


 * Here is an example command that allows you to record audio and then pipe the audio into aplay to instantaneously hear feedback:

beagle$ arecord -D plughw:0,0 | aplay


 * In order to encode the audio into mp3 format, you will need to pipe the audio into lame instead of aplay.


 * Here is an example of this:

beagle$ arecord -D plughw:0,0 -r 16000 -f S16_LE -c 2 -t raw -d 3 | lame -s 16 -r - blackbird.mp3


 * For more information about ALSA and how to use many of its interesting features visit | Jan Axelson's Lakeview Research web page


 * Beagle VNS Application


 * In order to run the Beagle VNS Application you will need go to the C-Programs Directory

beagle$ cd ~/BeagleBoardVNS/C-Program/


 * Once you are in this directory, you will need to compile the application.

beagle$ make clean; make


 * Now you can run the application. There is currently only a debug version of the application.  This verision will print out debug information which is helpful to see what is going on.

beagle$ ./beagleVNSApp_DEBUG


 * You can also start the node.js server to edit the configuration file. Simply run the command below in the BeagleBoardVNS destroyer and then point your browser to the beaglebone's port 8081 with a URL or host name, i.e: beagleVNS.local:8081

beagle$ node BeagleBoardVNS.js


 * Note that you can change your host name by editing this file: /etc/hostname. For example:

beagle$ nano /etc/hostname

Highlights
BeagleVNS YouTube Video Demo

BeagleVNS YouTube Video Demo

Theory of Operation


This device is intended to record audio messages from students when professors are out of their office. The device will sit outside a professors office and will have a microphone and user button attached. A student who wishes to leave a message will press and hold the button then begin speaking, when the student has finished speaking they will release the button. The software will then save the audio file and then send the file as a mp3 to the user specified email.

As a user the professor will be able to modify the default preferences such as email to send to and the message that they receive.

The system consists of a C program that will need to be started and checks for the button press. When it picks up that the button has been pressed it collects audio until the button is released. The system then calls on a python mail client script passing in the location of the newly created audio file. The python script then reads from the user preferences and sends an email accordingly.

.

Work Breakdown
List the major tasks in your project and who did what.

Also list here what doesn't work yet and when you think it will be finished and who is finishing it.

1. Acquire Hardware - Ruffin
 * Done

2. Set up project page - Tom & Kevin
 * Page made and updated

3. Get USB wireless to work - Kevin & Ruffin
 * This is not working at this time for A6 image

4. Get PlayStation Eye to work - Tom
 * Audio working, need to use A5 image
 * Passing capture video on to Ruffin

5. Get BeagleBoard Bone to run off a battery pack - Ruffin
 * Done

6. Register an email for the BeagleBoard - Ruffin
 * Google acound made, along with Gmail and Google voice accounts

7. Create an email script to send email with attachments - Tom
 * Email sending complete

8. Encode the raw audio from ALSA into mp3 format - Kevin
 * Able to record on bone, use lame to convert file, and SCP to send to PC and listen to the recording

9. Capture an image using GStreamer - Kevin & Tom & Ruffin
 * This is still being developed

10. Create a C program to capture the audio and listen for GPIO inputs - Kevin & Ruffin
 * This is complete it is in the C-Program Directory

11. Putting all the pieces together - Tom, Kevin, & Ruffin
 * If you run the C-Program the audio collection will work. However, the web interface is a separate service you will need to start.

C
The following C application is used to collect audio from the Playstation Eye and then write it to a file when a gpio button is being pressed. Once the pgio button is released, the program runs a bash file that will encode the raw audio into mp3 and email it.

/* * main.c * */

// Standard Linux headers //#include                             // Defines memcpy
 * 1) include                  // Always include this header
 * 2) include                 // Always include this header
 * 3) include                 // Defines signal-handling functions (i.e. trap Ctrl-C)
 * 4) include                              // Defines open, read, write methods
 * 5) include                             // Defines close and sleep methods
 * 1) include    			// ALSA includes

// Application headers //#include    "audio_thread.h"
 * 1) include    "debug.h"
 * 1) include    "gpio.h"
 * 2) include    "audio_input_output.h"             // Audio driver input and output functions

//* ALSA and Mixer devices ** //#define    SOUND_DEVICE     "plughw:1,0"	// This uses the PS EYE mikes
 * 1) define    SOUND_DEVICE     "plughw:0,0"	// This uses line in

//* Output file name **
 * 1) define    OUTFILE          "/tmp/audio.raw"

//* The sample rate of the audio codec **
 * 1) define    SAMPLE_RATE      8000

//* The gain (0-100) of the left channel **
 * 1) define    LEFT_GAIN        100

//* The gain (0-100) of the right channel **
 * 1) define    RIGHT_GAIN       100

//* Parameters for audio thread execution **
 * 1) define    BLOCKSIZE        48000

// Success and failure definitions for the thread
 * 1) define    AUDIO_THREAD_SUCCESS     ( ( void * ) 0 )
 * 2) define    AUDIO_THREAD_FAILURE     ( ( void * ) - 1 )

// The levels of initialization for initMask
 * 1) define    INPUT_ALSA_INITIALIZED      0x1
 * 2) define    INPUT_BUFFER_ALLOCATED      0x2
 * 3) define    OUTPUT_FILE_OPENED          0x4

// Thread environment definition (i.e. what it needs to operate) typedef struct  audio_thread_env {   int quit;                // Thread will run as long as quit = 0 int button; } audio_thread_env;

// Global audio thread environment audio_thread_env audio_env = {0};

/* Store previous signal handler and call it */ void (*pSigPrev)(int sig);

// Callback called when SIGINT is sent to the process (Ctrl-C) void signal_handler(int sig) {   DBG( "Ctrl-C pressed, cleaning up and exiting..\n" ); audio_env.quit = 1;

if( pSigPrev != NULL ) (*pSigPrev)( sig ); }

//***************************************************************************** //* main //***************************************************************************** int main( int argc, char *argv[] ) {

// Variables and definitions // *************************

// button values int button = 16; int bButton = 1; int bValue = 0; int recording = 0; button = (bButton*32)+button; audio_env.button = button; exportgpio(button);

// led light int led = 17; int bled = 1; led = (bled*32)+led; exportgpio(led);

//SET DIRECTION setdirection(button,1); setdirection(led,0);

//turn off led gpioWrite(led,1);

// Thread parameters and return value void            * status = AUDIO_THREAD_SUCCESS;      // < see above unsigned int   initMask =  0x0;		// Used to only cleanup items that were init'd

// Input and output driver variables snd_pcm_uframes_t exact_bufsize; snd_pcm_t	*pcm_capture_handle;

FILE         * outfile = NULL;	// Output file pointer (i.e. handle) int  blksize = BLOCKSIZE;		// Raw input or output frame size char *inputBuffer = NULL;		// Input buffer for driver to read into

// Setup audio input device // ************************

// Open an ALSA device channel for audio input exact_bufsize = blksize/BYTESPERFRAME;

if( audio_io_setup( &pcm_capture_handle, SOUND_DEVICE, SAMPLE_RATE, SND_PCM_STREAM_CAPTURE, &exact_bufsize ) == AUDIO_FAILURE ) {               ERR( "Audio_input_setup failed in audio_thread_fxn\n\n" ); status = AUDIO_THREAD_FAILURE; goto cleanup; }       DBG( "exact_bufsize = %d\n", (int) exact_bufsize);

// Record that input OSS device was opened in initialization bitmask initMask |= INPUT_ALSA_INITIALIZED;

blksize = exact_bufsize*BYTESPERFRAME; // Create input buffer to read into from OSS input device if( ( inputBuffer = malloc( blksize ) ) == NULL ) {          ERR( "Failed to allocate memory for input block (%d)\n", blksize ); status = AUDIO_THREAD_FAILURE; goto cleanup ; }

DBG( "Allocated input audio buffer of size %d to address %p\n", blksize,inputBuffer );

// Record that the input buffer was allocated in initialization bitmask initMask |= INPUT_BUFFER_ALLOCATED;

// Thread Execute Phase -- perform I/O and processing // **************************************************       while(1){ //Gets the button value //printf("Button:%d",bValue); bValue = gpioRead(button);

// Read capture buffer from ALSA input device if( snd_pcm_readi(pcm_capture_handle, inputBuffer, blksize/BYTESPERFRAME) < 0 ) {              	    snd_pcm_prepare(pcm_capture_handle); }

//Starts to record audio if(bValue && !recording){ printf("Button Pushed"); recording = 1; // Open a file for record outfile = fopen(OUTFILE, "w");

if( outfile == NULL ) {                         ERR( "Failed to open file %s\n", OUTFILE ); status = AUDIO_THREAD_FAILURE; goto cleanup ; }

DBG( "Opened file %s with FILE pointer = %p\n", OUTFILE, outfile );

// Record that input OSS device was opened in initialization bitmask initMask |= OUTPUT_FILE_OPENED;

// Processing loop DBG( "Entering audio_thread_fxn processing loop\n" ); gpioWrite(led,0); }

//saves to file while recording. if(bValue && recording){ if( fwrite( inputBuffer, sizeof( char ), blksize, outfile ) < blksize ) {                            ERR( "Error writing the data to FILE pointer %p\n", outfile ); status = AUDIO_THREAD_FAILURE; goto cleanup; }               }			// Sends the audio on button release if(!bValue && recording){ printf("Button Released"); gpioWrite(led,1);

DBG( "Closing output file at FILE ptr %p\n", outfile ); fclose( outfile ); DBG( "Freeing audio input buffer at location %p\n", inputBuffer ); free( inputBuffer ); DBG( "Freed audio input buffer at location %p\n", inputBuffer );

// Create input buffer to read into from OSS input device if( ( inputBuffer = malloc( blksize ) ) == NULL ) {			  ERR( "Failed to allocate memory for input block (%d)\n", blksize ); status = AUDIO_THREAD_FAILURE; goto cleanup ; }

//runs a script that will take the raw file saved and encode it to mp3 useing lame and send via email. system("~/BeagleBoardVNS/BeagleVNSScript"); //reset recording flag recording = 0; }	 }

// Thread Delete Phase -- free up resources allocated by this file // ***************************************************************

cleanup:

DBG( "Starting audio thread cleanup to return resources to system\n" );

// Close the audio drivers // ***********************   //  - Uses the initMask to only free resources that were allocated. // - Nothing to be done for mixer device, as it was closed after init.

// Close input OSS device if( initMask & INPUT_ALSA_INITIALIZED ) if( audio_io_cleanup( pcm_capture_handle ) != AUDIO_SUCCESS ) {           ERR( "audio_input_cleanup failed for file descriptor %d\n", (int) pcm_capture_handle ); status = AUDIO_THREAD_FAILURE; }

// Free allocated buffers // **********************

// Free input buffer if( initMask & INPUT_BUFFER_ALLOCATED ) {       DBG( "Freeing audio input buffer at location %p\n", inputBuffer ); free( inputBuffer ); DBG( "Freed audio input buffer at location %p\n", inputBuffer ); }

// Return from audio_thread_fxn function // *************************************

// Return the status at exit of the thread's execution DBG( "Audio thread cleanup complete. Exiting audio_thread_fxn\n" ); }

Python
This is the Python script that is used to email a message with an attachment.

import smtplib, os, sys from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.Utils import COMMASPACE, formatdate from email import Encoders from PREFERENCES import *
 * 1) from getpass import getpass

if __name__ == '__main__': #This version promts the user to specify recipient, files, #subject, and message. The version for incorperating in the #notifier will need to read from a preferences file that #should be modifiable by the user. print sys.argv[1] send_to = SEND_TO files = sys.argv[1]
 * 1) def send_mail(send_files=""):

send_to=send_to.split(',') files=filter(None, files.split(','))

#Make sure that we are working with a list assert type(send_to)==list assert type(files)==list

send_from = SEND_FROM subject = SUBJECT

#Create a message object that we will be sending msg = MIMEMultipart msg['From'] = send_from msg['To'] = COMMASPACE.join(send_to) msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject

text = MESSAGE

msg.attach( MIMEText(text) )

#Attach files to message for f in files: part = MIMEBase('application', "octet-stream") part.set_payload( open(f,"rb").read ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) msg.attach(part)

#Open up a connection to the gmail servers on port 587 server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo server.starttls server.ehlo #password = getpass password=PASSWORD server.login(send_from, password) server.sendmail(send_from,",".join(send_to),msg.as_string) server.close


 * 1) if __name__ == '__main__':
 * 2)    send_mail

Future Work
Suggest addition things that could be done with this project.


 * 1) Web Interface to manage audio or achieve files locally
 * 2) Capture video along with audio or capture image upon button press
 * 3) Voice-To-Text using Google Voice API
 * 4) Low Power Mode for longer battery life using interupts
 * 5) Release alsa device for other aplications when not in use
 * 6) Authentication
 * 7) Wireless Communication

Parts
Beagle Bone

PlayStation Eye

Belkin N150 Micro Wireless USB Adapter

Duracell Instant USB Charger

Gigaware® USB 4-Port Hub

Conclusions
Overall, we currently have a working version of the Beagle VNS. There are two separate parts to the project. The Beagle C-Program records the audio and sends an email with an mp3 attachment. There is also a web interface which will allow a user to change the default sender and recipient email address. Some cool additions to the project would be to be able to take an video and audio message, as well as incorporate a wireless driver.