Dockstar Scripts

This post is just to document all the scripts that were created/reused to make the Dockstar run pretty much on its own…

There’s basically just gonna be a lot of code and not much else.  I’ll at least describe what each script is doing…

This first script (by the way, these are in no particular order, and some depend on each other) is what gets the wireless connected and mjpg-streamer going too so that Zoneminder can use the video from this camera:


#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
echo "Starting wireless..." ; \
ifconfig wlan0 up ; \
iwconfig wlan0 txpower 15dbm ; \
iwconfig wlan0 essid "deathmeister" ; \
sleep 1; \
/etc/ &
sleep 5;
echo "Starting MJPG Streamer...." ; \
/root/mjpg-streamer-r63/ &
exit 0

I don’t remember if the slashes or semicolons at the end are needed or not.  If not, feel free to remove them.  Leaving them in doesn’t detract from the operation of the script, however.  Setting the TXpower to 15dbm makes sure that the wifi adapter isn’t overdriving the output.  The driver defaults to 23dbm (I think), but the max output for the card is supposed to be 15dbm (again if I remember right), and that’s where the 15dbm number came from.  Supposedly the wireless link quality improves when you’re not overdriving the output….

This next script is what does all the configurations for mjpg-streamer.  In this script, the resolution, framerate, and some other options can be changed for streaming out of the Dockstar:


exec /root/mjpg-streamer-r63/mjpg_streamer -i "/root/mjpg-streamer-r63/plugins/ -d /dev/video0 -r 800x600 -f 5" -o "/root/mjpg-streamer-r63/plugins/ -w /root/mjpg-streamer-r63/www -p 9000 -c user:password" -b &
sleep 1
curl "http://user:password@"
sleep 5
curl "http://user:password@"

The 1st line after #!/bin/bash  and before sleep 1 is one, massive line for starting mjpg-streamer.  Since mjpg-streamer provides a web interface for controlling the camera, we can cause the camera LED to blink to show that things are working, and then turn the camera LED off to make it less obvious it’s doing anything when other people see it (mainly smelly robbers….I’m assuming they’re smelly).  I’ve also removed the authentication credentials as no one needs to know what those are except me!

This next one isn’t a script, rather a configuration file for wpa_supplicant.  This is what wpa_supplicant uses for knowing how to connect to the wifi access point.  The key has been removed from the post, but to generate the router key, you use wpa_passphrase:


# This line enables the use of wpa_cli
# if possible (to check for successful association)

#this should keep things connected


Next up is the network interfaces config file.  In here we set the wifi up for static IP since we don’t need it grabbing a new IP by accident as Zoneminder won’t know that happened and we’re screwed until we discover the new IP (kinda need that IP to get into the Dockstar to find out what its IP is…a little catch 22 here).  The wireless interface is wlan0 if it wasn’t totally obvious.


# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

iface wlan0 inet static

The following in “hosts” allows you to set the hostname of the box:

/etc/hosts       localhost       wificam2

This last script supposedly reconnects to the access point if it is discovered that wpa_supplicant isn’t connected anymore.  I have yet to test this script out as I didn’t write it myself, but it looks like it kills wpa_supplicant off if it detects that the wifi is disconnected.  A major issue w/ wifi disconnecting and not reconnecting is that it’s the only remote way to get into the Dockstar.  Luckily mine are just downstairs, but if they’re located someplace that’s not easy to get to, having wifi go down and not come back up is a giant pain in the butt.  Then some poor dope has to go and physically reset the Dockstar to make wifi come back.  Not fun.


# Reconnect script. Be sure to have mutt installed, or comment that line out.

check_newip () {
newip=`/sbin/ifconfig|/bin/grep "Bcast"`
oldip=`cat $iplog`
if [ "$newip" != "$oldip" ]; then
#echo $newip|mutt -s 'address changed' $email
echo Address changed, time: `date` >> $output
echo "$newip" >> $output
if [ "`wpa_cli status|grep wpa_state`" == "wpa_state=COMPLETED" ]; then
echo "$newip" > $iplog

reconnect () {
echo Reconnecting, time: `date` >> $output
while [ "`wpa_cli status|grep wpa_state`" != "wpa_state=COMPLETED" ]; do
killall wpa_supplicant; sleep 1
wpa_supplicant -B -D$driver -i$iface -c$wpaconfig &
for i in `seq 1 10`;do
sleep 4
if [ "`wpa_cli status|grep wpa_state`" == "wpa_state=COMPLETED" ]; then
# setup the ip address and routing stuff again
ifconfig $iface
route add default gw

#dhclient $iface #for getting DHCP addresses

if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
while [ 1 ]; do
if [ "`wpa_cli status|grep wpa_state`" == "wpa_state=COMPLETED" ]; then
#echo -n "."
sleep 1
sleep 10
rm -f "$lockfile"
echo "Lockfile $lockfile is held by $(cat $lockfile)."

I commented out the check for a new IP thingy since we’re using static IPs on the Dockstar.  That piece of the script is only useful if you’re using DHCP to get your IP address.  Oh yeah, you need to have


in your /etc/wpa_supplicant.conf file so that wpa_cli knows how to connect to the wpa_supplicant daemon.  That’s already in my config up the page a bit.   The script recovers the wifi connection just fine.  There were a few bugs I introduced (since I’m using static IPs and not dynamic), but it’s all fixed and working.  If I force the wifi to disconnect (using wpa_cli or by killing wpa_supplicant), the connection comes back in 10 secs or less.

I think these are all the majority of the custom settings in the Dockstar that are different from stock.

This entry was posted in Wifi Webcam. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.