Wednesday, 19 March 2014

Firebase

firebase_logo.png
For our main storage we decided to use a relatively new data storage technology called Firebase. Firebase removed the need for us to use any Server side coding (php Asp.net etc) or database quering (SQl Server, MYSQL). Instead Firebase would transfer it data using JSON. This allows us to extract the data using Javascript and jQuery on the client side and with Python on the Pi. We decided to use Firebase because it saved us the niggly process that is involved in constantly switching back and forth between programming languages. Firebase would act as meeting point for the Server and Client and would eliminate any direct interaction between both. Firebase is also realtime so when a new value is received from the server it is automatically updated on the client end.  

Firebase has very comprehensive API for a wide range of technologies which can be found on the Firebase website.

Monday, 10 February 2014


Receiving a temperature reading.

The Sketch

To receive temperature data we created a simple sketch that reads the data from a DHT11 temp/humidity sensor that is connected on digital pin 2 of the Uno. The sketch imports a DHT library which allows for easy connectivity with the sensor. The values that are read from the sensor are then printed to the serial port so they can be read by the Raspberry Pi.

#include "DHT.h"//import library

#define DHTPIN 2 //sets pin for dht sensor
#define DHTTYPE DHT11 //sets type
DHT dht(DHTPIN, DHTTYPE);

int led_1 = 13; //pin for 1 LED

//int incomingByte = 0; //variable to hold incoming Serial data
void setup() {
   // initialize the digital pin as an output:
   pinMode(led_1, OUTPUT);    
   
   digitalWrite(led_1, HIGH); //turn on #1 indicator LED   
   digitalWrite(led_1, LOW); //turn off #1 LED

   dht.begin();//begin dht sensor
   Serial.begin(9600); //set baud rate for serial
    
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
    

    float h = dht.readHumidity();
    float t = dht.readTemperature();

    if (isnan(t) || isnan(h)) 
    {
      Serial.println("Failed to read from DHT");
    }

    else 
    {  
      Serial.print(h);
      Serial.print(",");
      Serial.print(t);    
      delay(2000);
    }
  
    if(t > 23)
    {
       digitalWrite(led_1, HIGH); // set the LED on
       delay(500); // wait for a second
    }
    else
    {
     digitalWrite(led_1, LOW); // set the LED on
     delay(500); // wait for a second
    }
    
} 


In the above example there is an led on pin 13 that is set to turn on once the temperature goes above 23 degrees.

Installing and configuring the OS

Raspbian OS

The first step was to install the operating system on the Pi. This was easy do and once installed the SSH could be configured to allow for remote access to the Raspberry Pi's command line from any computer on the network. 

SSH

To gain SSH access the Pi had to be set with a static IP address so that it could be logged onto using PuTTY on Windows 7. This was done using the nano text editor in LXTerminal e.g "nano /etc/network/interfaces" 

Once the SSH was set up we could now start installing some software and writing some scripts. Since Python is the Raspberry Pi's native language it made the most sense to use this, along with the fact that it is a brilliant language to code in. What we needed to do however was connect to the Arduino's serial port and start reading in some data. 

Python and PySerial

Python scripts can be ran in the terminal by using "python" and then writing your script into the compiler. You can also run scripts that have been saved with the .py extension so if you create a script using "nano script_name.py" you will be then be able to type "python script_name.py" and it will run the script. Scripts can be set to auto run which gives us the capability to create whole automation scripts that could potentially control many devices according to the temperatures read, for example opening the windows when warm or setting the thermostat when too hot or too cold.

It's easy install libraries and other software in the terminal and once installed in can be imported into any python script.

Just include serial in your python script now and you will have full access to the serial port and you can finally start reading and sending data over the serial port.

LAMP Server - Linux, Apache, MySql and PHP

After installing Apache, MySql and PHP on your machine you will gain the ability to serve up web pages to the local network which can be accessed by the IP Address you assigned earlier e.g "192.168.1.51". With PHPMyAdmin you can gain access, with a little configuring, to "192.168.1.51/phpmyadmin" which will allow you to run MySql code in your database. 

PHP scripts can be used then to make a connection to the database and display it on the site for the user to view. It can also send values over the site which can run scripts to update databases to add new sensors or send states to devices such as lights or electrical devices e.g immersions etc. 

When an Arduino is connected to the Pi, the Pi can run a python script to read values from the Arduino's sensors and then store them in the MySql database or on the Pi's local disk. The PHP files on the site can then update the site with the new data as well as send back commands to the Raspberry Pi which can control different devices on it's own GPIO pins or send commands towards the Arduino to control devices connected to that. 

Speeding Up the Pi

Since the Pi is only accessed over SSH and the GUI doesn't need to be given much memory, the memory that had been allocated to the GUI was reset to give more to the hardware and I also overclocked the Pi to a safe enough level. Since the Pi is going to be dealing with so much requests it may be a good option to create an image of the OS on a usb stick or hard drive and point towards that image on a boot file on the SD card which you would normally install the OS on. This is because there is a limited amount of read/writes on an sd card and since there will be so much data being updated and stored on the SD card over time, we want to ensure that none of it gets corrupted or lost. A Raspberry Pi if it's configured properly can serve up website that are in the top 30% fastest loading times in the world of the internet. 

Next thing to do is write to the Arduino to start control some device states and turn on some leds.

-Conor

Sunday, 9 February 2014


Home Automation with a Raspberry Pi and an Arduino.

The Hardware:

Using an Arduino Uno and a few cheap sensors we can receive data about the environment around them, giving you a visual representation of your home's
readings. The Arduino can also receive commands to control any relays or other outputs connected to the microcontroller, letting you gain control of your lighting and other electrical systems all on the one device.

The Arduino is limited in it's capabilities and it depended on another machine to do some of the processing. To combat this we have the Raspberry Pi acting as a server for the Arduino which connects to it over a usb-serial interface. This gives the system much more computing power and allows for much more functionality and mobility for the Raspberry Pi as it only requires a power supply and a network connection to run once the system has been fitted in the home. 

The Software:


The Arduino loops a C program which collects all the data from the sensors as well as sends commands to the output pins on the Arduino. This data is sent over the serial port while also reading the incoming bytes sent from the Raspberry Pi.

The Raspberry Pi runs the Raspbian Wheezy distro which boots straight into the command line with SSH access enabled to allow remote access over the local network using PuTTY. The Raspberry Pi runs as both a client and a server so the majority of the work is happening here. 

To connect with the Arduino, the Pi uses Python scripts which import the PySerial library among others to process,send and receive data over the serial connection.

A LAMP web server is served up by the Pi which gives the user a nicely designed web application that displays data from the MySql database as well as providing the user with controls to send and receive data throughout the system.

The Goal:

Create a system that is low-cost, but highly functional.

One that works, and works well.

Something that completes complex tasks with a simple design.

Make it ultra plug and play and easy to retro-fit into existing buildings.

-Conor

Sunday, 5 January 2014

Plans.. So Many Plans...

Here what we hope to achieve with the project

Home Automation
1.       Lighting switches on and off automatically. Lights can be turned off and on remotely.
Lighting programs can also be made to switch lights on and off at certain times, or in certain living conditions such as when you’re watching a movie. More extensions on this can be halfway lights turning off automatically when motion is detected, stairway lighting turning on when a step is taken. Mood lighting programs for parties may also be an option taken.

2.       The house can let you know how it is.
The system can monitor conditions from the home which can be viewed from a remote location. Temperature and weather information can be viewed on the app or online.  Alarm systems could also be incorporated with window/door sensors which could alert the user if the windows are left open or if there’s a break-in. Cameras could take photos or videos of visitors that come to your door or ring the doorbell. Humidity/Moisture sensors could be incorporated to detect flooding and humidity levels in a home which can then be viewed through the app.

3.       Intelligent climate control.
Heating and air conditioning can be adjusted remotely or in relation to outdoor/indoor temperatures. Windows can be programmed to open when inside temperatures are high and close when it rains.

4.       Security.
With a 360 degree PTZ IP camera and the app to view it a user can survey areas of the house with high importance such as a garage where the car may be stored. With RFID chips and receivers, keyless entry can be accomplished so when the user comes in close proximity with an entry door it will automatically be unlocked. Unlocked doors or open windows can also be locked and closed remotely.

5.       Media System.
With the OpenElec system ran on the Raspberry Pi the system can extend as far as having full control of your TV, Internet, Music, Video and all on the app. This could then be played on different mediums throughout the housing.

6.       Voice Integration.
The app will take advantage of the voice control to send commands to the system for pre-programmed controls. Commands from “Turn On TV” to “Turn Off Lights” can be incorporated. Voice feedback is also a feature that can be achieved.

7.       Feedback such as the weather conditions or even repeating your commands could be given back through the app much like apples SIRI.



8.       Open-Source.
The whole system is based on open-source hardware and software. Thanks to the nature of open-source along with the many members of the open-source community, the system can be extended to work with many other systems and components if needed.

9.       Remote Access.
The system will upload to a domain so any machine with internet access can be used to control the house. The mobile app is essentially an app that points to this domain while offering the user the incorporated controls to use all of the features in the system. This gives the user the potential to control their entire home from anywhere in the world.

10.   Cost Saving.
The beauty of having so much control at the push of a button is that you can see each light and power supply that is using power. This makes for much more efficient use of electricity and with the use of sensors and times; this can be a huge saving.
11.   Smoke/Toxin Detector.

An extension of the system which would appeal to the safety aspect of a home is a smoke detector alongside a carbon monoxide detector. CO is a killer gas and a system that will detect and warn of any high levels of this gas and potentially save lives. Smoke is not often as fatal but has the potential to set off alarms to warn occupants of fire danger. This could also be used as a real time alert for emergency services to be called if the home owner is away. Another more domestic use for smoke detection could be to turn on extractor fans when cooking.


Thursday, 3 October 2013

Team Members

Who are the members Of Team Synergy you Might Ask? Well Allow us to introduce ourselfs:

Seán  Caine:
Role: Web and Design
-From the democratic republic of Curry South

-Self Proclaimed face of the project

-Qualified Ceramic Technician

-One day wants to star in Home and Away


Tommie Corrigan
Role: Testing and Cloud
-Standard Cavan Man

- Believes a  Robert Lewandowski picture should be placed in every home beside   a picture of Jesus

-Astro Turf soccer Legend

-Claims to be the Poker and FIFA 14 King of Yeats Heights (Yet to be Confirmed)


Conor  Horan
Role: Hardware
-Winner of "Best Honda Civic in Claremorris" 3 years in a row

-The finest winger Ballyhaunis rugby has ever seen

-Runs his own Computer/Phone repair business "Horan fix this will ya!?"

-One of the few Mayo men who didnt utter the words "Mayo For Sam"




Paul  Kenny
Role: Mobile
-Legans own son

-If you could sum up rural Longford in 1 man, This is him

-Legan Sarsfields Top Junior B Full Forward

-Hope to one day grow a beard like Seáns











Monday, 30 September 2013

Here We Go!

Well here we go again. Back for Year 3 here in IT Sligo, where has time gone? Seems like only yesterday and I was learning Bismark and Parnell for the History exam and was on the cusp of making the Senior football team..... alas 2 years of Learning C# JavaScript among others and 2 banjaxed knees has left all that to fall by the wayside. Anyway more important things happening these days anyway. 
This year as our module PRJ300 requires to to undertake a project to try and do something innovative using the coding skills we have developed over the last 2 years. This year our team is going to build a home automation system i.e turn off lights using a Android app. What exact features the app will have are under discussion but we have so innovative ideas in the works. Who is our team you might ask? You'l find out in our next post. - Paul