ECE497 Beagle VNS

From eLinux.org
Revision as of 09:47, 13 November 2012 by Geislekj (talk | contribs) (Theory of Operation)
Jump to: navigation, search

thumb‎ Embedded Linux Class RHIT

by Tom Atnip, Kevin Geisler, Ruffin White


BeagleVNS.png


Grading Template

I'm using the following template to grade. Each slot is 10 points. 0 = Missing, 5=OK, 10=Wow!

10 Executive Summary (Looks good.  Be sure to keep it up to date)
00 Installation Instructions (I suggest putting the Hardware section before the software)
05 User Instructions (How do I make sendmail work on my Bone?)
00 Highlights (Not done yet)
00 Theory of Operation (ditto)
10 Work Breakdown
00 Future Work
00 Conclusions
00 Demo
00 Late
Comments: I'm looking forward to seeing the completed project.

Score:  25/100

Executive Summary

Where is Dr. Yoder?
I'll leave him a message

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 have have been 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 encoding the recording into a mp3 file and send it via an email message 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 and where to send the email message.

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 nodejs server controlls the preference file for the python script.

Hardware

BeagleBone
PlayStation Eye
Belkin N150 Micro Wireless USB Adapter
  • 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.
To download the code for the Beagle VNS run the following code:
beagle$ git clone git://github.com/geislekj/BeagleBoardVNS.git
  • 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.
  • 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
  • GStreamer
GStreamer is an application that allows the user to capture video from a camera for multiple types of solutions. For this project, it is being used to capture an image of the person leaving a message.
Instructions to install GStreamer is still in the process of being developed.

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
  • 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
  • Email Script
A python mail client that prompts the user for information to send an email with optional attachments.
 python smtp-mail-client-attachments.py
 Send To (Separated by a comma): 
 Files (Separated by a comma): 
 Send From: beagle497@gmail.com #Must use this email for now
 Subject: 
 Message:
  • Install Instructions
Currently as long as the arecord libraries are installed and nodejs is install, no other installation is required. The app file will use files that are contained in the 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.

Highlights

Here is where you brag about what your project can do.

Include a YouTube 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 vouice accounts

7. Create an email script to send email with attachments - Tom

Email sending

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

This is still being developed

10. Create a C program to capture the audio and listen for GPIO inputs - Kevin & Ruffin

This is still being developed

11. Putting all the pieces together - Tom, Kevin, & Ruffin

Making c file for initializing GPIOs, interrupts and start up scripts for VNS server

Code

C

/*
 * main.c
 *
 * ============================================================================
 * Copyright (c) Texas Instruments Inc 2005
 *
 * Use of this software is controlled by the terms and conditions found in the
 * license agreement under which this software has been supplied or provided.
 * ============================================================================
 */

// Standard Linux headers
#include     <stdio.h>              // Always include this header
#include     <stdlib.h>             // Always include this header
#include     <signal.h>             // Defines signal-handling functions (i.e. trap Ctrl-C)


// Application headers
#include     "debug.h"
// #include     "audio_thread.h"
#include     "gpio.h"

// 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[] )
{
    int   status = EXIT_SUCCESS;

    void *audioThreadReturn;


    // Set the signal callback for Ctrl-C
    pSigPrev = signal( SIGINT, signal_handler );
    DBG( "Registered SIGINT signal handler.\n" );

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

	//SET DIRECTION
	setdirection(button,1);	
	
//	printf("ENTER");
    while(1){
//	printf("Button:%d",bValue);
	bValue = gpioRead(button);
	if(bValue){
		printf("Button Pushed");
		//Grab the audio from the microphone while the button is pressed
		//audioThreadReturn = audio_thread_fxn( (void *) &audio_env, button);
		//runs a script that will take the raw file saved and encode it to mp3 useing lame and send via email.
 		system("./../BeagleVNSScript");
	}	
//	sleep(100);
    }
}

Python

import smtplib, os, sys
#from getpass import getpass
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 *

#def send_mail(send_files=""):
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]

    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()



#if __name__ == '__main__':
#    send_mail()

Future Work

Suggest addition things that could be done with this project.

  1. Web Interface using HTML and NodeJS
  2. Web Interface to manage audio files
  3. Capture video along with audio
  4. Voice-To-Text
  5. Low Power Mode for longer battery life
  6. Authentication

Parts

Beagle Bone

PlayStation Eye

Belkin N150 Micro Wireless USB Adapter

Duracell Instant USB Charger

Gigaware® USB 4-Port Hub

Conclusions

Give some concluding thoughts about the project. Suggest some future additions that could make it even more interesting.
Need More Cake
Want to discuss alsa limitations that prevented more advanced recording methods.



thumb‎ Embedded Linux Class RHIT

by Tom Atnip, Kevin Geisler, Ruffin White