Wednesday, October 17, 2012

iOS - Showing/Hiding MPMoviePlayerController Controls

This question seems to be all over stack overflow and iphone dev sdk forums with no real answer....So how does one show and hide the controls of the MPMoviePlayerController programmatically? Here you go...
 - (void)showControls  
 {  
   for(id views in [[player view] subviews]){  
     for(id subViews in [views subviews]){  
       for (id controlView in [subViews subviews]){  
         if ( [controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")] ) {  
           [controlView setAlpha:1.0];  
           [controlView setHidden:NO];  
         }  
       }  
     }  
   }  
 }  
 - (void)hideControls  
 {  
   for(id views in [[player view] subviews]){  
     for(id subViews in [views subviews]){  
       for (id controlView in [subViews subviews]){  
         if ( [controlView isKindOfClass:NSClassFromString(@"MPInlineVideoOverlay")] ) {  
           [controlView setAlpha:0.0];  
           [controlView setHidden:YES];  
         }  
       }  
     }  
   }  
 }  




Thursday, January 27, 2011

The Predictor: College Football

The Predictor: College Football Edition brought to you by Dean's Sports.




With this application you can input statistics from the official college football website and the app will give you the predicted team scores, the favorite, and the total game points.

The formula used in this application has been in use for over a decade and has a fairly good track record.

2010-2011:
Team Points 45%, Total Points 75%

Data from previous years is coming...

The screen shots are from the Orange Bowl on Jan 3, 2011. Virginia Tech vs. Stanford. The Predictor said Stanford would win by 12. The odds-makers set the line as Stanford a 3.5 point favorite. Good value in the line for Stanford. Stanford won 40-12. This was one of the biggest line differences (8.5) of all the bowl games. The Predictor also said there would be a total of 56 total points scored in the game. The odds-makers set the total at 59 points. 52 total points were scored in the game, under 59. Meaning The Predictor also predicted the total points better than the odds-makers.

The Predictor is for entertainment purposes only. We do not condone gambling.


Tuesday, December 21, 2010

Simple Weather Bash Script

This simple weather bash script was written with the intention of piping it to a text to speech program such as flite or festival. However, it can be used for any sort of text notification such as printing to the command line or emailing.


#!/bin/sh

# spkweather.sh
# Written by:
# Brandt Daniels
# December 2010

LAT=XX.XXXX
LON=-XXX.XXX

RAW=$(curl -s "http://forecast.weather.gov/MapClick.php?site=SGX&lat=$LAT&lon=$LON&TextType=1")
echo "$RAW" | sed 's/\(.*\)<\/b>\(.*\)
.*/\1\2/;s/.*<.*//g;/^$/d' | head -$1

Friday, October 15, 2010

x10 Rain8II sprinkler weather scripts for use with Heyu

I use Heyu-2.9.1 for X10 home automation running on a Sheevaplug. For irrigation, I purchased a Rain8II from WGL Designs some time ago. With the Rain8II you need an X10 ON, and OFF for each zone to control it, unlike the first Rain8 where you just needed to trigger the first zone and it would automatically go through it's watering cycle. The Rain8II is also 2-way X10. That means you can configure it to automatically send back a status message to confirm that is has received the command that an x10 device has sent it.

The Rain8II states in the manual that it can be controlled by an X10 Mini Timer schedule, which I've done. When you want to disable the schedule, due to rain for example, you simply slide the selector from 'Run' to 'Set Clock' and it disables the first 5 unit codes. In my case I am only using 5 sprinkler zones so this worked out perfect. If you want to disable all 8 zones on the Rain8II, you will need to change the house code on the Mini Timer to an unused house code.

I mostly use the CM11a and Heyu for my Rain8II timers. Only when my CM11a cable went bad, I used the Mini Timer until I replaced the cable. I simply created the proper macros and timers in the schedule file an uploaded them to the CM11a. Well since I have a LOT of x10 signals flying around my house, some of the x10 signals for the Rain8II were being missed. According to the Heyu man pages, the solution for this was to simply schedule it twice a minute apart. So I have two ON and two OFF timers for all five zones. This works great, but I still have to comment out the timers and re-upload the schedule file on unexpected rainy days I don't want to water, and remember to reverse that when I am ready to water according the regular schedule again. Also, since the Rain8II sends back confirmation messages to Heyu, I shouldn't need two entries per ON and OFF for each zone in the schedule file!

With Heyu-2.9.1, the module type RAIN8II was added, as well as the module option 'DEFER'. What DEFER does, is it makes Heyu wait until it receives back the Status message from the module before updating it's internal state tables. So now you can send the command 'heyu status backyard_grass' and it will give you a guaranteed result. I also recently learned that you can trigger heyu scripts in the x10.conf file with CM11a uploaded timers using the 'sndm' flag in your script. If you use Heyu, you should know what the transmission flags are.

All that being said, I wanted a way so that my sprinkler timers would work with only the CM11a in case my Sheevaplug is down for some reason. I also wanted to be able to supplement the CM11a timers with a little intelligence when the Sheevaplug and heyu were up and running, which they are most of the time.

The first goal here is to create a status checking script so that I can eliminate the two timer schedules per x10 signal per zone that I currently have uploaded to the CM11a. I only want one timer entry per signal!

The second goal is to create a rain checking script, so that sprinklers won't turn on if it is raining, or has rained in the last X number of days. It would be so cool if I could calculate evapo-transpiration in the script, but that is a pipe dream for now.

So far, I have a first draft of the weather script created and as of tonight it worked! (it is raining a bit at the moment).

I still need to create the status checking script. I will update this blog as I get to it.

I hope some of you shell scripting and heyu experts can offer corrections and advice!



It appears that pasting my code has messed it up a bit, need to figure that out...




/etc/heyu/x10.conf:

alias driveway_grass I1 RAIN8II DEFER
alias walkway_grass I2 RAIN8II DEFER
alias front_planters I3 RAIN8II DEFER
alias backyard_grass I4 RAIN8II DEFER
alias sideyard_grass I5 RAIN8II DEFER

SCRIPT driveway_grass on sndm :: /usr/local/bin/chkrain.sh; if [ "$?" ]; then heyu off driveway_grass; fi
SCRIPT walkway_grass on sndm :: /usr/local/bin/chkrain.sh; if [ "$?" ]; then heyu off walkway_grass; fi
SCRIPT front_planters on sndm :: /usr/local/bin/chkrain.sh; if [ "$?" ]; then heyu off front_planters; fi
SCRIPT backyard_grass on sndm :: /usr/local/bin/chkrain.sh; if [ "$?" ]; then heyu off backyard_grass; fi
SCRIPT sideyard_grass on sndm :: /usr/local/bin/chkrain.sh; if [ "$?" ]; then heyu off sideyard_grass; fi


/etc/heyu/x10.sched:

macro driveway_grass_on 0 on driveway_grass
macro driveway_grass_off 0 off driveway_grass
macro walkway_grass_on 0 on walkway_grass
macro walkway_grass_off 0 off walkway_grass
macro front_planters_on 0 on front_planters
macro front_planters_off 0 off front_planters
macro backyard_grass_on 0 on backyard_grass
macro backyard_grass_off 0 off backyard_grass
macro sideyard_grass_on 0 on sideyard_grass
macro sideyard_grass_off 0 off sideyard_grass


timer s.t.tf. 01/01-12/31 21:30 21:40 driveway_grass_on driveway_grass_off
timer s.t.tf. 01/01-12/31 21:31 21:41 driveway_grass_on driveway_grass_off
timer s.t.tf. 01/01-12/31 21:42 21:52 walkway_grass_on walkway_grass_off
timer s.t.tf. 01/01-12/31 21:43 21:53 walkway_grass_on walkway_grass_off
timer s.t.tf. 01/01-12/31 21:54 22:04 front_planters_on front_planters_off
timer s.t.tf. 01/01-12/31 21:55 22:05 front_planters_on front_planters_off
timer s.t.tf. 01/01-12/31 22:06 22:16 backyard_grass_on backyard_grass_off
timer s.t.tf. 01/01-12/31 22:07 22:17 backyard_grass_on backyard_grass_off
timer s.t.tf. 01/01-12/31 22:18 22:23 sideyard_grass_on sideyard_grass_off
timer s.t.tf. 01/01-12/31 22:19 22:24 sideyard_grass_on sideyard_grass_off


/usr/local/bin/chkrain.sh:

#!/bin/bash

# This script will check for rain and
# return a 0 if no rain, and a 1 if
# it is raining.

STATIONID=KSNA
RAINPAD=2 # Day 0 is today.
RAINTHRESH="0.05"

# Get dates in various formats for use below.
DATE=`date +"%Y/%m/%d"`
CURPDT=`date +'%Y%m%d'`

# Available colums are:
# PDT,Max TemperatureF,Mean TemperatureF,Min TemperatureF,Max Dew PointF,MeanDew PointF,Min DewpointF,Max Humidity, Mean Humidity, Min Humidity, Max Sea Level PressureIn, Mean Sea Level PressureIn, Min Sea Level PressureIn, Max VisibilityMiles, Mean VisibilityMiles, Min VisibilityMiles, Max Wind SpeedMPH, Mean Wind SpeedMPH, Max Gust SpeedMPH,PrecipitationIn, CloudCover, Events
RESULT=`curl -s http://www.wunderground.com/history/airport/$STATIONID/$DATE/WeeklyHistory.html?format=1`

# Remove HTML
# Remove header line
# We only care about fields: PDT, Mean TemperatureF, PrecipitationIn, and Events
# Reverse output so today is first going back in time.
WEEKLY=`echo $RESULT | sed 's/
/\\n/g' | sed '/<.*>/d' | sed '/PDT/d' | cut -d, -f1,3,20,22 | sed -n '1!G;h;$p'`

# Remove decimal and convert RAINTHRESH to base10
RAINTHRESH=`echo $RAINTHRESH | sed 's/\.//g'`; RAINTHRESH=$((10#$RAINTHRESH))

echo "$WEEKLY" | while read RECORD
do
RECPDT=`echo $RECORD | cut -d, -f1 | sed 's/-//g'`
TEMP=`echo $RECORD | cut -d, -f2`
INCHES=`echo $RECORD | cut -d, -f3`
EVENT=`echo $RECORD | cut -d, -f4`
DATEDIFF=$(($CURPDT - $RECPDT))
if [ "$DATEDIFF" = "0" ] && [ "$EVENT" = "Rain" ]; then exit 1; fi
if [ "$INCHES" = "T" ] && [ "$EVENT" != "Rain" ]; then INCHES="0"; else INCHES=$((10#$INCHES)); fi
if [ "$DATEDIFF" -le "$RAINPAD" ] && [ "$EVENT" = "Rain" ] && [ "$INCHES" -ge "$RAINTHRESH" ]; then
exit 1
fi
done

Monday, September 27, 2010

Sheevaplug

Well I got a sheevaplug. I don't feel like writing now so I'll update this as I feel like it.

Reserved for sheevaplug

Monday, February 22, 2010

Linux Voice Recognition and Speech Home Automation

Here is a video I made for the Syno contest:



Please read more!!


I was able to successfully cross-compile and run Julius Voice Recognition Engine on my Synology DS209.
http://julius.sourceforge.jp/en_index.php
http://voxforge.org/home/downloads#QuickStart%20Anchor

I am working on trying to compile Festival w/ MBROLA engine in place of Flite for better TTS voices. I am also looking at Cepstral and AT&T Natural Voices.
http://www.cstr.ed.ac.uk/projects/festival/
http://tcts.fpms.ac.be/synthesis/mbrola.html
http://cepstral.com/
http://www.voiceforge.com/demo/
http://www2.research.att.com/~ttsweb/tts/demo.php


Another good program to look at would be DomotiGa + Gambas for linux HA.
http://www.domotiga.nl/

Flite TTS on a Synology NAS

I was able to successfully cross compile a text-to-speech engine called Flite which is very lightweight to run on my DS209j. This means you can use HEYU or Misterhouse to output speech upon an event.

http://www.speech.cs.cmu.edu/flite/

Here is my config file generated from running configure:


root@xubuntu-vm:/usr/local/flite-1.3-release# cat config/config
# -*- makefile -*-
#
# This file is automatically generated by configure.
# Do not hand edit.

TARGET_OS    = linux-gnu
TARGET_CPU   = powerpc
HOST_OS    = linux-gnu
HOST_CPU   = powerpc

CC       = /usr/local/powerpc-linux/bin/powerpc-linux-gcc
CFLAGS   = -I/usr/local/powerpc-linux/include -Wall
CPPFLAGS = 
DEFS     = -DWORDS_BIGENDIAN=1
#DEFS     = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DWORDS_BIGENDIAN=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1   # we don't use these anywhere
SHFLAGS  = 

AR       = /usr/local/powerpc-linux/bin/powerpc-linux-ar
RANLIB   = /usr/local/powerpc-linux/bin/powerpc-linux-ranlib
INSTALL  = /usr/bin/install -c

M68KCC   = 

AUDIODRIVER = oss
AUDIODEFS   = -DCST_AUDIO_LINUX
AUDIOLIBS   = 

LEXDEFS = 
VOXDEFS = 

OTHERLIBS = 

MMAPTYPE    = posix
STDIOTYPE   = stdio

FL_LANG  = usenglish
FL_VOX   = cmu_us_kal16
FL_LEX   = cmulex

prefix        = /usr/local
exec_prefix   = ${prefix}
EXEEXT       = 
INSTALLBINDIR = ${exec_prefix}/bin
INSTALLLIBDIR = ${exec_prefix}/lib
INSTALLINCDIR = ${prefix}/include/flite

Misterhouse on Synology NAS

Misterhouse:
http://misterhouse.sourceforge.net/

I've confirmed that misterhouse does work with /dev/usb/ttyUSB0.

I recommend unzipping Misterhouse in /usr/local

DiskStation> cd /usr/local
DiskStation> gunzip < /volume1/Downloads/misterhouse-2.105.tar.gz | tar xvf -
Make sure you run the configure which uses h2ph. h2ph is just a perl script, but you have to make sure you download the your systems GPL source from Synology and change one line in the Misterhouse configure script:
#cd /usr/include
cd /usr/local/powerpc-linux/include 
When you run the script it will remove all Windows files and will use the C header files to produce Perl header files ending in .ph Follow this: http://misterhouse.sourceforge.net/install.html#quick_install_instructions and this: http://misterhouse.sourceforge.net/install.html#unix_detailed_install_instructions In /usr/local/mh/bin create a file called mh.private.ini and add these basic entries:
sound_program=
latitude=12.345678
longitude=-123.456789
time_zone=-8
city=YourCity
zone=SomeMajorCityNearYou
state=YourStateAbbreviation
zip_code= 12345
dbi_user=mhuser
dbi_password=SomePassword
voice_text=
cm11_port=/dev/ttyUSB0
tk=0
Now when you start Misterhouse do something like this to run it in the background and have its output go to some logfile:
DiskStation> cd /usr/local/mh/bin
DiskStation> ./mhl & > /var/log/mh.out
Now you should be able to go to http://192.168.x.x:8080 and access Misterhouse. Please read the Misterhosue docs from here...

CM11a, Heyu, and domus.Link running on Synology NAS

I have an old HD11a which is just a re-branded CM11a, and I verified that it does work through the usb/serial converter I have.

Using optware ipkg (ipkg is a must!) I was able to install HEYU. They also have one called Ppower or Penguin Power, which I assume would also work:


DiskStation> ipkg list | grep "home automation"
heyu - 2.8.0-1 - X10 home automation control using the CM11A
ppower - 0.1.5-1 - Ppower, short for 'Penguin Power', is a piece of software for controlling x10 home automation equipment connected to the comput



domus.Link PHP frontend for HEYU


I wasn't too excited about cgi/perl scripts, but I found what I think is one of the only PHP front ends which runs perfectly on the Syno after slight tweaking of the php.ini file.

domus.Link
http://domus.link.co.pt/

I was even able to create a 3rd-Party applications node for it to run embedded in the web manager.
DiskStation> pwd
/usr/syno/synoman/webman/3rdparty
DiskStation> ls -laR domusLink/
domusLink/:
drwxr-xr-x    2 root     root         4096 Dec 23 00:53 .
drwxr-xr-x    3 root     root         4096 Dec 23 00:33 ..
-rw-r--r--    1 root     root          198 Dec 23 01:01 application.cfg
lrwxrwxrwx    1 root     root           44 Dec 23 00:53 images -> /volume1/web/domus.Link/theme/default/images

DiskStation> cat application.cfg 
text_enu = domus.Link
description_enu = domus.Link - Home Automation Interface
type = embedded
protocol = https
port = 443 
path = /domus.Link
icon_16 = images/menu_home_on.png
icon_32 = images/menu_home_on.png


Cross-Compiling Bottlerocket for CM17a Firecracker on Synology

Cross-Compiling Bottlerocket, which uses the Firecracker CM17a:
http://www.linuxha.com/bottlerocket/

Following the 3rd-party app integration guide; configure, make, make install. This puts it in your local machines /usr/local/bin. You then have to upload the program 'br' to your Synology in the same directory.

Set your cross-compiling environment variables to point to the toolchain you installed in /usr/local:
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# export CC=/usr/local/powerpc-linux/bin/powerpc-linux-gcc
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# export LD=/usr/local/powerpc-linux/bin/powerpc-linux-ld
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# export RANLIB=/usr/local/powerpc-linux/bin/powerpc-linux-ranlib
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# export CFLAGS="-I/usr/local/powerpc-linux/include"
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# export LDFLAGS="-L/usr/local/powerpc-linux/lib"

Run the configure that came with the code giving it a few extra parameters as specified in the guide:
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# ./configure \
> --host=powerpc-unknown-linux \
> --target=powerpc-unknown-linux \
> --build=i686-pc-linux \
> --prefix=/usr/local
creating cache ./config.cache
checking for gcc... /usr/local/powerpc-linux/bin/powerpc-linux-gcc
checking whether the C compiler (/usr/local/powerpc-linux/bin/powerpc-linux-gcc -I/usr/local/powerpc-linux/include -L/usr/local/powerpc-linux/lib) works... yes
checking whether the C compiler (/usr/local/powerpc-linux/bin/powerpc-linux-gcc -I/usr/local/powerpc-linux/include -L/usr/local/powerpc-linux/lib) is a cross-compiler... yes
checking whether we are using GNU C... yes
checking whether /usr/local/powerpc-linux/bin/powerpc-linux-gcc accepts -g... yes
checking how to run the C preprocessor... /usr/local/powerpc-linux/bin/powerpc-linux-gcc -E
checking for a BSD compatible install... /usr/bin/install -c
checking for features.h... yes
checking for errno.h... yes
checking for sys/termios.h... yes
checking for termios.h... yes
guessing x10 port
using /dev/ttyS0 for x10 port
updating cache ./config.cache
creating ./config.status
creating Makefile
creating config.h

Run make:
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# make
/usr/local/powerpc-linux/bin/powerpc-linux-gcc -I/usr/local/powerpc-linux/include -I. -Wall  -O2 -DX10_PORTNAME=\"/dev/ttyS0\" -DHAVE_CONFIG_H -c ./br_cmd.c
/usr/local/powerpc-linux/bin/powerpc-linux-gcc -I/usr/local/powerpc-linux/include -I. -Wall  -O2 -DX10_PORTNAME=\"/dev/ttyS0\" -DHAVE_CONFIG_H -c ./br.c
/usr/local/powerpc-linux/bin/powerpc-linux-gcc -I/usr/local/powerpc-linux/include -I. -Wall  -O2 -DX10_PORTNAME=\"/dev/ttyS0\" -DHAVE_CONFIG_H -o br br.o br_cmd.o

Run 'make install' which installs it in /usr/local/bin on your local machine:
root@xubuntu-vm:/usr/local/bottlerocket-0.04c# make install
/usr/bin/install -c -d -m 755 /usr/local/bin
/usr/bin/install -c -m 555 br /usr/local/bin

Now copy the file /usr/local/bin/br to your synology in the same directory.


Once that is running, you issue commands as such:
DiskStation> cd /usr/local/bin/
DiskStation> ./br
BottleRocket version 0.04c

Usage: ./br [][()  ...]

  Options:
  -v, --verbose   add v's to increase verbosity
  -x, --port=PORT  set port to use
  -c, --house=[A-P]  use alternate house code (default "A")
  -n, --on=LIST   turn on devices in LIST
  -f, --off=LIST  turn off devices in LIST
  -N, --ON   turn on all devices in housecode
  -F, --OFF   turn off all devices in housecode
  -d, --dim=LEVEL[,LIST] dim devices in housecode to  relative LEVEL
  -B, --lamps_on  turn all lamps in housecode on
  -D, --lamps_off  turn all lamps in housecode off
  -r, --repeat=NUM  repeat commands NUM times (0 = ~ forever)
  -h, --help   this help

  is a comma separated list of devices (no spaces),
  each ranging from 1 to 16
 is an integer from -12 to 12 (0 means no change)
 is a letter between A and P
 is one of ON, OFF, DIM, BRIGHT, ALL_ON, ALL_OFF,
  LAMPS_ON or LAMPS_OFF

For native commands,  should only be specified for ON or OFF.

DiskStation> ./br -x /dev/ttyUSB0 -v M3 OFF
./br:  Turning off appliance M3
DiskStation> ./br -x /dev/ttyUSB0 -v M3 ON 
./br:  Turning on appliance M3
DiskStation> ./br -x /dev/ttyUSB0 -v M3 OFF
./br:  Turning off appliance M3
DiskStation> ./br -x /dev/ttyUSB0 -v C1 ON 
./br:  Turning on appliance C1
DiskStation> ./br -x /dev/ttyUSB0 -v C1 OFF
./br:  Turning off appliance C1
DiskStation> ./br -x /dev/ttyUSB0 -v C1 ON 
./br:  Turning on appliance C1
DiskStation> ./br -x /dev/ttyUSB0 -v C3 ON
./br:  Turning on appliance C3
DiskStation> ./br -x /dev/ttyUSB0 -v C3 OFF
./br:  Turning off appliance C3
DiskStation> ./br -x /dev/ttyUSB0 -v C3 ON 
./br:  Turning on appliance C3
DiskStation> ./br -x /dev/ttyUSB0 -v C1 OFF
./br:  Turning off appliance C1
DiskStation> ./br -x /dev/ttyUSB0 -v C3 OFF
./br:  Turning off appliance C3
DiskStation> ./br -x /dev/ttyUSB0 -v C LAMPS_ON
DiskStation> ./br -x /dev/ttyUSB0 -v C LAMPS_OFF
DiskStation> ./br -x /dev/ttyUSB0 -v C1 ON      
./br:  Turning on appliance C1
DiskStation> ./br -x /dev/ttyUSB0 -v -d25 C1   
./br:  For dimming either specify just a dim level or a comma
separated list containing the dim level and the devices to dim.
./br:  Valid dimlevels are numbers between -12 and 12.
DiskStation> ./br -x /dev/ttyUSB0 -v -d6 C1 
BottleRocket version 0.04c

Usage: ./br [][()  ...]

  Options:
  -v, --verbose   add v's to increase verbosity
  -x, --port=PORT  set port to use
  -c, --house=[A-P]  use alternate house code (default "A")
  -n, --on=LIST   turn on devices in LIST
  -f, --off=LIST  turn off devices in LIST
  -N, --ON   turn on all devices in housecode
  -F, --OFF   turn off all devices in housecode
  -d, --dim=LEVEL[,LIST] dim devices in housecode to  relative LEVEL
  -B, --lamps_on  turn all lamps in housecode on
  -D, --lamps_off  turn all lamps in housecode off
  -r, --repeat=NUM  repeat commands NUM times (0 = ~ forever)
  -h, --help   this help

  is a comma separated list of devices (no spaces),
  each ranging from 1 to 16
 is an integer from -12 to 12 (0 means no change)
 is a letter between A and P
 is one of ON, OFF, DIM, BRIGHT, ALL_ON, ALL_OFF,
  LAMPS_ON or LAMPS_OFF

For native commands,  should only be specified for ON or OFF.

DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d6,1
./br:  Brightening lamp C1 by 6.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d-6,1
./br:  Dimming lamp C1 by 6.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d6,3 
./br:  Brightening lamp C3 by 6.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d-3,3
./br:  Dimming lamp C3 by 3.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d-3,3
./br:  Dimming lamp C3 by 3.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d-3,2
./br:  Dimming lamp C2 by 3.
DiskStation> ./br -x /dev/ttyUSB0 -v -cC -d3,2 
./br:  Brightening lamp C2 by 3.
DiskStation> ./br -x /dev/ttyUSB0 -v C LAMPS_OFF

Home Automation on Synology NAS

I am the proud owner of a Synology DS209j NAS. This NAS has firmware that allows much more than just storage. While I only wanted one computer on 2/47 in the house. I also wanted a home automation server. Unfortunately, the Synology NAS devices weren't intended to be home automation servers. Therefore, a lot of modification has been required to get it to act as a home automation server. These next few posts have been up in the Synology forum for a while now, but I wanted to add my work to my own blog so please click 'read more' to expand this post...


http://forum.synology.com/enu/viewtopic.php?f=27&t=19788#p81040

I have a Synology DS209j, and I'll always run the latest firmware.

I've installed Xubuntu 9.04 in a virtual machine on my mac.

Following this page:
http://www.synology.com/us/support/3rd-party_application_integration.php

There is a document:
http://download.synology.com/download/ds/userguide/Synology%20NAS%20Server%203rd-Party%20Apps%20Integration%20Guide.pdf

Following the document I've downloaded the latest toolchain from Synology as well as the latest GPL source:
http://www.synology.com/us/gpl/index.php

As far as usb to serial hardware goes, I am using this product from Parallax as it give you proper RS232 levels and is very affordable:
http://www.parallax.com/tabid/768/ProductID/378/Default.aspx

From that page I followed the link to the external FTDI drivers for linux.

I renamed the ftdi_sio header and c file to .orig and placed these new files in their location in the synology source. From their I followed the document and made the modules.



Now i've got usbserial.ko and ftdi_sio.ko somewhere on my DS209j

Now you have to load the modules into the kernel and create the devices:
insmod usbserial.ko
insmod ftdi.ko
mknod /dev/usb/ttyUSB0 c 188 0
mknod /dev/usb/ttyUSB1 c 188 1

Also, add some lines like these to /etc/rc.local to make it persistent over reboot:
insmod /volume1/archive/usbserial.ko
insmod /volume1/archive/ftdi_sio.ko
mknod /dev/usb/ttyUSB0 c 188 0
mknod /dev/usb/ttyUSB1 c 188 1

run the command 'dmesg' and you should see something like this:
usb 1-2.1: new full speed USB device using ehci_hcd and address 15
usb 1-2.1: configuration #1 chosen from 1 choice
ftdi_sio 1-2.1:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT232RL
drivers/usb/serial/ftdi_sio.c: Number of endpoints 2
drivers/usb/serial/ftdi_sio.c: Endpoint 1 MaxPacketSize 16384
drivers/usb/serial/ftdi_sio.c: Endpoint 2 MaxPacketSize 16384
drivers/usb/serial/ftdi_sio.c: Setting MaxPacketSize 16384
usb 1-2.1: FTDI USB Serial Device converter now attached to ttyUSB0

The X-10 device I got working for now is known as the Firecracker CM17a, and the HD11A/CM11A 2-way computer interface

Sunday, January 31, 2010

I got one of these to help me map the circuits in my house for X10 use. With this you can do it without turning the power off to see what is on what circuit.

Monday, August 31, 2009

Getting started in home automation

I just picked this up from the Smarthome factory store and it prompted me to write a blog about home automation, abbreviated as HA from here on out.




I'm not going to go into a definition of what HA is as I will assume you are already aware of it. As I am interested in robotics, I am also interested in home automation. Like robotics it is a series of sensors (distance, motion, temperature), a brain (computer/MCU), and actuators (servos, relays).

The two protocols I am focusing on for now are X10 and Insteon. The place to go for X10 hardware is: http://www.x10.com, the place to go for Insteon hardware is http://www.smarthome.com. Although smarthome also sells X10 components in a pinch. I would recommend X10.com because they have nice deals on packages of hardware.

While Insteon is more modern and has error checking and correcting in a sense, I am mostly going to go with X10 for now because it is cheaper and I'm a starving student.

Starting out I would recommend buying all your X10/Insteon hardware first and use it around the house with your controllers and remotes by hand. Buy bulk in motion sensors, lamp modules, and appliance modules (2 and 3 pin).

Recent experience has told me to stay away from the X10 TM751 transceivers because they have a high failure rate. TM751s also can not accept Power Line Carrier (PLC) commands, which we will use later when we bring the computer into the picture. The transceiver I recommend for starters is the RR501 model. Later on we will replace the RR501s with something much better, a W800USB, but will require the use of a computer. The W800USB will also be able to receive X10 signals from those magnetic door contact closures which by default only work with security system receivers.

The package you see above in the picture is a kit containing an RR501 transceiver and the HR12a Palm Pad. The item number of the package is PHK05 or RC5000 depending on where you go.

Since the number of rooms in your residence will vary, I will just give you the basic inventory per room:

LM465 Dimmable Lamp Module - 1 per incandescent lamp (do not use on flourescents)
MS13a HawkEye or MS14a EagleEye Motion Sensor - 1 per room
AM466 3-Pin Appliance Module - Depending on how many 3-Pin devices you have in a room
AM486 2-Pin Appliance Module - Depending on how many 2-Pin devices you have in a room.
RR501 Wireless Transceiver - 1 per 16 wireless devices
Remotes and/or Controllers - Your choice:
Wired: http://www.x10.com/automation/plugin_controllers.html
Wireless: http://www.x10.com/automation/wireless_remotes.html#home_remotes

Note: You can use appliance modules on everything. You can use lamp modules on only incandescent lamps.


Later I will talk about adding a computer, software, computer interface, X10 wireless receiver interface, and DS10a door/window sensors.

Friday, February 20, 2009

Robot firmware over the air!

Sorry my posts have been kind of weak lately. I have not really felt like writing things up, and I've been very busy with school and work. Here is a horrible video I made last night of my robot demonstrating object avoidance and programming the target MCU wirelessly.



Robot firmware over the air! from Brandt Daniels on Vimeo.

Tuesday, February 3, 2009

Servo Magazine

I was featured in this month's Servo Magazine regarding wireless programming :)

Check it out:





Friday, January 30, 2009

Wind-Up Robots

I love these wind-up robots of mine! Now all I need is the B9 from 'Lost in Space', R2D2, and C3-PO!

Wednesday, January 28, 2009

MEMS 2-Axis Accelerometer

I picked up a Memsic 2-axis accelerometer from the sensor drawer at radio shack. I've never used an accelerometer before and this one uses MEMS technology. I hooked it up to my BS2-IC via breadboard and uploaded a maze game.

My next goal is to write C code for it using the AVR libraries and integrate it with my robot. I am thinking it will help with pathfinding as well as being able to tell when my robot is stuck on a chair leg or something.

Monday, January 26, 2009

Wednesday, January 21, 2009

Free upgrade to my electronics tools

I recently received a postcard in the mail from the HR department where I work. They often send out mailings that go straight in the trash, but the thing that caught my eye on this one was an offer for a $100 gift certificate. As I read more, I found out all I had to do was complete a simple health related survey and I would receive a $100 gift certificate to any place on a list of about 350 retailers.

At first, I was going to go with target because they have a good selection of things I could use. Second, I almost went with Hammacher Schlemmer because they have neat stuff. Then I thought about it more before I chose, and i decided that the best thing would be to go with Amazon.com because they have a wide variety of items to chose from.

A couple of days later I received an e-mail containing my Gift Card Code for Amazon.com. I quickly entered in this code into my account, and I had $100 in my balance!!! I held on to it for a few days while decided what I wanted, and at the same time added some things to my wish list. In the end, I ended up paying ~$40 because I went a little over, and there is multiple shipping costs from different vendors. Here is what I got for approximately $40USD:

Weller WES51













Weller ETH 1/32" Screwdriver Tip for SMD soldering
(ETA Shown)






1LB Kester 44 0.31" 60/40 Solder




















Weller SM1 Solder Dispenser
















Pretty good deal if you ask me!!

Monday, January 12, 2009

Battery Monitor - Voltage Divider Circuit

There are many IC's out there that can do what is called "gas gauging" to monitor how much battery is left in your robot, just like in mobile phones.

Since I am somewhat new to electronics, I wanted to learn how to implement a battery monitor sensor by using what is called a voltage divider circuit.



Just like LEDs use a series resistor to ensure they receive no more than 20mA of current, with 5vdc this usually turns out to be a 330ohm resistor.

If you wanted to power this same LED, but all you had was say a 9volt or 12volt power source, then you would have to use a second resistor on the ground side of the LED, which would give you a lower voltage AND lower current.

This voltage divider circuit has many more uses besides just LEDs, it can also be used to create a reference voltage or logical voltage level.

For example, I have a 6vdc NiMH battery, but when fully charged it reads 7.08vdc on the multimeter. For my sensor, I want to say that 5vdc is fully charged. I will do some math to calculate what resistors I need to get a 5vdc Vout. Or in my case, I dread math so I will use a Java applet I found:

The applet will help me get a close approximation to start with. I enter in 7v for Vs, and I find I can get 5.00vdc on the voltmeter with R1 = 20k, and R2 = 50k
Voltage Divider Applet

The only snag apparent right now is that with common 5% resistors, there are only a limited selection to chose from. Unfortunately, there is no such thing as a 5% 20k and 50k resistor.

There is another snag too that i'll tell you about now, is that this circuit is assuming there is nothing connected to Vout, meaning no load. It is basically just a series resistance. The way to deal with that is if you know the current that will be on the load, you can use another series resistor on your 5v. The other way, which is what I will use, is you can add a capacitor between ground, and the voltage you want to stabalize. In my case a 10uF 16V cap is perfect.

According to Ohm's Law, the ratio of voltage across our two resistors will be equal to the ratio of the resistance values themselves. In my case, I want to drop from 7.08 to 5, thats a drop of 2.08. Therefore my ratio is 2.08:5, or more simply 0.416:1. Unfortunately, this ratio will not work using common 5% resistors. I will round down and say my batteries max charge is 7vdc, which is fine as they will lower in voltage as they get older anyway. So lets say 2:5, or 0.4:1 (or for the purpose of the calculator below, 1:0.4)

In this next calculator, the table shows the significant digits (1st digit, and 2nd digit) of standard 5% resistor values. When you type in a ratio, it calculates the corresponding significant digits (1st digit, and 2nd digit) that would be required to complete that ratio.

Resistor Ratio Calculator

Go ahead and type in '0.4' in the desired ratio box.

All you need to do is pick out ratios of valid significant digits (meaning no decimal point, and a number you already see listed on the table, in my case the first 4 in 10:4 is not an existing resistor value).

The table shows that you can use resistance values with the first two digits of (this does not talk about the multiplier) 30:12, or 75:30 to obtain the ratio of 1:0.4.

If instead of doing 2/5 to get 0.4, you had done 5/2, you would have gotten 2.5. If you had specified 1:2.5 (the inverse of 1:0.4), you would have gotten the ratios of 12:30, and 30:75. Which is the same ratios that fit the standard resistor values.

We the voltage out that we want (5vdc) by using any resistors of the ratios that we discovered. We could use (12ohm & 30ohm), (120ohm & 300ohm), (1.2kohm & 3kohm), (12kohm & 30kohm), (120kohm & 300kohm), all the way up to (120Mohm & 300Mohm). The same goes with the 30:75 ratio.

You can check it out by entering some of these values into a calculator:

The sensor:

The way we make this into a sensor, is wire up some sort of battery tap on the MCU board, and the place the 10uF cap across your positive and negative voltages. Place your two resistors in series on each end of the cap. From the two resistor wires that are connected, place a wire coming off of there and crimp it with a molex connector

From there you can plug that into a male header coming off of a pin on your microprocessor. The pin should be one that is using your mcu's 8-bit ADC. This way theoretically, a full battery would return 255, and a drained battery would be closer to zero (although your robot may start malfunction a lot earlier). You have to test to see the lowest voltages your robot can operate at. From there you can either flash some sort of LED, or have it enter into an algorithm that searches out for a charger beacon, or tape on the ground leading to the charger.

From all of that your robot will know when its low and power, and will be able to implement a self-charging routine.