Home Monitoring System
.
Goal
Provide a Home Monitoring System that monitors temperature to detect if it is out of range and also detects motion of the mbed application board. It stores alerts locally until a host is connected via a USB Serial connection where the host is running the host-side application. Once connected to the host application it allows the host to control the alert generation, retrieve historical information and provide full control over the device.
Detail
mbed application board sensors used to monitor temperature and compare to a threshold. mbed application board motion sensors used to detect motion of the application board. When temperature is out of range or motion is detected an LED is lit and an alert generated. If the device is connected to the host running the host application it will alert the host otherwise it stores the alerts. The host side application can control these features of the mbed application board:
- Set and Get Temperature Thresholds
- Set and Get Motion Sensitivity (vector of x, y, and z)
- Set and Get Temperature sampling period (determine how often historical temperature reading taken)
- Set and Get buffer depth for historical motion and temperature information
- Retrieve historical motion and temperature information from the board
Protocol
The communication between the device and host is a simple one character based protocol. The device sends alerts, acknowledgments, and data to the host. Each command or request is acknowledged by the host or device depending on the direction of the command. All data that is passed is a fixed 7 bits wide and is padded with spaces if required. This allows communication without parsing of data.
Some example transfers:
Connection
- Host sends 'c' for connect
- Device sends 'k' for acknowledge
Motion Alert
- Device sends 'a' for alert
- Host sends 'k' for acknowledge
- Device sends 'm' indicating motion alert ('l' for low temp, 'h' for high temp)
- Host sends 'k' for acknowledge
Data Transfer (Get temperature history from Host)
- Host sends single character command to fetch temperature history
- Device sends a 'k' for acknowledge
- Device sends 7 character integer N (padded with spaces) to indicate length of transfer
- Device sends N 7 character doubles for temperature history
Project Hardware
- mbed LPC1768 CPU board
- mbed DEV-11695 application board
- Host PC running HomeMonitorApp (Windows Console App, code on this page)
- Two USB Cables (normal mbed connection and USB Serial Device connection to host PC)
Project Software
- mbed Libraries - LM75B, MMA7660, C12832_lcd, USBDevice (USB Serial Device mode)
- Windows Console Application (base written by instructor Avnish Aggarwal, heavily modified by me) for serial communication
- Other code and classes referenced here
MBED Output
- LED0 - Device correctly connected to host application
- LED1 - Motion alert (cleared only when host has received alert)
- LED2 - Temperature High Alert (cleared when host receives alert)
- LED3 - Temperature Low Alert (cleared when host receives alert)
- LCD Screen - some helpful debug messages, alert generation, connected status, etc.
Host Application
Pretty lame user interface for now. Just allows user to enter commands to control device parameters. When alerts are received they are displayed to the application window. When data is received from the device it is dumped to the window. A GUI, file saving features, etc. would have been nice but ran out of time.
The code listing for the host side application is here. It was done with Visual Studio Express 2010 as a Console Application. When launched it expects the COM port for the serial connection in use and the baud rate. For example if the serial port is COM6 and the baud rate is 9,600 the command line should be:
HostMonApp.exe 6 9600
Host-Side Application Files: /media/uploads/groletter/parseresults.cpp /media/uploads/groletter/hosthomemonapp.cpp
Errata
- Under heavy alerts traffic there are protocol errors (still debugging) when trying to send commands at the same time an alert arrives
- Code could be cleaned up a bit and multiple threads on host and device would be nice (ran out of time)
Weak Video
I was down to the 11th hour, so not a lot of time to make a pretty video. It doesn't show much but gives some idea of the project.
The mbed code
Import programFinalProject
This is my final project for UCSC Extension - USB Programming. It is a home monitoring program for motion and temperature and requires host-side code.
1 comment on Home Monitoring System:
Please log in to post comments.
There were some bugs in my original host application code that confused the protocol I created. It should all be working now. The interface is still pretty crude. Since the class is done though I doubt I'll be making it pretty unless I get motivated to turn it into an Android app which was my original goal.....