Difference between revisions of "S14: Android based home monitoring system"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Software Design)
(Project Source Code)
 
(51 intermediate revisions by one other user not shown)
Line 1: Line 1:
=== Grading Criteria ===
 
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
 
 
== Android based home monitoring system==
 
== Android based home monitoring system==
  
Line 20: Line 8:
 
#  Android application to view status of sensors
 
#  Android application to view status of sensors
  
=== Team Members ===
+
== Team Members ==
 
#  Om Narasimhan
 
#  Om Narasimhan
#*  Software design and Android App development
+
#*  FreeRTOS application design-protocol implementation
 
#  Aysha Malik
 
#  Aysha Malik
#*  Hardware interface design and integration
+
#*  Android application development
 
#  Sri Latha Ayyannagari
 
#  Sri Latha Ayyannagari
#*  FreeRTOS driver design and development
+
#*  FreeRTOS device driver and data structures implementation
  
 
== Schedule ==
 
== Schedule ==
Line 60: Line 48:
 
| 3/13
 
| 3/13
 
| Study about bluetooth module and its interfacing
 
| Study about bluetooth module and its interfacing
| In progress
+
| Completed
 
|-
 
|-
 
! scope="row"| 5
 
! scope="row"| 5
Line 66: Line 54:
 
| 3/13
 
| 3/13
 
| Learn application development using Android,  Complete hardware interfaces
 
| Learn application development using Android,  Complete hardware interfaces
| In progress
+
| Completed
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
Line 72: Line 60:
 
| 3/18
 
| 3/18
 
| Finish software design and conduct reviews  
 
| Finish software design and conduct reviews  
| Not yet started
+
| Completed
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
 
| 3/18
 
| 3/18
| 4/4
+
| 4/8
| Driver development to communicate with Android app. Developing android App. Communication protocols implementation
+
|Develop App to establish communication b/w bluetooth device android device, Add component in app to discover available devices,Develop SPP emulator for android app
| Not yet started
+
| Completed
 +
|-
 +
! scope = "row"| 8
 +
|4/8
 +
|4/18
 +
|working on developing data transfer protocol and communicating with multiple devices at the same time
 +
|Completed
 
|-
 
|-
! scope="row"| 8
+
! scope="row"| 9
| 4/4
+
| 4/18
| 4/6
+
| 4/25
 
| Integrate code and start testing
 
| Integrate code and start testing
| Not yet started
+
| Completed
 
|-
 
|-
! scope="row"| 9
+
! scope="row"| 10
| 4/6
+
| 4/25
| 4/10
+
| 4/30
 
| Resolve issues if any
 
| Resolve issues if any
| Not yet started
+
| Completed
 
|-
 
|-
 
! scope="row"| 10  
 
! scope="row"| 10  
| 4/10
+
| 4/30
| 4/15
+
| 5/3
 
| Final Testing
 
| Final Testing
| Not yet started
+
| Completed
 
|}
 
|}
  
Line 114: Line 108:
 
| align="center"|1||Samsung Galaxy S4||Samsung ||align="center"|-||align="right"|   
 
| align="center"|1||Samsung Galaxy S4||Samsung ||align="center"|-||align="right"|   
 
|-
 
|-
| ||'''Total Cost'''|| || ||align="right"|'''  !'''
+
| ||'''Total Cost'''|| || ||align="right"|'''  262.50'''
 
|-
 
|-
 
|}
 
|}
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.
+
The project was completed in a number of steps
 +
 
 +
1. Device driver development
 +
 
 +
2. Android Application development
 +
 
  
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design hereShow detailed schematics, and the interface here.
+
[[File:CmpE244_S14_AHM_JY_MCU.JPG|200px|thumb|right|Fig 1. Bluetooth module]]
 +
Basic Bluetooth module (JY-MCU HC-06) was purchased from ebay for $8 including shipping. This particular series (HC-06) has four pins RX, TX, VCC and GND and can only work in slave modeThe module specification mentions that the module can be reprogrammed, but the KEY and STATE pins are not available in this series (HC-06).
 +
 
 +
Note: Although VCC pin indicates that the module works with 3.6-6V, connecting it to the LPC1758 3.3V output worked fine. 
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
+
 
 +
This project uses UART2 for communication.The default setting for UART is: Baud Rate - 9600, no parity, one start bit and one stop bit.
 +
 
 +
[[File:CmpE244_S14_AHMS_HW_Interface.jpg|400px|thumb|center|Fig 2. Hardware Interface]]
  
 
=== Software Design ===
 
=== Software Design ===
 +
[[File:CmpE244 S14 AHMS Android Software.jpg|300px|thumb|right|Fig 3. Android application flowchart]]
  
 
Parameters are monitored by devices placed in each room. The monitoring device communicates to android application using Bluetooth. The application records incoming data from different devices and continuously analyses it. Interpretation of the data can either be done in real time or at fixed intervals and logical decisions are taken (e.g, no motion sensor update for X minutes, so switch off lights, or based on the historical data, switch on lights at a particular time ..etc)
 
Parameters are monitored by devices placed in each room. The monitoring device communicates to android application using Bluetooth. The application records incoming data from different devices and continuously analyses it. Interpretation of the data can either be done in real time or at fixed intervals and logical decisions are taken (e.g, no motion sensor update for X minutes, so switch off lights, or based on the historical data, switch on lights at a particular time ..etc)
  
*Application GUI
+
In this project software design has two components: device driver and android application. 
<TODO>
+
 
 +
Figures (Fig 3 and Fig 4 )give an overview of the individual components.
 +
[[File:CmpE244 S14 AHMS Device Driver.jpg|300px|thumb|center|Fig 4. Device driver flowchart]]
 +
 
 +
 
 +
*Android application is implemented in three parts:
 +
 
 +
:1. Start Screen
 +
::*Enable Bluetooth
 +
::*Upon selection of Room connect to the corresponding device
 +
:2. Communication Screen
 +
::*Once connection is established, status is shown as connected or a message “connection failed”
 +
::*Send characters for information request and display incoming data
 +
::: Current Temperature
 +
::: Temperature History
 +
::: Current Lumosity
 +
::: Lumosity History
 +
:3. Graphing Screen
 +
::*Plot the requested weather data.
 +
 
 +
*Free RTOS application is implemented in two parts
 +
:1. Data Structure
 +
::*Every board gathers temperature and Luminosity samples at fixed intervals. The interval is configurable and was set at 5sec
 +
:2. Data gathering and transfer Protocol
 +
 
 +
 
 +
'''Android application development'''
 +
 
 +
[[File:CmpE244 S14 AHMS SDK manager.jpg|400px|thumb|right|Fig 5. Android SDK manager]]
 +
First thing to do before application development is to install the tools needed.  We downloaded the Android SDK and followed the instructions for tool setup in this tutorial.
 +
(https://developer.android.com/sdk/index.html) Second thing to get started on android development is to understand the android development environment we used this tutorial (https://developer.android.com/training/index.html) for building and run the first application.
 +
 
 +
It is very hard for anyone without the knowledge of Java and Xml to write an application from scratch. For this reason we used the Bluetooth Chat sample code provided in the Android SDK package as a starting point for this project.
 +
 
 +
'''Application GUI'''
 +
 
 +
Start app development by changing the main.xml file to add buttons as seen in the layout in figure(10) , add the corresponding stings in the string.xml file. This project uses the buttons to send a particular character when clicked. To do this change the BluetoothChat.java file as follows by adding the following lines of code in the setupChat() function.
 +
 
 +
 
 +
● The first screen for application is for home station selection
 +
[[File:CmpE244 S14 AHMS Home monitor 2.jpg|200px|thumb|right|Fig 6. First Screen]]
 +
 +
As you can see in the screen shot, there are three buttons to select among three home stations. Upon selecting a weather station (denoted by “roomX”, X => 1, 2, and 3), the application establishes a connection to the Bluetooth agent in the weather station.
 +
Once connection is established, the status is shown to the user as “connection established” or “connection failed”
 +
 
 +
● Screen for requesting statistics
 +
[[File:CmpE244 S14 AHMS Home monitor 1.jpg|200px|thumb|right|Fig 7. Select parameter]]
 +
 
 +
Add a new activity to the project, Activity_main. The IDE creates a corresponding xml file automatically. Create the layout as shown in figure(7),add the corresponding stings in the string.xml file. Copy and paste the Bluetooth enabling code from BluetoothChat.jave to Activity_main.java and add the functionality for the buttons as follows. For this project we have hardcoded the MAC address of the Bluetooth modules, the address is passed to the BluetoothChat activity. Add the following lines of code in Activity_main.java.
  
*Application configuration
+
There are 4 different buttons viz,
<TODO>
+
 +
:Temperature Now (Read the current temperature) History (Historical temperature data and graphs)
 +
:Light     Now (Read the current luminosity) History (Historical luminosity data and graphs)
 +
  
*Data Analysis
+
● Graphing method
<TODO>
 
  
*Data structures
 
<TODO>
 
  
*Communication protocol
+
:Our graphics are primarily based on the library “androidplot” downloadable from (www.androidplot.com)
<TODO>
+
:AndroidPlot is a very powerful package to plot graphs. The input for graphing method are two arrays of type Number. To plot an XY graph, these numbers are converted to XY-Series data type and use a LineandPointFormatter class. Once X-axis plane is fully plotted, another series will be used to plot Y- axis plane.
 +
[[File:CmpE244 S14 AHMS XYplotcode.jpg|400px|thumb|center|Fig 8. XYplotcode]]
 +
'''FreeRTOS Application configuration'''
  
=== Implementation ===
+
In main.c, we have instantiated two variables (one for Temperature and another for Luminosity) of type data_buffer with a buffer size 100 entries. We setup a thread to read the sensors at periodic intervals and fill into the corresponding buffers. By virtue of our data structure, maximum space allocated for readings are bound at the init time.
This section includes implementation, but again, not the details, just the high levelFor example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI FlashYou can include sub-sections for each of your component implementation.
+
 
 +
'''Data Analysis'''
 +
 
 +
The gather_tmplight() thread wakes up at intervals and fills in the data into the buffer. The Android app can query any device either for a. Last wrote data, or b. Complete history (upto 100 entries).
 +
 
 +
'''Data structures'''
 +
 
 +
[[File:CmpE244 S14 AHMS Datastructures code.jpg|400px|thumb|right|Fig 10. Data structures]]
 +
Every board gathers temperature and Luminosity samples at fixed intervals. The interval is configurable and default is set at 5sec. Initially, our first choice was to use a FIFO for storing these readings. But then, it became very difficult to discard older entries. Although we planned to have a timeout mechanism associated with every entry, later we figured out that a FIFO implementation based on a circular buffer would be easier to implement and maintain.
 +
Here is a graphical representation of our FIFO based on a circular buffer.
 +
[[File:CmpE244 S14 AHMS Circular-Buffer.jpg|290px|thumb|left|Fig 9. Circular buffer]]
 +
 
 +
 
 +
 
 +
'''Communication protocol'''
 +
 
 +
The transaction is carried out using the following protocol:
 +
 
 +
{| class="Protocol"
 +
|-
 +
! scope="col"| S.NO.
 +
! scope="col"| Message type
 +
! scope="col"| Description
 +
|-
 +
! scope="row"| 1
 +
| Query last wrote data – temperature
 +
| The application will write the character 'A' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'A'. It calls the stringify_data() method of the temperature buffer for last read data which is printed out with the set delimiter (default : $)
 +
|-
 +
! scope="row"| 2
 +
| Query last wrote data  – Luminosity
 +
| The application will write the character 'C' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'C'. It calls the stringify_data() method of the luminosity buffer for last read data which is printed out with the set delimiter (default : $)
 +
|-
 +
! scope="row"| 3
 +
| Query historical data  – temperature
 +
| The application will write the character 'B' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'B'. It calls the stringify_data() method of the luminosity buffer for all data in the history buffer. Resulting string, a $ delimited character array of all readings will be written to the uart. The application will read this array and convert them to numbers and input to the graphing function.
 +
|-
 +
! scope="row" | 4
 +
| Query historical data – Luminosity
 +
| The application will  write the character 'D' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'D'. It calls the stringify_data() method of the luminosity buffer for all data in the history buffer. Resulting string, a $ delimited character array of all readings will be written to the uart. The application will read this array and convert them to numbers and  input to the graphing function
 +
|-
 +
! scope="row"| 5
 +
| Any other query
 +
| Result in a single string “-01:-02”
 +
|-
 +
|
 +
|}
 +
 
 +
== Implementation ==
 +
The sample code is downloaded using the Android SDK Manager. From the navigation menu of the IDE go to Windows -> Android SDK Manager. All the installed and available SDK packages are listed; attention should be paid to the version of SDK platform. It should be the same as the Android version of your deviceThis project is developed using Android 4.2.2.(kitkat), API level 19. After this sample code can be found in the folder sdk->samples->android-19->legacy on the host machine. Import the Bluetooth Chat sample in to the project workspace.
 +
 
 +
[[File:CmpE244 S14 AHMS BluetoothChatService modification.jpg|500px|thumb|right|Fig 12. BluetoothChatService]]
 +
 
 +
Next step is to establish communication with the LPC1758 using Bluetooth Chat sample application. Bluetooth sample is not a functioning application; this tutorial (http://www.instructables.com/id/Android-talks-to-Arduino/?ALLSTEPS) provided the solution to the problem. It said to change the UUID in BluetoothChatService.java file to “00001101-0000-1000-8000-00805F9B34FB”
 +
[[File:CmpE244 S14 AHMS Send character code.jpg|500px|thumb|center|Fig 11. Setupchat]]
 +
 
 +
Once the change is made this application is able to communicate with LPC1758. In this project android application is composed of three activities: BluetoothChat.java, Avtivity_main.java and SampleXYPlotActivity.java.
 +
 
 +
*Develop start screen
 +
Start app development by changing the main.xml file to add buttons as seen in the layout in (fig.6) , add the corresponding stings in the string.xml file. This project uses the buttons to send a particular character when clicked. Modify the DeviceListActivity.java as follows to connect to the intended device automatically.
 +
[[File:CmpE244 S14 AHMS Activity main code.jpg|500px|thumb|center|Fig 13. start screen creation]]
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again?
+
'''Testing'''
Make a smooth transition to testing section and described what it took to test your project.
+
 
 +
Install the app BlueTerm on your android device. This app is a terminal emulator, and uses RFCOMM/SPP protocol for serial communication over Bluetooth. It is used to establish connection between LPC1758 and android device. The JY-MCU Bluetooth module appears as linvor in the available device list. Once the connection is established send a character from LPC1758 using Hercules, you should now be able to see the character appear on the terminal. Now send a character from the android device and it should appear on the Hercules terminal.
 +
This verifies the communication between LPC1258 and android device.
 +
 
 +
'''Challenges'''
  
Include sub-sections that list out a problem and solution, such as:
+
Data structures implementation: Initially we toyed with the idea of every reading will be stored with a timeout value. But soon it became apparent that it is not a scalable solution. So, we searched for an alternative and finally came up with a Circular Buffer based FIFO. Initially we tried storing both temperature and luminosity in the same data structure. But later it became so cumbersome that we decided to simplify code using two separate instances of the same data structure. Graph plotting was considered difficult till we came across Androidplot libraries.
  
=== My Issue #1 ===
+
Difficulty with testing: The state machine designed was to wait till a suitable input. In order to simplify testing, we implemented a command (to be input from the prompt) using a terminal task. Thus, by connecting uart2 to uart3 we could independently verify the functionality of the device – by reading the temperature value and history as well as Luminosity value and history.
Discuss the issue and resolution.
 
  
 
== Conclusion ==
 
== Conclusion ==
Conclude your project hereYou can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?
+
In conclusion the goal of the project was to make an android based home monitoring system that communicates via Bluetooth. The goal was successfully accomplished as all of the requirements set for the project were metThe team faced and overcame many challenges including but not limited to designing data management and transfer protocol, establishing communication between android device and LPC1758. These challenges were resolved through intensive research and testing. Through this project the team gained much valued knowledge and hands-on experience in developing applications for android and Free RTOS. Our group worked well together, new relationships were built. It was a challenging project due to the fact that all of the team was learning to do something new, but with hardwork and dedication of all team members, the project was successful. For future, more monitoring fucntions can be added; like alerts when environment changes quickly
  
 
=== Project Video ===
 
=== Project Video ===
Line 165: Line 283:
  
 
=== Project Source Code ===
 
=== Project Source Code ===
Send me your zipped source code and I will upload this to SourceForge and link it for you.
+
*  [https://sourceforge.net/projects/sjsu/files/CmpE244_SJSU_S2014/ Sourceforge source code link]
  
 
== References ==
 
== References ==
=== Acknowledgement ===
+
:1. Android development: http://developer.android.com/training/index.html
Any acknowledgement that you may wish to provide can be included here.
+
:2. User manual for SJOne development board
 +
:3. Graph generation: http://androidplot.com/docs/quickstart/
 +
 
 +
== Acknowledgement ==
 +
 
 +
Preet Kang
 +
 
  
=== References Used ===
 
  
 
=== Appendix ===
 
=== Appendix ===
 
You can list the references you used.
 
You can list the references you used.

Latest revision as of 23:45, 6 August 2014

Android based home monitoring system

Abstract

The home monitoring system is designed to monitor light and temperature of different rooms. The monitoring system will monitor light and temperature of different rooms and report the status to the user via an android application.

Features

  1. Light and temperature monitoring of multiple rooms
  2. Android application to view status of sensors

Team Members

  1. Om Narasimhan
    • FreeRTOS application design-protocol implementation
  2. Aysha Malik
    • Android application development
  3. Sri Latha Ayyannagari
    • FreeRTOS device driver and data structures implementation

Schedule

Sl. No Start Date End Date Task Actual
1 2/28 2/28 Order Components and Make a schedule Completed)
2 3/1 3/10 Components Procurement. Completed (03/06/2014)
3 3/6 3/6 Identify tasks assign work Completed (03/06/2014)
4 3/6 3/13 Study about bluetooth module and its interfacing Completed
5 3/6 3/13 Learn application development using Android, Complete hardware interfaces Completed
6 3/13 3/18 Finish software design and conduct reviews Completed
7 3/18 4/8 Develop App to establish communication b/w bluetooth device android device, Add component in app to discover available devices,Develop SPP emulator for android app Completed
8 4/8 4/18 working on developing data transfer protocol and communicating with multiple devices at the same time Completed
9 4/18 4/25 Integrate code and start testing Completed
10 4/25 4/30 Resolve issues if any Completed
10 4/30 5/3 Final Testing Completed

Parts List & Cost

Qty Description Manufacturer Part Number Total Cost
3 SJOne Board SJSU - $240.00
3 2013 Bluetooth Master UART Board Communication Module- 4 Needle Blue $22.50
1 Samsung Galaxy S4 Samsung -
Total Cost 262.50

Design & Implementation

The project was completed in a number of steps

1. Device driver development

2. Android Application development


Hardware Design

Fig 1. Bluetooth module

Basic Bluetooth module (JY-MCU HC-06) was purchased from ebay for $8 including shipping. This particular series (HC-06) has four pins RX, TX, VCC and GND and can only work in slave mode. The module specification mentions that the module can be reprogrammed, but the KEY and STATE pins are not available in this series (HC-06).

Note: Although VCC pin indicates that the module works with 3.6-6V, connecting it to the LPC1758 3.3V output worked fine.

Hardware Interface

This project uses UART2 for communication.The default setting for UART is: Baud Rate - 9600, no parity, one start bit and one stop bit.

Fig 2. Hardware Interface

Software Design

Fig 3. Android application flowchart

Parameters are monitored by devices placed in each room. The monitoring device communicates to android application using Bluetooth. The application records incoming data from different devices and continuously analyses it. Interpretation of the data can either be done in real time or at fixed intervals and logical decisions are taken (e.g, no motion sensor update for X minutes, so switch off lights, or based on the historical data, switch on lights at a particular time ..etc)

In this project software design has two components: device driver and android application.

Figures (Fig 3 and Fig 4 )give an overview of the individual components.

Fig 4. Device driver flowchart


  • Android application is implemented in three parts:
1. Start Screen
  • Enable Bluetooth
  • Upon selection of Room connect to the corresponding device
2. Communication Screen
  • Once connection is established, status is shown as connected or a message “connection failed”
  • Send characters for information request and display incoming data
Current Temperature
Temperature History
Current Lumosity
Lumosity History
3. Graphing Screen
  • Plot the requested weather data.
  • Free RTOS application is implemented in two parts
1. Data Structure
  • Every board gathers temperature and Luminosity samples at fixed intervals. The interval is configurable and was set at 5sec
2. Data gathering and transfer Protocol


Android application development

Fig 5. Android SDK manager

First thing to do before application development is to install the tools needed. We downloaded the Android SDK and followed the instructions for tool setup in this tutorial. (https://developer.android.com/sdk/index.html) Second thing to get started on android development is to understand the android development environment we used this tutorial (https://developer.android.com/training/index.html) for building and run the first application.

It is very hard for anyone without the knowledge of Java and Xml to write an application from scratch. For this reason we used the Bluetooth Chat sample code provided in the Android SDK package as a starting point for this project.

Application GUI

Start app development by changing the main.xml file to add buttons as seen in the layout in figure(10) , add the corresponding stings in the string.xml file. This project uses the buttons to send a particular character when clicked. To do this change the BluetoothChat.java file as follows by adding the following lines of code in the setupChat() function.


● The first screen for application is for home station selection

Fig 6. First Screen

As you can see in the screen shot, there are three buttons to select among three home stations. Upon selecting a weather station (denoted by “roomX”, X => 1, 2, and 3), the application establishes a connection to the Bluetooth agent in the weather station. Once connection is established, the status is shown to the user as “connection established” or “connection failed”

● Screen for requesting statistics

Fig 7. Select parameter

Add a new activity to the project, Activity_main. The IDE creates a corresponding xml file automatically. Create the layout as shown in figure(7),add the corresponding stings in the string.xml file. Copy and paste the Bluetooth enabling code from BluetoothChat.jave to Activity_main.java and add the functionality for the buttons as follows. For this project we have hardcoded the MAC address of the Bluetooth modules, the address is passed to the BluetoothChat activity. Add the following lines of code in Activity_main.java.

There are 4 different buttons viz,

Temperature Now (Read the current temperature) History (Historical temperature data and graphs)
Light Now (Read the current luminosity) History (Historical luminosity data and graphs)


● Graphing method


Our graphics are primarily based on the library “androidplot” downloadable from (www.androidplot.com)
AndroidPlot is a very powerful package to plot graphs. The input for graphing method are two arrays of type Number. To plot an XY graph, these numbers are converted to XY-Series data type and use a LineandPointFormatter class. Once X-axis plane is fully plotted, another series will be used to plot Y- axis plane.
Fig 8. XYplotcode

FreeRTOS Application configuration

In main.c, we have instantiated two variables (one for Temperature and another for Luminosity) of type data_buffer with a buffer size 100 entries. We setup a thread to read the sensors at periodic intervals and fill into the corresponding buffers. By virtue of our data structure, maximum space allocated for readings are bound at the init time.

Data Analysis

The gather_tmplight() thread wakes up at intervals and fills in the data into the buffer. The Android app can query any device either for a. Last wrote data, or b. Complete history (upto 100 entries).

Data structures

Fig 10. Data structures

Every board gathers temperature and Luminosity samples at fixed intervals. The interval is configurable and default is set at 5sec. Initially, our first choice was to use a FIFO for storing these readings. But then, it became very difficult to discard older entries. Although we planned to have a timeout mechanism associated with every entry, later we figured out that a FIFO implementation based on a circular buffer would be easier to implement and maintain. Here is a graphical representation of our FIFO based on a circular buffer.

Fig 9. Circular buffer


Communication protocol

The transaction is carried out using the following protocol:

S.NO. Message type Description
1 Query last wrote data – temperature The application will write the character 'A' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'A'. It calls the stringify_data() method of the temperature buffer for last read data which is printed out with the set delimiter (default : $)
2 Query last wrote data – Luminosity The application will write the character 'C' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'C'. It calls the stringify_data() method of the luminosity buffer for last read data which is printed out with the set delimiter (default : $)
3 Query historical data – temperature The application will write the character 'B' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'B'. It calls the stringify_data() method of the luminosity buffer for all data in the history buffer. Resulting string, a $ delimited character array of all readings will be written to the uart. The application will read this array and convert them to numbers and input to the graphing function.
4 Query historical data – Luminosity The application will write the character 'D' to the Bluetooth agent. The device's uart read/write thread wakes up and reads the input character 'D'. It calls the stringify_data() method of the luminosity buffer for all data in the history buffer. Resulting string, a $ delimited character array of all readings will be written to the uart. The application will read this array and convert them to numbers and input to the graphing function
5 Any other query Result in a single string “-01:-02”

Implementation

The sample code is downloaded using the Android SDK Manager. From the navigation menu of the IDE go to Windows -> Android SDK Manager. All the installed and available SDK packages are listed; attention should be paid to the version of SDK platform. It should be the same as the Android version of your device. This project is developed using Android 4.2.2.(kitkat), API level 19. After this sample code can be found in the folder sdk->samples->android-19->legacy on the host machine. Import the Bluetooth Chat sample in to the project workspace.

Fig 12. BluetoothChatService

Next step is to establish communication with the LPC1758 using Bluetooth Chat sample application. Bluetooth sample is not a functioning application; this tutorial (http://www.instructables.com/id/Android-talks-to-Arduino/?ALLSTEPS) provided the solution to the problem. It said to change the UUID in BluetoothChatService.java file to “00001101-0000-1000-8000-00805F9B34FB”

Fig 11. Setupchat

Once the change is made this application is able to communicate with LPC1758. In this project android application is composed of three activities: BluetoothChat.java, Avtivity_main.java and SampleXYPlotActivity.java.

  • Develop start screen

Start app development by changing the main.xml file to add buttons as seen in the layout in (fig.6) , add the corresponding stings in the string.xml file. This project uses the buttons to send a particular character when clicked. Modify the DeviceListActivity.java as follows to connect to the intended device automatically.

Fig 13. start screen creation

Testing & Technical Challenges

Testing

Install the app BlueTerm on your android device. This app is a terminal emulator, and uses RFCOMM/SPP protocol for serial communication over Bluetooth. It is used to establish connection between LPC1758 and android device. The JY-MCU Bluetooth module appears as linvor in the available device list. Once the connection is established send a character from LPC1758 using Hercules, you should now be able to see the character appear on the terminal. Now send a character from the android device and it should appear on the Hercules terminal. This verifies the communication between LPC1258 and android device.

Challenges

Data structures implementation: Initially we toyed with the idea of every reading will be stored with a timeout value. But soon it became apparent that it is not a scalable solution. So, we searched for an alternative and finally came up with a Circular Buffer based FIFO. Initially we tried storing both temperature and luminosity in the same data structure. But later it became so cumbersome that we decided to simplify code using two separate instances of the same data structure. Graph plotting was considered difficult till we came across Androidplot libraries.

Difficulty with testing: The state machine designed was to wait till a suitable input. In order to simplify testing, we implemented a command (to be input from the prompt) using a terminal task. Thus, by connecting uart2 to uart3 we could independently verify the functionality of the device – by reading the temperature value and history as well as Luminosity value and history.

Conclusion

In conclusion the goal of the project was to make an android based home monitoring system that communicates via Bluetooth. The goal was successfully accomplished as all of the requirements set for the project were met. The team faced and overcame many challenges including but not limited to designing data management and transfer protocol, establishing communication between android device and LPC1758. These challenges were resolved through intensive research and testing. Through this project the team gained much valued knowledge and hands-on experience in developing applications for android and Free RTOS. Our group worked well together, new relationships were built. It was a challenging project due to the fact that all of the team was learning to do something new, but with hardwork and dedication of all team members, the project was successful. For future, more monitoring fucntions can be added; like alerts when environment changes quickly

Project Video

Upload a video of your project and post the link here.

Project Source Code

References

1. Android development: http://developer.android.com/training/index.html
2. User manual for SJOne development board
3. Graph generation: http://androidplot.com/docs/quickstart/

Acknowledgement

Preet Kang


Appendix

You can list the references you used.