Using bluetooth to turn on ZM

Forum for questions and support relating to the 1.24.x releases only.
Locked
prupert
Posts: 10
Joined: Mon Mar 02, 2009 3:47 pm
Location: Bristol, UK

Using bluetooth to turn on ZM

Post by prupert »

Hi

I was thinking of using bluemon:

http://www.matthew.ath.cx/projects/bluemon/

as a way to automatically turn on ZM when I am away, so it aint running when I am here, and is when I am not. Bluemon uses bluetooth to detect your presence (so it looks for a particular bluetooth device like your phone for example) and then when it no longer sees your device it carries out a command.

I was wondering if anyone can suggest which command that should be?
Is "sudo zmpkg.pl start" the best command to start ZM and "sudo zmpkg.pl stop" the best way to stop it, or are there better alternatives??
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Those are the approved methods provided using sudo doesn't mess up permissions and try and run everything as root.
Phil
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

You could also use runstates to stop and start the recording but stopping the entire process would work as well.
prupert
Posts: 10
Joined: Mon Mar 02, 2009 3:47 pm
Location: Bristol, UK

Post by prupert »

Cool, cheers, good to know.
prupert
Posts: 10
Joined: Mon Mar 02, 2009 3:47 pm
Location: Bristol, UK

Post by prupert »

So, I finally got round to writing a script to turn ZoneMinder on and off when I am at home or not, based on my phone's bluetooth connection.

I am a very new to Linux and bash, so you might all laugh at this script and the hacky way I do it, if you have any suggestions, please do add ammednments.

Basically, I have a USB Bluetooth dongle and I use hcitool to scan for my phone's MAC address. If my phone is present, the scan returns my phones name and the script turns ZoneMinder off and writes to a log file.

If my phone is not present, because the MAC address returns no answer/name, then the script turns ZoneMinder on and writes to a log file. It also changes the permissions on the video devices when it turns on ZM since there are somtimes problems with permissions on the USB wecams I use.

Here is the script:

Code: Select all

#!/bin/bash
# Rupert's Bluetooth monitoring progam to turn zoneminder on and off
# v0.1 March 2009
# written with next to no knowledge of bash and loads of googling
MOBILE=""
SCAN=""
# lets assign the name of our mobile phone to a variable
MOBILE="Nokia"

# lets scan for the presence of my mobile by scanning for its bluetooth MAC address and seeing if it's name is returned and assign it to a variable
SCAN=( $(hcitool name 00:1D:FD:72:61:F8) )

# now, lets do the main part of the script, if the name of my phone is returned then the phone is here, so turn off ZM, it the name isn't returned
# then turn ZM on!

if [ "$MOBILE" = "$SCAN" ]; then
	sudo zmpkg.pl stop
	echo Mobile present at `date "+%m/%d/%y %l:%M:%S %p"` >> /var/log/bluetoothscan.log
else 
	sudo chmod 777 /dev/video0
	sudo chmod 777 /dev/video1
	sudo zmpkg.pl start
echo Mobile absent and ZM started at `date "+%m/%d/%y %l:%M:%S %p"` >> /var/log/bluetoothscan.log
fi
I then use cron to run this script every ten minutes.

If people want to suggest improvements, please do say.

Obviously, if you want to use this script, you will need to change the variables MOBILE - so it says your phones make and the variable SCAN for your phone's bluetooth MAC address .
Locked