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

From Embedded Systems Learning Academy
Jump to: navigation, search
(Quadcopter)
(Project Source Code)
 
(61 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==
  
 
== Abstract ==
 
== Abstract ==
Our team aims to build a Quadcopter (Quad-rotor helicopter), which is a multi-rotor aerial vehicle that is lifted and propelled by four rotors. The thrust generated by the propellers lifts the Quadcopter while the flight controller system govern the rotor speed for attitude control. A wireless remote control is used to interact with the flight controller system for changing the flight path. Our objective would be todesign and build a flight controller system that stabilizes the flight and accept commands from a hobbyist remote control during its flight.
+
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.
  
== Objectives & Introduction ==
+
Features
The scope of our project can be divided into three parts:
+
#  Light and temperature monitoring of multiple rooms
* Design and build interfaces to all the on-board electronic sensor such as IMU, barometer and distance sensors  
+
# Android application to view status of sensors
*  Design and build interfaces to telemetry and radio modules to communicate with remote control and the computer
 
*  Process the various sensor inputs and control the brushless motors on board using an electronic speed control system to stabilize the aircraft
 
  
=== Team Members & Responsibilities ===
+
== Team Members ==
Sree Harsha
+
Om Narasimhan
#*  Driver Development
+
#*  FreeRTOS application design-protocol implementation
Balaji
+
Aysha Malik
#*  Sensor Data Processing
+
#*  Android application development
Divya Kamath
+
Sri Latha Ayyannagari
#*  PWM Design
+
#*  FreeRTOS device driver and data structures implementation
  
 
== Schedule ==
 
== Schedule ==
Line 44: Line 30:
 
| 2/28
 
| 2/28
 
| Order Components and Make a schedule
 
| Order Components and Make a schedule
| Component Ordering Partially Completed (critical components done)  
+
| Completed)  
 
|-
 
|-
 
! scope="row"| 2
 
! scope="row"| 2
 
| 3/1
 
| 3/1
| 3/
+
| 3/10
 
| Components Procurement.  
 
| Components Procurement.  
|  
+
| Completed (03/06/2014)
 
|-
 
|-
 
! scope="row"| 3
 
! scope="row"| 3
| 2/20
+
| 3/6
| 3/15
+
| 3/6
| Establish communication with all sensors and validate data
+
| Identify tasks assign work
| IMU done. Left with the rest
+
| Completed (03/06/2014)
 
|-
 
|-
 
! scope="row"| 4
 
! scope="row"| 4
| 2/28
+
| 3/6
| 3/5
+
| 3/13
| Establish communication with radio module of remote control
+
| Study about bluetooth module and its interfacing
| Learning PPM and PWM
+
| Completed
 
|-
 
|-
 
! scope="row"| 5
 
! scope="row"| 5
| 2/28
+
| 3/6
| 3/5
+
| 3/13
| Speed control of motors
+
| Learn application development using Android,  Complete hardware interfaces
| Learning PPM and PWM
+
| Completed
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
| 2/28
+
| 3/13
| 3/25
+
| 3/18
| Flight Controller Algorithm (PID Controller)
+
| Finish software design and conduct reviews
| Learning
+
| Completed
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
| 3/15
+
| 3/18
| 3/30
+
| 4/8
| Create tasks and integrate complete code
+
|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
 
|-
 
|-
! scope="row"| 8
+
! scope = "row"| 8
| 3/
+
|4/8
| 3/
+
|4/18
| Assemble quadcopter
+
|working on developing data transfer protocol and communicating with multiple devices at the same time
|  
+
|Completed
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
| 4/1
+
| 4/18
| 4/1
+
| 4/25
| Initial testing and tweaks
+
| Integrate code and start testing
|  
+
| Completed
 
|-
 
|-
 
! scope="row"| 10
 
! scope="row"| 10
| 4/15
+
| 4/25
| 4/
+
| 4/30
 +
| Resolve issues if any
 +
| Completed
 +
|-
 +
! scope="row"| 10
 +
| 4/30
 +
| 5/3
 
| Final Testing
 
| Final Testing
|  
+
| Completed
 
|}
 
|}
  
Line 110: Line 102:
 
! width="60" align="center"|Total Cost
 
! width="60" align="center"|Total Cost
 
|-
 
|-
| align="center"|4||4x Electric Speed Controller (ESC)||Turnigy||Plush 25||align="right"|$50.00  
+
| align="center"|3||SJOne Board||SJSU||align="center"|-||align="right"|$240.00  
 
|-
 
|-
| align="center"|4||Park 480 Brushless Outrunner 1020kV motor||E-Flight||EFLM1505||align="right"|$180.00
+
| align="center"|3||2013 Bluetooth Master UART Board Communication Module- 4 Needle Blue|| || ||align="right"|$22.50
 
|-
 
|-
| align="center"|1||Inertial measurement unit (IMU) MPU-9150||Sparkfun||SEN-11486 ||align="right"|$40.00
+
| align="center"|1||Samsung Galaxy S4||Samsung ||align="center"|-||align="right"|
 
|-
 
|-
| align="center"|1||SJOne Board||SJSU||align="center"|-||align="right"|$80.00
+
| ||'''Total Cost'''|| || ||align="right"|''' 262.50'''
|-
 
| align="center"|1||DX6i 6 Channel 2.4Ghz Tx/Rx Remote Control||Spektrum||DX6i||align="right"|$140.00
 
|-
 
| align="center"|1||2500mAH 5C 3S Lipo battery||Zippy||align="center"|-||align="right"|$15.97
 
|-
 
| align="center"|1||Quadcopter frame ||HJ MWC||align="center"|-||align="right"|$21.26
 
|-
 
| ||'''Total Cost'''|| || ||align="right"|'''increasing !'''
 
 
|-
 
|-
 
|}
 
|}
  
 
== 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 ===
The MPU-9150 consists of a 3-axis accelerometer, 3axis Gyroscope and a 3 axis magnetometer. its a one chip IMU solution with onboard Motion processor for sensor fusion.Though it inherently supports on board Sensor Fusion, the IP is undisclosed. Therefore we used the library for arduino by Pansenti. (https://github.com/Pansenti)
+
[[File:CmpE244 S14 AHMS Android Software.jpg|300px|thumb|right|Fig 3. Android application flowchart]]
The 6 axis sensor fusion (accel+gyro) is done on the MPU and sent to an arduino where the magnetometer data is used for YAW correction.  
+
 
The arduino transmits the orientation data over UART which is recieved by the SJONE for further processing.
+
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.
 +
[[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'''
  
For testing, we coded a GUI in python. The code parses the serial data from the arduino and displays the orientation of the IMU in real-time using Vpython.(video and code to be linked).
+
[[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.  
  
=== Implementation ===
+
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.
This section includes implementation, but again, not the details, just the high level. For 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.
+
 
 +
'''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.
 +
 
 +
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.
 +
[[File:CmpE244 S14 AHMS XYplotcode.jpg|400px|thumb|center|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'''
 +
 
 +
[[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 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.
 +
 
 +
[[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 163: 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 ===
 
# https://github.com/Pansenti
 
# https://code.google.com/p/sf9domahrs/
 
# http://www.rcgroups.com/forums/showthread.php?t=1284741
 
# http://blog.oscarliang.net/quadcopter-pid-explained-tuning/
 
  
 
=== 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.