Arduino Yun: Light Control

This is a proof of concept for setting up the newly released arduino Yun as light controller. A web server was setup on arduino Yun with support of MySQL and PHP. Light status is controlled with MySQL queries and even when a button is pressed triggers an SQL query, this is the advantage  of Arduino Yun’s Bridge, you can interact between the ATmega 32U4 (Arduino side) and the Linino AR9331(Linux side). Below are some pictures of the setup and also a demo video.

DSC_0053 DSC_0055 home_automation_bb 

Before proceeding with the setup I have to mention that at the moment I bypassed the security aspect of this project.

Use it at your own risk. If this is going to be in public you are exposed and vulnerable in attacks.

Setup of the Linino (Linux) side of arduino:

Download all necessary files from the below link:

https://www.dropbox.com/s/2b8edx2nmomto49/light_control.rar

  • Install LAMP stack following the below website:

http://wiki.openwrt.org/doc/howto/lamp

  • Download the below file and put then in the desired folder of the webserver running on Arduino (skip downloading if you already downloaded the files from the first step):

Web Interface

I created the homeautomation database and the LEDstatus and webstatus tables as below :

LEDstatus table:

 Field  Type  Null  Key  Default  Extra
 id  int(2)  NO  PRI  NULL  auto_increment
 name  varchar(15)  YES  NULL
 LEDstatus  varchar(5)  YES  NULL
 pin  int(2)  YES  NULL
 pinOut  int(2)  YES  NULL

..and added two entries in the LEDstatus table:

 id  name  LEDstatus  pin  pinOut
1  LED1 -1 2 8
2  LED2 -1 3 9
    webstatus table:
 Field  Type  Null  Key  Default  Extra
 status  int(1)  YES  NULL
  • Create some bash scripts for different mysql queries and place them in the root folder  (skip downloading if you already downloaded the files from the first step) :

Scripts

  • Download the arduino sketch  (skip downloading if you already downloaded the files from the first step):

Arduino sketch

Many thanks to the below:

http://arduino.cc/en/Tutorial/Switch

http://wiki.openwrt.org/doc/howto/lamp

DLink DNS-320 NAS as an Always-On BitTorrent Box

This post is a tutorial on how to setup a DLink DNS-320 NAS as an always on BitTorrent box.

Steps to achieve that are:

  1. Install fun_plug0.7 on the NAS
  2. Install Debian on the NAS.
  3. Install and configure Deluge BitTorrent Client on the NAS.
  4. Fine tune of Debian installation.

1.  Install fun_plug0.7 on the NAS

Follow one of the bellow link to install fun_plug on NAS:

2. Install Debian on the NAS.

Follow link bellow to install Debian Squeeze on NAS

3.  Install and configure Deluge BitTorrent Client on the NAS.

For the installation and configuration of Deluge BitTorrent client I used the bellow article. Feel free and use that for a detailed reference.

Install Deluge BitTorrent client on a Debian based machine

I’m going to write down the commands I have used to achieve this:

  • As usual before the installation update your repositories:

apt-get update

  • Installing the necessary components:

apt-get install deluged deluge-console python-mako deluge-web

  • The we have to run for first time the Deluge daemon:

deluged

pkill deluged

  • Create a new user that will be used to run deluged

adduser nas_torrent

In my tutorial consider the below credentials:

username: nas_torrent

password: Torrent1!

  • Backup the original configuration

cp ~/.config/deluge/auth ~/.config/deluge/auth.old

  •  Open the original configuration file with your favourite editor

vim ~/.config/deluge/auth

Put the below line to the bottom :

nas_torrent:Torrent1!:10

Basicaly the format is as follows:

<username>:<password>:<access level>

  • Start the deluge daemon

deluged
deluge-console

If all went ok you will have something similar as below on your screen:

2013-03-24_163942

  • Put the below  commands while you are in deluge console:

config -s allow_remote True
config allow_remote
exit

  • Restart the daemon to apply the settings:

sudo pkill deluged
deluged

  • Install and launch deluge client

Disable the Classic Mode option:

2013-03-24_173041

  • Apply the changes and restart the client after that you will prompted to add host.
  • Complete the fields according to your setup. Username and password are the same as the user we created in the begining

add_new_host

  • After adding the host the connection manager will appear with one entry. Select your connection and press connect.

Now you have your desktop ThinClient connected to the deluge BitTorrent client running on your NAS.

Also you can access the Web UI of the deluge client by visiting the bellow link:

http:// < your_nas_ip > : 8112

But first we have to do some fine tuning to our setup

4. Fine tune of Debian installation.

We have to create two cron jobs that will run every minute to check the status of deluged and deluge-web services to be sure that our client will be always in running state.

Access your NAS via ssh connection.

First we have to create two scripts for deluged and deluge-web services.

  • Use your favourite editor and:

1. Deluge.sh script

vim deluged.sh

   Put the below in the script:

#!/bin/bash

# Check if gedit is running
if ps aux | grep “deluged” > /dev/null
then
#echo “deluged is running”
deluged
else
#deluged
echo “deluged is running”
fi

2. Deluge-web.sh script

vim deluged-web.sh

  Put the below in the script:

#!/bin/bash

# Check if gedit is running

if ps aux | grep “deluge-web” > /dev/null
then
#echo “deluge-web is running”
deluge-web
else
#deluge-web
echo “deluge-web is running”

fi

  • Open the crontab file:

crontab -e

And enter the below lines:

*/1 * * * * sh /root/deluged.sh
*/1 * * * * sh /root/deluged-web.sh

  • Save the configuration and restart your NAS.

Now setup and configuration is complete.

Also you can access your setup via Transdroid android application to access your Deluge client.

You have an Always-On BitTorrent Box accessible from all over the world.

Happy downloading ( and seeding 🙂 ).

Using a raspberry pi for remote-WiFi console access

2013-01-01 23.19.20

Bill of materials:

1 x Raspberry Pi model B rev2 (The latest version with 512 MB RAM, this version doesn’t have any issues with usb wifi dongles)

1 x USB to serial adapter

1 x usb wifi dongle

How-to:

1.  Download and install the latest raspbian image from official raspberry pi website http://www.raspberrypi.org/downloads

2.  Finish the initial configuration

3.  Update repositories for available packages

  • sudo apt-get update

4.  Install minicom

  • apt-get install minicom

5.  Configure minicom

First we have to locate the proper serial device

  • find /dev | grep ttyUSB

Note down the result and proceed with minicom configuration

  • minicom –s -> Serial port setup
  • Change setting A – Serial Device

/dev/modem to /dev/ttyUSB0

(in place of ttyUSB0 enter the device listed from  find /dev | grep ttyUSB)

  • Change setting  E – Bps/Par/Bits

Most common bitrate is 9600

  • When done save configuration

6.  Next we have to setup wireless connection

  • The easy way is to open the window manager with startx command and then open the wpa_gui tool.
  • The hard to way is to edit the wpa_supplicant.conf file

vim /etc/wpa_supplicant.conf

  • Use the below link as reference:

7.  Access raspberry pi with your favourite ssh client

wpa_supplicant

Tips:

  1. A good practice is to always change the default root and pi user passwords to avoid any security issues.
  2. Insert minicom inthe  last line of ~/.bashrc to have minicom running on startup.
  3. Add a static IP to raspberry pi to be easier to access it.

 

Installing owncloud on DNS-320 NAS

This post is a tutorial on how to install owncloud on a DLink DNS-320 NAS.

Is tested on DNS-320 NAS but basically applies to any device that supports implementation of fun_plug.

Steps to achieve that are:

  1. Install fun_plug0.5 or fun_plug0.7 on the NAS
  2. Install Debian on the NAS.
  3. Install owncloud on the NAS.
  4. Configure webserver to change webserver’s listening port. This helps in case you want to do port forwarding since many ISP’s have port 80 blocked.

1. Install fun_plug0.5 or fun_plug0.7 on the NAS

Follow one of the bellow links to install fun_plug on NAS:

2. Install Debian on the NAS

Follow link bellow to install Debian Squeeze on NAS

3. Install owncloud on the NAS.

Follow link bellow to install owncloud on  NAS. Avoid any errors ate the moment.

4. Configure webserver to change webserver’s listening port.

Last thing to do is to configure webserver to listen to different port as the NAS by itself has a build in webserver.

Im using vim to edit configuration files.

1. Get root access to NAS.

2. Edit the ports.conf file

  • vim /etc/apache2/ports.conf
  • Change the bellow entries (8888 is the new port number)

NameVirtualHost *:8888

Listen 8888

3. Edit the 000-default file

  • vim /etc/apache2/sites-enabled/000-default
  • Change the below entry

<VirtualHost *:8888>

4. Restart apache webserver

  • service apache2 restart

5. Visit owncloud your from fav browser http :// < your_ip > :8888/owncloud